my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Jbutton to website Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
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
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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


GenRocket - Experts at Building Test Data
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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: 41085
    
  43
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jbutton to website
 
Similar Threads
Modify JToolBar buttons and actions
Using mouseClicked in swing
open the website entered in JTextField in browser
Drop Down Arrow in JButton
Mouse shift event coding - to trigger a predetermined sequence of images to a GUI