Open InternetExplorer Webpage with Java

Open InternetExplorer Webpage with Java

Hello Sir I want to Open my webpage from swing application when I Click On
"VISIT US" Boutton then website will be display
How I can Create it on Button Click.
View Answers

March 20, 2010 at 4:23 PM

Hi Friend,

Try 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);
}
}

Hope that it will be helpful for you.
Thanks









Related Tutorials/Questions & Answers:
Open InternetExplorer Webpage with Java - Java Beginners
Open InternetExplorer Webpage with Java  Hello Sir I want to Open my webpage from swing application when I Click On "VISIT US" Boutton then website...(); final JTextField url =new JTextField(20); JButton button = new JButton("Open
webpage
webpage  design a webpage student database using forms and frameset
Advertisements
webpage
webpage  java, servlet and JSPs to create a web page with a text box and a button named submit. after submitting i shpuld get a msg successfully added
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?  How to export the table content from an webpage to excel using java? The table contents are generated dynamically in that java page
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?  How to export the table content from an webpage to excel using java? The table contents are generated dynamically in that java page
how to send the content of jtextarea from netbeans IDE to webpage's textarea in java
how to send the content of jtextarea from netbeans IDE to webpage's textarea in java   Hi, i m interested to send the content of my jtextarea which i have developed in netbeans IDE to the webpage's textarea. how can i do
webpage capture
webpage capture   webpage capture source code using jsps and servlets
How to find the size of a dynamic webpage using java... eg : Youtube........
How to find the size of a dynamic webpage using java... eg : Youtube........  package newpack; import java.io.BufferedInputStream; import...... Please help... Thanks, Ramit   the above code is running on JAVA
copy something from a webpage to my webpage
copy something from a webpage to my webpage  How can I copy something from a webpage to my webpage
Last modified time of a webpage
Last modified time of a webpage  how can we get the last modified time of a webpage using java
make a webpage
make a webpage   I will provide you some basic requirements that you will be implementing over a small web page... Requirements: A web page having... webpage in a different way Try to use features of HTML5, CSS3 and JavaScript
ModuleNotFoundError: No module named 'webpage'
ModuleNotFoundError: No module named 'webpage'  Hi, My Python... 'webpage' How to remove the ModuleNotFoundError: No module named 'webpage... to install padas library. You can install webpage python with following command
ModuleNotFoundError: No module named 'webpage'
ModuleNotFoundError: No module named 'webpage'  Hi, My Python... 'webpage' How to remove the ModuleNotFoundError: No module named 'webpage... to install padas library. You can install webpage python with following command
Showing div at the center of the webpage
Showing div at the center of the webpage  Showing div at the center of the webpage
Will i be able to get the content of a webpage in a word document (Note:i don t have access to the source code)through java code?
Will i be able to get the content of a webpage in a word document (Note:i don t have access to the source code)through java code?  public class... document to the webpage(for which i don t have access to source code
how to open java
how to open Java  how to open java file simple Java Example
ModuleNotFoundError: No module named 'webpage-reader'
ModuleNotFoundError: No module named 'webpage-reader'  Hi, My... named 'webpage-reader' How to remove the ModuleNotFoundError: No module named 'webpage-reader' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'webpage-reader'
ModuleNotFoundError: No module named 'webpage-reader'  Hi, My... named 'webpage-reader' How to remove the ModuleNotFoundError: No module named 'webpage-reader' error? Thanks   Hi, In your python
open source - Java Beginners
open source  hi! what is open source? i heard that SUN has released open source .what is re requisite to understand that open source. i know core concepts only  Hi friend, Open source is an approach to design
Java open source software
Open source software for Java In this page we will tell list down the most used Open source in Java. Java is one of the programming language used... is the list of java open source software used for the development and deployment
How to print a webpage without url and date in jsp ?
How to print a webpage without url and date in jsp ?  How to print a webpage without url and date in jsp
displaying a physical webpage with frames in iframe
displaying a physical webpage with frames in iframe  i have iframe in my webpage, i have done the coding part for browsing the folders and viewing... sources.i tried to display a sample webpage without frames and it was a success
how to open notepad using java
how to open notepad using java  Hi, how to open notepad using java? I want to open windows notepad from java program. Thanks   Hi, Use following code: import java.util.*; import java.io.*; class Notepad { public
Open Source Testing Tools in Java
Open Source Testing Tools in Java In this page we are discussing about the different Open Source Testing Tools available in Java. JUnit JUnit... by the developer who implements unit tests in Java. JUnit is Open Source Software
Open Jgraph Problem - Java Beginners
Open Jgraph Problem  Hi, I have go through the example given in http://sourceforge.net/projects/openjgraph/ for Open Jgraph by Jesus M. Salvo Jr... on this. I am a newbie in Java language. Thank you. Ulamraja
Parent child windows relationships when webpage is accesssed through a hyperlink.
Parent child windows relationships when webpage is accesssed through a hyperlink.  A particular session timeout functionality works when a webpage is loaded. The webpage has parent/child windows. This timeout functionality works
JSP - Problem of displaying result at webpage
JSP - Problem of displaying result at webpage  Can anyone please help to solve my problem below. My webpage has problem in displaying result position. The result should be display below my title. How do i solve it? Thank you so
Open Source software written in Java
Open Source software written in Java Open Source Software  or OSS... Code Coverage Open Source Java Collections API... Purpose ERP/CRM Written in Java Open Source
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
give me source code of webpage creation using html
give me source code of webpage creation using html  how to create a webpage using html
display resume content in webpage - JSP-Servlet
display resume content in webpage  Hi everbody, I have to display resume(.pdf, .doc,.rtf..txt)file content into a webpage(jsp or html). please i want help like are there any APIs available or any solution?? thank in advance
Page is not getting loaded when I refresh the webpage???
Page is not getting loaded when I refresh the webpage???  **I am loading an image section(image,demo link,Zoom) in a webpage by using javascript function in JSP. It will get all details of image section from database. *I am
Login Box appears at the background of my webpage?
Login Box appears at the background of my webpage?   As per the answer regarding my earlier query, when I post the code in my HTML page, the Login Box appears at the background of my HTMl page...........I tried CSS to change its
java code to open and display MS-word document
java code to open and display MS-word document  java code to open and display MS-word document
How to open a file in java using JFileChooser
How to open a file in java using JFileChooser  How to open a file in java using JFileChooser
how to open a file with a jbutton? - Java Beginners
how to open a file with a jbutton?  Hello Is it possible that by clicking on a button it can open java html file or doc exists on the pc? I searched and I found that it is possible to open a web page so I tried to open
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... = new JButton("Open Browser"); button.addActionListener(new ActionListener
open source web services tool java
Open Source web services tool in java        ...: The Web Services Invocation Framework (WSIF) is a simple Java API
displaying a calendar of only current month in jsp on webpage using javascript
displaying a calendar of only current month in jsp on webpage using javascript  how can we display a calendar of only current month in jsp on webpage using javascript
hi RoseIndia why there is not Fackbook Like button on your webpage?
hi RoseIndia why there is not Fackbook Like button on your webpage?   hi RoseIndia why there is no Fackbook Like button on your webpage? That's the only prob in your problem. Others are excellent
Open website on Button Click - Java Beginners
Open website on Button Click  Hello sir I want to open website on button click using java swing plz help me sir. in my swing application one "VISIT US BUTTON" i want to open my website on Button CLick  Hi Friend
open a bufferedwriter file in append mode - Java Beginners
open a bufferedwriter file in append mode  hi.. i jus want knw how to opena bufferedwriter file in append mode..  Hi friend, FileWriter...://www.roseindia.net/java/example/java/io/java-append-to-file.shtml Thanks
Open TextFile on JButton Click - Java Beginners
Open TextFile on JButton Click  Hello Sir I Want to open TextFile on JButton Click. plz Help Me  Hi Friend, Do you want to simply open the text file or you want to open the file using JFileChooser,read that file
how to display the data from excel to webpage
how to display the data from excel to webpage  Hi, I need help on following I have a webpage contains a text box and a button(get), i give a value in text box such as serial no. like 4024 and by click on get button it should
How to add google page in my webpage using jquery ajax.
How to add google page in my webpage using jquery ajax.  Hi, I created a page index.html on desktop . this page content following code. <html>... not open on my browser. how google page will load using ajax. thanks
Accessing MS ACCESS databse using a HTML webpage [created using Javascript]
Accessing MS ACCESS databse using a HTML webpage [created using Javascript... pressing the button - 'Submit'. the webpage includes fields like Name, Age, Sex... be displayed in a webpage after click the button - 'show details'. Could you pls help me
Maven Repository/Dependency: com.github.binarywang | weixin-java-open
Maven Repository/Dependency of Group ID com.github.binarywang and Artifact ID weixin-java-open. Latest version of com.github.binarywang:weixin-java-open dependencies. # Version Release Date
Open or Open Source Software
Open or Open Source Software  what is mean by open or open source software in Computer Terminology?   In a computer terminology, open or open source software means any technology or a software that are freely available

Ads