I want to make: when i click a button after I've given some input it checks & if successful it opens a new window/page i.e I want to create a link....till now I've done

import javax.swing.JOptionPane;

public class inputwindow {

     * @param args
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //String id= "admin";
        //String pw= "admin";
        String name,pass = "";
        name = JOptionPane.showInputDialog("UserName");
        pass = JOptionPane.showInputDialog("Password");
        //String msg = "Hello " + name ;
        //JOptionPane.showMessageDialog(null, msg);
        if (name.equals("admin") && pass.equals("admin")) 
            JOptionPane.showMessageDialog(null, "login successful");
            else {
                JOptionPane.showMessageDialog(null,"you are not allowed");


here in the place of "login successful" i want to put somthing that will open a window to be specific I want open a "xyz" web application. for eg: "http://localhost:8080/xyz"......hope I've made myself clear....please suggest..thanks

Re: button with hyperlink....how? 80 80

I dont think you can use hyperlink in windows application

its only for web application

Re: button with hyperlink....how? 80 80

Read the Swing tutorial. You are looking for ActionListener.

Re: button with hyperlink....how? 80 80

As masijade said, you can do that with an ActionListener, however I have to wonder why you are writing a Java program just for a login and then opening a web application. Why not simply login in to the web application?

Re: button with hyperlink....how? 80 80

actually i want only "one person"/admin to enter a specific folder inside the application not the whole application as you said....could someone tip me some details about ActionListener....i'm bit confused!

Re: button with hyperlink....how? 80 80

What don't you understand. Be more specific.

Re: button with hyperlink....how? 80 80

I want to pass this URL
"http://localhost:8080/xyz/admin" as a parameter when the user clicks OK or enters the password in the JoptionPane.......is it possible with ActionListener.....how?

ps: how can I make both the username/password be taken from ONE dialog box? (as you can see i'm using 2boxes)

Re: button with hyperlink....how? 80 80

Read the API for JOptionPane. I assume you're letting him enter a URL, in that case you already have the URL, you simply need to capture the return value of the JOptionPane method. As I said, read the API for that (and the tutorial), it explains it completely.

Re: button with hyperlink....how? 80 80

I assume you're letting him enter a URL.

could'nt understand what you meant by that.
the user enters id/pw (both "admin")...if he enters correctly he will be given the access to the "admin" folder of the web application. the user does'nt enters any URL!!!....is there any tool other than JoptionPane that will make matters easier?

Re: button with hyperlink....how? 80 80

What do you mean "you want to pass it as a parameter". Explain, without reference to URLs, JOptionPanes, Parameter Passing, or anything else technical, what it is, exactly that you want to accomplish.

Re: button with hyperlink....how? 80 80

If you want to have both input fields on a single panel with one Ok button, you have two options:
- Create a standard JFrame/JPanel UI form with your fields and button and put the code that processes login and opens the browser in the ActionListener (or a small Action class).
- Create a custom dialog by extending JDialog and returning whether login was successful as the dialog result and opening your browser based on the result.

The JFrame is probably the easier and more conventional option, but there are a lot of ways to skin a cat in Java.

If you are using Java 6, this method will allow you to open a url in the default browser:

If not Java 6, then http://www.centerkey.com/java/browser/ may be of use.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.