File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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: 19781
    
  20

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: 15300
    
    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: 15300
    
    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: 42906
    
  69
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
 
subject: Jbutton to website