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?

    How would I go about getting a webpage to open when a button is clicked, in my java file (this is for a private server, but I though the main part of the question would be better suited to here.

    This is what I have so far:
    case 378:
    if (buttonId == 143) {
    (This is the part I am stuck on, is it possible to put a line/some lines of code here, or anywhere else to make a webpage open when the button is clicked.

    Thanks!
     
  2. 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?

  3. 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?

    I did google it, but I couldn't find anything that I could understand particularly well, or anything that I felt was completely suited to what I wanted to do, thanks very much anyway though :)
     
  4. 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?

    I got that link on a thread which was the first link. So.
     
  5. 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?

    Why use org.jdesktop.jdic.desktop.Desktop? Doing so means that you'll have to include the JDIC library with your app which is kinda pointless as you could do virtually the same thing with java.awt.Desktop. o_O
     
  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?

    Well maybe we googled different things, any way that you look at it, I didn't find that.

    Are there any other ways that are good, for the reasons that jimmy stated?
     
  7. 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?

    In pseudo-code:
    Code:
    import java.awt.Desktop;
    
    class Example {
        static void showShit() {
            if(Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(new URI("www.mysite.com"));
                } catch (Exception e) {
                    System.out.println("Unable to go to site!");
                    e.printStackTrace();
                }
            }
        }
    }
     
  8. 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?

    Okay so basically, the above code is a new class, and the 'Desktop.getDesktop().browse(new URI("www.mysite.com"));' part is the line of code that I put into my existing class in order to make the site open when the button is clicked, or does it work by using the 'static void showShit(() { part to tell the server to refer to Example.class in when it is called?
     
  9. 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?

    Erm.. what?
     
  10. 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?

    well I assumed that if you put that somewhere it tells the program to go to the file with that in and then kind of do what that file says?

    I don't know to be honest, I'm just trying to make some sense out of it all :S
     
  11. 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?

    the showShit() method will open your website- just change the string arg for the uri to whatever your website is.
     
  12. 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?

    Ooops. I just copied and pasted the first answer I saw.... >_>.
     
  13. 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?

    Right, I understand everything that has been said so far, but once I have added that class into my files, what do I have to do with my other files (actionbuttons.java to be precise) in order for the webpage I have specified to open once I press the button on my screen.
     
  14. 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?

    Just do...

    if(buttonid=blah){
    if(Desktop.isDesktopSupported()) {
    try {
    Desktop.getDesktop().browse(new URI("www.mysite.com"));
    } catch (Exception e) {
    System.out.println("Unable to go to site!");
    e.printStackTrace();
    }
    }}
     
  15. 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?

    Unfortunately, that didn't work. Anyone got any other ideas?
     
  16. 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?

    Did you get an error?
     
  17. 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?

  18. 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?

    Delete the example class.... it was an example. u don't need it... >_>.
     
  19. 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?

    Nice you are pretty damn incompetent. Sorry to say but before you try programming it is always good to try and read up on the language you wish to be doing work in.
     
  20. 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?

    I have read up quite a lot on java, I just struggle to understand it sometimes. Thanks very much for the help so far anyway, I will give your suggestion a go SuF
     
< Java Doesn't Work | I have a question about Python >


 
 
Adblock breaks this site