This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Opening a webpage via a component? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Opening a webpage via a component?" Watch "Opening a webpage via a component?" New topic
Author

Opening a webpage via a component?

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 354

So I want to be able to click a Picture Label to open a webpage. I found this API called Desktop

http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html

There is a method called


void browse(URI uri)
Launches the default browser to display a URI.

I assume this is all I would need?


Thanks!

~JO
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35241
    
    7
What happened when you tried?


Android appsImageJ pluginsJava web charts
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
Try the static Desktop#getDesktop() method to get an instance, then try the browse method. You are likely to have at least two checked Exceptions to handle.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 354

Campbell Ritchie wrote:Try the static Desktop#getDesktop() method to get an instance, then try the browse method. You are likely to have at least two checked Exceptions to handle.


thanks! I also found something on the Oracle trail about this, so I am going to read up.

I have a question regarding this class. There is no constructors. now I've done in the past things like and it worked. I didn't even need to import the API it seems. Why is that? I can do the same with the Desktop class which is why I'm bringing it up. It's pretty handy, and also seems to be the only way you can call the Desktop class unless you do(I believe) Object o = new Desktop(); But even then I'm not too sure since it might need a constructor... Is there a name for these, and/or a better place to read up on this?

Thanks!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 5868
    
    6

Jay Orsaw wrote:
Campbell Ritchie wrote:Try the static Desktop#getDesktop() method to get an instance, then try the browse method. You are likely to have at least two checked Exceptions to handle.


thanks! I also found something on the Oracle trail about this, so I am going to read up.

I have a question regarding this class. There is no constructors.


It's a class with all static methods. There is no state, so we're not intended to create any instances. There would be no reason. The purpose for creating an instance of an object is to hold some state that can be manipulated and queried. These methods simply take an input and give an output with no side effects that remain around for later use.

now I've done in the past things like and it worked.


Because that's a static method.

I didn't even need to import the API it seems.


java.lang.* is implicitly imported.

Is there a name for these


They're usually called helper classes or possibly utility classes. Some people mistakenly call them static classes, but that's incorrect. The class itself isn't static. (Only nested classes can be static, not top-level classes.) It's just that all its methods are.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
Jeff Verdegan wrote: . . . It's a class with all static methods. . . . we're not intended to create any instances. . . .
Are you sure? I think Desktop has got instance methods, and has got state. It only has a private constructor, and that method I quoted is a factory method. You don’t create an instance, but calling that method allows the class to create an instance and return it. Whether you get different instances from multiple calls, or whether you get the same instance which had been created and cached previously, I don’t know.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Nor should you care about it.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 354

Yeah true, makes sense, thanks all! I'll see how it goes!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Opening a webpage via a component?
 
Similar Threads
neither action class called nor jsp page displayed
iterator() in ArrayList
How to link JComboBox item with a webpage
using string value as a variable name
Whats On India Error