Hi,

I can't figure out why my exit button is not working as all the other buttons in my code seem to be working. I have given the code below.

The constructor for the button is

private JButton exit;
....
add(exit);
....		
exit = new JButton("Exit");
exit.addActionListener(this);

The code for the ActionEvent is

Object eventSource = e.getSource();

if(eventSource == exit){
	textIO.setText("QUIT");
	System.exit(0);
}

Thanks

I would guess that you might be declaring a local "exit" button variable and adding that to the container, instead of the one that you have declared at the class level. I can't really say for certain with just the excepts that you posted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.