I am creating a quiz and have created a class with a JFrame which sort of acts like the main menu. On this menu, I have created a JButton which I want to open the seperate JDialog (which will contain the questions etc).
The JDialog is a seperate class called questionDialog.java
I believe you have to implement an action listener calling setVisible(true) however when I do that, I get a cannot make static reference to non-static method setvisible error.
Any help would be greatly appreciated, I am using eclipse and Jigloo for the GUI
here is my code in my main menu JFrame class, specifically the code for the button I want to open the new JDialog public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { NewJFrame inst = new NewJFrame(); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); }
startButton = new JButton();
getContentPane().add(startButton);
startButton.setText("Start Quiz");
startButton.setBounds(454, 239, 65, 23);
And here is the code which gives me the error
startButton = new JButton();
getContentPane().add(startButton);
startButton.setText("Start Quiz");
startButton.setBounds(454, 239, 65, 23);
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent)
{
questionDialog.setVisible(true);
}
});
Here is the code from the seperate JDialog class
package ZillionaireGUI;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class questionDialog extends javax.swing.JDialog {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame();
questionDialog inst = new questionDialog(frame);
inst.setVisible(true);
}
});
}
public questionDialog(JFrame frame) {
super(frame);
initGUI();
}
private void initGUI() {
try {
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
}
questionDialog.setVisible(true)
. Is that the case? – SharpKnight