• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jbutton to website

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you want to open that URL? In your preferred browser? In a custom control?
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
});
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did some googling and found this tidbit:

 
singh sagar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for writing wrong name.Its "Nina Milo Solution"
Thanks Nina Milo
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic