There are two frames and when you click on a button on the first frame it opens the second frame. On the second frame I'm trying to create a button which when pressed closes the JFrame without terminating the program but I'm having no luck. This is the code that I'm trying to use for the second frame, which without the button compiles fine:
class Time_First_Depot extends JFrame
{
Time_First_Depot()
{
Container c = getContentPane(); \\ creates content pane
c.setLayout ( null );
Color b = new Color(100,200,255); \\ set colour of JFrame
c.setBackground( b );
JButton exit = new JButton("EXIT"); \\creats button
exit.addActionListener(new ExitButtonListener()); \\ adds listener to button
exit.setForeground(Color.BLUE); \\edits buton
exit.setFont(new Font("Time", Font.BOLD, 12));
c.add(exit);\\adds button
exit.setBounds(250, 375, 90, 30);\\ sets location of button
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setBounds((int) screenSize.getWidth()/2 - 370, (int) screenSize.getHeight()/2 - 300, 600, 450); // set position and size
this.setResizable(false);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setTitle("Time");
this.setVisible(true);
this.setResizable(false);
}
}
class ExitButtonListener implements ActionListener
{
ExitButtonListener(){}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("EXIT"))
{
dispose();
}
}
}
While compiling I get the following error message:
cannot find symbol
symbol : method dispose()
location: class ExitButtonListener
dispose();
^
(Note: I've removed bits or irrelevant code that has nothing to do with the question.)
Thanks in advance for help anybody can give me.