Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jbutton to website

 
singh sagar
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you want to open that URL? In your preferred browser? In a custom control?
 
Nina Milo
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nina, that is a very platform specific solution. We need to wait on answers to Rob's questions before giving the best solution.
 
Ted Smyth
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did some googling and found this tidbit:

 
singh sagar
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone
I got my solution.


Java ranch is one of the most usefull website i have ever searched
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for writing wrong name.Its "Nina Milo Solution"
Thanks Nina Milo
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic