So I am trying to make a button that opens a new frame.
The problem is that my main method is static so I can't put an action listener in the main part. I assume that I can make another class to make the action listener. So far I have this:
public class VertexAdd extends JPanel implements ActionListener { JButton button; public VertexAdd() { super(new BorderLayout()); [U]Main.AddVert.addActionListener(this);[/U] } public void actionPerformed(ActionEvent e) { createAndShowGUI(); } private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("FrameDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel emptyLabel = new JLabel(""); emptyLabel.setPreferredSize(new Dimension(175, 100)); frame.getContentPane().add(emptyLabel, BorderLayout.CENTER); //Display the window. frame.pack(); frame.setVisible(true); } }
It doesn't work right now and I am not sure how to make it so the action listener works. The button I want to attach it to is in my main class called 'AddVert'