您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)

 

Content Index

Content Page # 9

Closing the main window and stopping the program

When the user indicates that the program is to exit, it should shut down gracefully. By convention there are at least two ways for the user to do this: 

    from a ‘close’ window icon 

    from an ‘exit’ menu command.

The program can be terminated (stopped) by the sending of a System.exit() message. This will work whatever the program was doing at the time. A well-designed program should tidy up before it does this. In many cases the program should ask the user if it is okay to close. 

For example, if you are editing a document in a word processor and click on the ‘close’ button, and there are some changes made since the last change, the word processor should ask if you want to save the work first. 

If stopping the program is uncomplicated — no files to save, for example — it can simply call System.exit() from within windowClosing()

So the windowClosing() method would look as follows:

public void windowClosing (WindowEvent e)

  {

  // terminate program

  System.exit(0);

  } 

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg