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

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

How to get a web page to open when a button is clicked?
  1. Unread #1 - Sep 13, 2009 at 9:34 AM
  2. bad_moose
    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0

    bad_moose Guru

    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!
     
  3. Unread #2 - Sep 13, 2009 at 9:46 AM
  4. SuF
    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

    SuF Legend
    Pirate Retired Global Moderator

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

  5. Unread #3 - Sep 13, 2009 at 10:08 AM
  6. bad_moose
    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0

    bad_moose Guru

    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 :)
     
  7. Unread #4 - Sep 13, 2009 at 11:34 AM
  8. SuF
    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

    SuF Legend
    Pirate Retired Global Moderator

    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.
     
  9. Unread #5 - Sep 13, 2009 at 11:39 AM
  10. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    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
     
  11. Unread #6 - Sep 13, 2009 at 11:52 AM
  12. bad_moose
    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0

    bad_moose Guru

    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?
     
  13. Unread #7 - Sep 13, 2009 at 12:40 PM
  14. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    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();
                }
            }
        }
    }
     
  15. Unread #8 - Sep 13, 2009 at 12:46 PM
  16. bad_moose
    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0

    bad_moose Guru

    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?
     
  17. Unread #9 - Sep 13, 2009 at 1:34 PM
  18. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

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

    Erm.. what?
     
  19. Unread #10 - Sep 13, 2009 at 1:54 PM
  20. bad_moose
    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0

    bad_moose Guru

    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
     
  21. Unread #11 - Sep 13, 2009 at 1:59 PM
  22. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    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.
     
  23. Unread #12 - Sep 13, 2009 at 4:30 PM
  24. SuF
    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

    SuF Legend
    Pirate Retired Global Moderator

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

    Ooops. I just copied and pasted the first answer I saw.... >_>.
     
  25. Unread #13 - Sep 13, 2009 at 5:14 PM
  26. bad_moose
    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0

    bad_moose Guru

    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.
     
  27. Unread #14 - Sep 13, 2009 at 5:21 PM
  28. SuF
    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

    SuF Legend
    Pirate Retired Global Moderator

    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();
    }
    }}
     
  29. Unread #15 - Sep 14, 2009 at 11:41 AM
  30. bad_moose
    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0

    bad_moose Guru

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

    Unfortunately, that didn't work. Anyone got any other ideas?
     
  31. Unread #16 - Sep 14, 2009 at 4:41 PM
  32. SuF
    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

    SuF Legend
    Pirate Retired Global Moderator

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

    Did you get an error?
     
  33. Unread #17 - Sep 14, 2009 at 5:10 PM
  34. bad_moose
    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0

    bad_moose Guru

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

  35. Unread #18 - Sep 14, 2009 at 5:23 PM
  36. SuF
    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

    SuF Legend
    Pirate Retired Global Moderator

    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... >_>.
     
  37. Unread #19 - Sep 15, 2009 at 8:45 AM
  38. super_
    Joined:
    Dec 20, 2008
    Posts:
    91
    Referrals:
    0
    Sythe Gold:
    0

    super_ Member

    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.
     
  39. Unread #20 - Sep 15, 2009 at 11:15 AM
  40. bad_moose
    Joined:
    Jul 31, 2008
    Posts:
    1,305
    Referrals:
    0
    Sythe Gold:
    0

    bad_moose Guru

    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 >

Users viewing this thread
1 guest


 
 
Adblock breaks this site