• Log in or sign up for an account here: https://www.sythe.org/login

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

bad_moose

Guru
Joined
Jul 31, 2008
Sythe Gold
0
Messages
1,305
Location
UK
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!
 
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 :)
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
I got that link on a thread which was the first link. So.
 
I got that link on a thread which was the first link. So.
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
 
I got that link on a thread which was the first link. So.
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?
 
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?

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();
            }
        }
    }
}
 
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();
            }
        }
    }
}
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?
 
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
 
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
the showShit() method will open your website- just change the string arg for the uri to whatever your website is.
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
Ooops. I just copied and pasted the first answer I saw.... >_>.
 
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.
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
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();
}
}}
 
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();
}
}}
Unfortunately, that didn't work. Anyone got any other ideas?
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
Did you get an error?
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
Delete the example class.... it was an example. u don't need it... >_>.
 
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.
 
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
 
Runescape Gamblingrunescape gambling
Back
Top