2 Replies - 10784 Views - Last Post: 09 May 2007 - 04:51 AM Rate Topic: -----

#1 Ryan747  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 16-October 06

Closing a Frame

Posted 15 November 2006 - 07:17 AM

Hi guys! I'm a beginner in java..... I just would like to know how to close a Frame when you press the close button because in JFrame it has a setDefaultCloseOperation function in it so when you press the close button the JFrame would close, but in a Frame I just don't know how...
Is This A Good Question/Topic? 0
  • +

Replies To: Closing a Frame

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Closing a Frame

Posted 15 November 2006 - 09:10 AM

You would create a WindowsListener and then inside the method exit your application.

Example of anonymous listener:
		//monitor the window for the close button to exit
		addWindowListener(new WindowAdapter()
		{
			public void windowClosed(WindowEvent event)
			{
				System.exit(0);
			}
		});

Was This Post Helpful? 0
  • +
  • -

#3 phantom2850  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-May 07

Re: Closing a Frame

Posted 09 May 2007 - 04:51 AM

View Postjayman9, on 15 Nov, 2006 - 09:10 AM, said:

You would create a WindowsListener and then inside the method exit your application.

Example of anonymous listener:
		//monitor the window for the close button to exit
		addWindowListener(new WindowAdapter()
		{
			public void windowClosed(WindowEvent event)
			{
				System.exit(0);
			}
		});


This would bring you out of your program...

Better way is:

	   //monitor the window for the close button to exit
		addWindowListener(new WindowAdapter()
		{
			public void windowClosed(WindowEvent event)
			{
				Frame f = (Frame) event.getSource();
								f.dispose();
			}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1