Home Answers Viewqa Swing-AWT opening internet browser in java program

 
 


omkar
opening internet browser in java program
1 Answer(s)      4 years and 3 months ago
Posted in : Swing AWT

View Answers

April 4, 2009 at 12:30 PM


Hi Omkar,

Use the following code:

1) 'OpenBrowser.java'
import javax.swing.*;
import java.lang.reflect.Method;

public class OpenBrowser {
public static void openURL(String url) {
String osName = System.getProperty("os.name");
try {
if (osName.startsWith("Windows"))
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
else {
String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
String browser = null;
for (int count = 0; count < browsers.length && browser == null; count++)
if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor() == 0)
browser = browsers[count];
Runtime.getRuntime().exec(new String[] {browser, url});
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error in opening browser" + ":\n" + e.getLocalizedMessage());
}
}
}

2) 'Browser.java'
import javax.swing.*;
import java.awt.event.*;

public class Browser {
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
final JTextField url =new JTextField(20);
JButton button = new JButton("Open Browser");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
OpenBrowser.openURL(url.getText().trim()); }
} );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.add(new JLabel("URL:"));
panel.add(url);
panel.add(button);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}

}

Thanks









Related Pages:
opening internet browser in java program - Swing AWT
opening internet browser in java program  i want a code to open the internet browser in swing program using JFrame.  Hi Omkar, Use...) { JOptionPane.showMessageDialog(null, "Error in opening browser" + ":\n" + e.getLocalizedMessage
Opening a browser only with body from a java program
Opening a browser only with body from a java program  Hi all, I got following requirement, Opening a browser window only with body and title bar. And based on some condition, after some time, i have to close the browser window
opening new browser with new JSESSIONID using java
opening new browser with new JSESSIONID using java  I am facing following problem, I am trying to open a new browser using java. First i have opened one IE browser and manually. And i ran my LaunchURL.java file, it is opening new
Opening files with .jnlp extension on browser!?!?!
Opening files with .jnlp extension on browser!?!?!  I working... for Runtime.getRuntime().exec("..........."); I came across the java code.... Rather i want to open it in my browser(Mozilla/IE) itself. Kindly provide me
Java - Opening a URL from an Applet
Java - Opening a URL from an Applet  ... document or browser window. In this program you will see that many features have been used for opening url from an applet. This program is using two functions
Opening IE from Java Swing Application in Kiosk mode
Opening IE from Java Swing Application in Kiosk mode  Hi All, I want...) { String browserPath = "C:/Program Files/Internet Explorer...(); } } }   Here is a simple example of opening browser
Java - Opening a url in new window from an applet
Java - Opening a url in new window from an applet       This is the example of opening a url from an applet. This program shows that how a url is opened in a new document or browser
INTERNET - CVS
in the toolbar. ? Select What to Clear -> Browser History item. ? Check the Delete Cookies option. ? Select the browser(s). You can remove cookies for several browsers simultaneously. In Internet Explorer even if you remove cookies
Delete Internet Explorer History in java program
Delete Internet Explorer History in java program  code for Delete Internet Explorer History in java program
Opening a URL from an Applet
document or browser window. In this program you will see that many features have been used for opening url from an applet. This program is using two functions in which... init() is self executed when the program is loaded on the browser. In the init
browser
in the swing because I am working on my project Browser and one more problem is that when I entered the URL then some page open which made in java and the page
Opening Notepad
Opening Notepad  Sir/madam I want to open notepad from java applications and save the contents on it. Can someone please help me to do...}; Runtime.getRuntime().exec(commands); }   Java Create
browser
browser  how to add menu items in the menu in java swing through java coding
Java for Internet Explorer
browser as Internet Explorer 7. To enable or disable Java in Internet Explorer 4... Java for Internet Explorer      ... and select Internet Options. Click on the Programs tab. Click Manage Add-ons
Exception when opening a excel file in JFrame
(jniwrap.dll) in java.library.path: C:\Program Files\Java\jdk1.7.0_05\bin;C...:\Program Files\Java\jre7\bin;. I already added the following libraries...Exception when opening a excel file in JFrame  Hello, I have
Welcome to the Internet
; Now a days Java has become so stupendous that we can't even think of WWW... network known as the Internet. This collection which is known as Internet can.... Initially Java applets started off with a bang and continue to be the most widespread
browser - JSP-Servlet
browser  Browser buttons In a website program with login and session concept, logout option is working properly in JSP pages. While pressing directly the back and front buttons in browser [Internet Explorer 6.0
cannot find java.exe error while opening netbean5.5 - IDE Questions
is C:\Program Files\Java\jdk1.6.0\j2sdk1.4.2_03\bin\java.exe How can i solve...cannot find java.exe error while opening netbean5.5  HI, 1)i am working netbean5.5 tool.I got the error of cannot find c:\programfiles\java
Open Source Browser
pages;     Java based X3D Toolkit and X3D Browser Xj3D... to Microsoft's dominant Internet Explorer browser -- Firefox 1.0, an open-source... program.      Open source browser improves Windows
Java - Opening a url in new window from an applet
Java - Opening a url in new window from an applet  ... in this program to open any url by replacing the value of url. In this example our applet will open new browser window and then show you the web page. Opening a new
Rich Internet Application Development
Rich Internet Application Development RIA architecture provides a new Web page... a number of restrictions and requirements remaining in it. These are: Browser... evaluation of Java 1.1, it becomes simpler to write in Java applets that run on all
datetime picker is not opening
datetime picker is not opening  Hi I have a java servlet code in this date time picker is not opening. The same opens in JSP code. My code is: **function.js** <script language="javascript" type="text/javascript" src
Help with opening a text file upon closing a program.
Help with opening a text file upon closing a program.  I need some helping in figuring out something I want to do. I have this program... that file to open whenever the user exits the program. My code so far
Java Swing Open Browser
Java Swing Open Browser Java provides different methods to develop useful... that will open the specified url on the browser using java swing. This example will really...) { JOptionPane.showMessageDialog(null, "Error in opening browser" + ":\n
opening new window - Java Beginners
opening new window  Hi All, I have two classes with me , lets say A and B.when I press a button in class A , the class B should open in a new window.i.e., I want to know, how a new window(B) can be opened by clicking a button
Internet and Web related questions for Web Master.
Internet and Web related questions for Web Master.   Explain the difference between the Internet and Web. What are Web browsers? Explain the two main functions of a Web browser. Write a note on the structure of a Web page. What
Cross platform browser question - Java Beginners
Cross platform browser question  Can you tell me what this is specifially asking for? I have my program that works fine, but the instructor said...-browser (works in Firefox and MS IE) web page using anonymous JS methods
Rich Internet Applications(RIA) Development and Deployment
internet applications are Java Web start applications and applets. The RIA are applications of java which benefit of the internet. According to deployment... : Applets : This application runs on the web browser. Java Web Start
Error Opening File - Java Interview Questions
Error Opening File  Dear, Please if help me to resolve this problem. I have an application in java that works correctly under Eclipse... this generated file, a message was displayed: Error opening file. But If I
problem in swing program for opening two windows with same login credentials
problem in swing program for opening two windows with same login credentials  I Face two problems while writing the code in swing program 1.i developed one application using swings that has username,password when i login
How to launch my web application from my desktop without opening Netbeans IDE everytime i run the application?
How to launch my web application from my desktop without opening Netbeans IDE... dont want all these steps, so i knw that java application can be launched using Java Web Start but dont knw abt web application, Is there any way to do
VoIP - Voice Over Internet Protocol
VoIP - Voice Over Internet Protocol          Vioce Over Internet or VOIP For Short is Promising technology for delivering the voice information over the Internet
finding java code on internet
finding java code on internet  Is there anybody to help me? i want to some java coding web sites.it is prerequest for me
RMI in internet - RMI
for controlling a PC from a remote location in Java. communication is done through internet. so is it possible to use RMI, or Sockets for internet communication? can we use RMI to communicate with any host connected to internet using it's IP
should close the browser with user confirmation in javascript - Java Beginners
should close the browser with user confirmation in javascript  Hi, I need to close the browser with the user confirmation. If the user accept olny he/she can close the browser otherwise can't close the browser. How can I do
Browser making by java coding
Browser making by java coding  import javax.swing.*; import...*; import java.io.*; public class Browser extends JFrame implements...[]) { if(args.length==0) new Browser ("http:google.com"#; else new Browser#args#0
Toolbar to a browser - Java Beginners
to display toolbar on the browser? Thanks  I want to create a website's... browser, some site ask us to download the application and install it. so i wanted
Java Program
Java Program  A Simple program of JSP to Display message, with steps to execute that program   Hi Friend, Follow these steps: 1)Go... and press enter. 9)You jsp program will then display the output on the browser
JAVA SCRIPT CODE FOR OPENING A WEBSITE IN A NEW WINDOW - Java Beginners
JAVA SCRIPT CODE FOR OPENING A WEBSITE IN A NEW WINDOW   PLS TELL ME? HOW CAN I DEFINE A WINDOW.OPEN FUNCTION WITHIN ANOTHER FUNCTION e.g IF THERE ARE THREE FIELDS OF A FORM, AND AFTER CKECKING THAT ALL THE FIELDS HAVING
Resize browser in flex
Resize browser in flex  Hi........ Please tell me about How can I Resize the Internet Explorer browser window from flex ? please give me the appropriate answer Thanks  Ans: UsegetURL() to communicate
Rich Internet Application
. Usually a Rich Internet Application runs in a Web browser. It does not need...Rich Internet Application The term RIA (Rich Internet Applications) refers... applications, it means Rich Internet Applications are a cross between web
Applet in Java
Applet is a Java program designed for execution within the web browser. They are embedded into HTML pages and run on Java enabled web browsers like Mozilla... the Internet and run them. An Applet is a Java subclass that extends
Rich Internet Application Development
Rich Internet Application Development   ... of restrictions and requirements remaining in it. These are: Browser approval: Many... in writing RIA that cannot run in all platforms. After evaluation of Java 1.1
JavaFX: New Paradigm in Rich Internet Applications
, a family of products based on Java technology to create Rich Internet applications... JavaFX: New Paradigm in Rich Internet Applications  ... prevailing with the rich internet application (RIA) development landscape
browser
browser  how to make a browser
Browser tire - Java Interview Questions
Browser tire  If we use multithreading in my application then which tire is needed on clients browser so that application run successfully? Plz help me ass soon as possible
Internet Phone Services
Internet Phone Services          Introduction VoIP or voice over internet Protocol is that technology which makes it possible to make phone calls through the internet
Rich Internet Applications Benefits
Rich Internet Applications Benefits Rich Internet Applications provides grates... for web applications. The deployment cost of Rich Internet Applications are also very low, as it only requires web browser to use the application at client
How to get browser time zone?
How to get browser time zone?  How to get browser Time Zone and browser date using java concept
java code to get the internet explorer version
java code to get the internet explorer version  Hi, Could u plz help me in finding the internet explorer version using java code...i have the javascript but i want this in java code... Thanks, Pawan