Im having problem with this code , it doesn't compile . Could you help me ?
I need to close the JFrame when i click the button
public class SlotMachine extends JFrame
JButton btnExit = new JButton("Exit");
public void mouseClicked(MouseEvent arg0)
this.dispose(); the key here being that
this refers to the inner class, the MouseListener, and MouseListener doesn't have a
Solution: get rid of
this, and it should work, since the compiler will then look into the outer class if the inner class does not contain the method. Alternatively you could specify which this you mean:
SlotMachine.this.dispose(); will tell the compiler to call the method of the outer SlotMachine class.
Use an ActionListener on a JButton for several reasons:
setEnabled(false), then pressing it should not cause the action to be fired. This does not work with MouseListener but does with ActionListener.