站内搜索: 请输入搜索关键词
当前页面: 图书首页 > SWT: The Standard Widget Toolkit

5.2 Display Life Cycle - SWT: The Standard Widget Toolkit

Previous Section  < Day Day Up >  Next Section

5.2 Display Life Cycle

Displays follow the same life cycle as widgets. They are explicitly created and disposed of by the programmer. Before you can do anything useful with SWT, you must create a display. When you are completely finished with the user interface for your application, call the dispose() method of Display.[2]

[2] Strictly speaking, this is not necessary if your program exits. In this case, all memory, including window system resources, is released back to the operating system. You should call the dispose method anyway because it will allow third-party operating system leak detection tools to distinguish between leaks and resources that were automatically released on shutdown.

5.2.1 Creation

Normally, displays are singletons. On some platforms, it is possible to have multiple displays active at the same time but this generally is not a useful programming metaphor. Instances of class Display are constructed using a simple no-parameter constructor.

Display() Constructs a new display that allows access to the platform window system.

5.2.2 Destruction

Displays are disposed of in the same manner as widgets, by calling their dispose() method.

dispose() Disposes of all operating system resources associated with the display.

Calling the dispose() method causes all widgets that were created on the display to also be disposed of. Accessing a display after the dispose method has been called causes an SWTException ("Device is disposed"). Displays support the method isDisposed() that returns true when the display has been disposed of and false otherwise.

    Previous Section  < Day Day Up >  Next Section