Here is a very simple segment of code. What I want is when I click on the button "First Button" then the window become empty. What actually happens is the window just becomes unresponsive. What could be the problem and what could be a solution??
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
/**
*
* @author Muhammad Anas
*/
public class ClearingJframe
{
private static JFrame mainWindow;
public static void main(String[] args)
{
mainWindow = new JFrame( "Clearing a JFrame" );
mainWindow.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
JButton button1 = new JButton( "First Button" );
mainWindow.add( button1 );
button1.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent eve )
{
mainWindow.removeAll();
}
}
);
mainWindow.pack();
mainWindow.setLocation( 500, 500 );
mainWindow.setVisible( true );
}
}
Currently I want not to be concerned with issues like Event Dispatch Thread etc. for atleast today because I have not studied Multi Threading yet (Actually all discusions about this issue that I found via google are mixed up with the discusion of these topics). So, if a quick and dirty solution is possible then for now, I would preffer that.
Thanks!!