public static void
public static void

Reputation: 95

How do I make dialog windows in java?

I found a webpage on the java site on how to make dialog windows, but it isn't working when I try it. The site said to type:

JOptionPane.showMessageDialog(frame, "Window text.");

I'm just trying to make a window with a bit of text and an ok button, but when I type this in, my Eclipse IDE wants me to import something for the JOptionPane, and after I do that, it says the the "frame" part is incorrect, that it "cannot be resolved to a variable." What am I doing wrong here?

Upvotes: 0

Views: 1731

Answers (2)

user3079266
user3079266

Reputation:

The first parameter in the call to JOptionPane.showMessageDialog should be an instance of a JFrame or JWindow that you want to assign your message dialog to. If you don't have a JFrame or JWindow but still want to display the message dialog, just put in null as the first parameter, like this:

JOptionPane.showMessageDialog(null, "Window text.");

Upvotes: 3

MadProgrammer
MadProgrammer

Reputation: 347184

Start by making sure you have included the import javax.swing.JOptionPane; statement within your import portion of your code.

Next, try using

JOptionPane.showMessageDialog(null, "Window text.");

instead.

For example...

import javax.swing.JOptionPane;

public class TestDialog {

    public static void main(String[] args) {
        JOptionPane.showMessageDialog(null, "Window text.");
    }

}

Take a closer look at How to Make Dialogs for more details.

You should also consult the JavaDocs when in doubt...

Upvotes: 5

Related Questions