Adblock breaks this site

How to get a web page to open when a button is clicked?

Discussion in 'Programming General' started by bad_moose, Sep 13, 2009.

  1. bad_moose

    bad_moose Guru

    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0
    How to get a web page to open when a button is clicked?

  2. super_

    super_ Member

    Joined:
    Dec 20, 2008
    Posts:
    91
    Referrals:
    0
    Sythe Gold:
    0
    How to get a web page to open when a button is clicked?

    Ugh... have you ever heard of Sun's Java API docs? Desktop.browse() takes a java.net.URI object; it appears it can't locate that symbol (*cough* import java.net.URI; *cough*).
     
  3. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    How to get a web page to open when a button is clicked?

    Why don't you download Eclipse. It makes life a lot easier.
     
  4. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    How to get a web page to open when a button is clicked?

  5. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    How to get a web page to open when a button is clicked?

    My idea still helps. Sir.
     
  6. bad_moose

    bad_moose Guru

    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0
    How to get a web page to open when a button is clicked?

    Super, you are awesome, your idea worked, thanks very much!

    Thanks very much also to everyone else who posted, your advice really helped too ! :D
    Thanks!
     
  7. Canownueasy

    Canownueasy Newcomer

    Joined:
    Oct 3, 2009
    Posts:
    7
    Referrals:
    0
    Sythe Gold:
    0
    How to get a web page to open when a button is clicked?

    Wow, this shows that this community knows shit.

    First make a new class with this in it. Save as WebHandler.java

    Code:
    import java.awt.Desktop;
    
    public class WebHandler {
    
        public void openWebsite() {
            if(Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(new URI("www.yoursite.com"));
                } catch (Exception e) {
                    System.out.println("Error upon opening webpage.");
                    e.printStackTrace();
                }
            }
        }
    }
    Now under
    Code:
    if (buttonId == 143) {
    Add this.

    Code:
    openWebsite();
    }
    And in your Client, Player, and ActionButton class.

    Add this import:

    Code:
    import WebHandler;
     
  8. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    How to get a web page to open when a button is clicked?

    Which is pretty much what I stated, however you forgot to import java.net.URI in your WebHandler class. Also, you can't import classes in the default package like you tried to do with your "import WebHandler" statment.
     
  9. Canownueasy

    Canownueasy Newcomer

    Joined:
    Oct 3, 2009
    Posts:
    7
    Referrals:
    0
    Sythe Gold:
    0
    How to get a web page to open when a button is clicked?

    Well if he a packaged server he would need an import. :p
     
< Java Doesn't Work | I have a question about Python >


 
 
Adblock breaks this site