• Post Reply Bookmark Topic Watch Topic
  • New Topic

Opening a webpage via a component?  RSS feed

 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried?
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 56518
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nor should you care about it.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah true, makes sense, thanks all! I'll see how it goes!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!