The moose likes Swing / AWT / SWT / JFace and the fly likes Jbutton to website Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Jbutton to website" Watch "Jbutton to website" New topic
Author

Jbutton to website

singh sagar
Ranch Hand

Joined: Sep 23, 2007
Posts: 30
Hi all
Can i have this functionality on a jbutton that when i click on it, i can open any website link(like www.saloon.javaranch.com)
Please Help
Thanks and regards
Sagar
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 17244

How do you want to open that URL? In your preferred browser? In a custom control?


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Nina Milo
Greenhorn

Joined: Jul 29, 2008
Posts: 19
Yes its possible.
Get the runtime instance of the application and then execute the command.All this should be implemented within the actionlistener. Hope this is helpful.

sample action listener code:
******************************************
JButton button1= new JButton("Button1");
button1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

try{

String command = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE http://java.sun.com/" ;

Process link = Runtime.getRuntime().exec(command);
}
catch(Exception ex){
System.out.println("cannot execute command. " +ex);
}
}
});
Gregg Bolinger
Sheriff

Joined: Jul 11, 2001
Posts: 15020

Nina, that is a very platform specific solution. We need to wait on answers to Rob's questions before giving the best solution.


My Blog | DZone Articles
Ted Smyth
Ranch Hand

Joined: May 28, 2008
Posts: 73
I did some googling and found this tidbit:



Edward Smith
singh sagar
Ranch Hand

Joined: Sep 23, 2007
Posts: 30
Thanks everyone
I got my solution.


Java ranch is one of the most usefull website i have ever searched
Gregg Bolinger
Sheriff

Joined: Jul 11, 2001
Posts: 15020

Originally posted by singh sagar:
Thanks everyone
I got my solution.


Care to share your solution with the rest of us?
singh sagar
Ranch Hand

Joined: Sep 23, 2007
Posts: 30
Care to share your solution with the rest of us?


Nino's solution was what i was looking for.

Thanks Again Nino .


singh sagar
Ranch Hand

Joined: Sep 23, 2007
Posts: 30
Sorry for writing wrong name.Its "Nina Milo Solution"
Thanks Nina Milo
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 32420
Be aware that this works only on an English-language Windows version. The BrowserLauncher class not only works on Windows versions in other languages, but also on other operating systems. Given how easy it would be to use that, I wouldn't consider what was posted above to be a proper solution.


Android appsImageJ pluginsJava web charts
 
 
subject: Jbutton to website
 
MyEclipse, The Clear Choice