Differences between Windows frame dialog in AWT

Source: Internet
Author: User

9.2 window container

AWT provides three widgets used to display windows on the screen: window, frame, and dialog. We call it a window component.

Java. AWT. window is the most basic component of the three window components. The window component is the parent class of frame and dialog. It has no boundaries, title bars, and menus, and its size cannot be adjusted.

Java. AWT. frame is a subclass of window. It has boundaries and title bar settings, and the size can be adjusted. It can have a menu bar.

Java. AWT. dialog is also a subclass of window. It also has the border and title bar settings. The size can be adjusted, but it does not support the menu bar;

The window component triggers the window event javaswevent. Its listener is windowlistener. The interfaces include windowopened (javaswevent) and windowclosed (javaswevent). You can refer to the Help file; Java. AWT. event. the windowadapter class implements the windowlistener interface, but the methods in it are all empty methods. We can choose to implement some methods in the windowlistener interface.

The following uses frame, dialog, and filedialog as examples to describe the usage of window components.

9.2.1 frame class

An object created by the frame class or subclass in the Java. AWT package is a window (default layout: borderlayout ).

The main methods of the frame class:

Frame (): creates an unknown window.

Frame (string S): create a window named "S.

Setbounds (int A, int B, int width, int height ):

Setsize (INT width, int height ):

Setbackground (color C ):

Setvisible (Boolean B ):

Pack (): displays the window in a compact mode.

Settitle (string name ):

Gettitle (): Get the window name.

Setresizable (Boolean B ):

Example: example15_2.java

9.2.2 Dialog (dialog box) Class

Create a dialog box by extending the dialog class. The dialog class is a class in Java. AWT and also a container.

The dialog box can accept user input for interaction with users. The difference between a dialog box and a common window is that it depends on other windows. When the window on which it depends disappears or is minimized, the dialog box also disappears. When the window is restored, the dialog box is automatically restored.

The dialog box can be divided into two types: NO mode and no mode. The mode dialog box only allows the program to respond to events in the dialog box, and does not respond to events outside the dialog box, the stateless dialog box allows the program to respond to events other than the dialog box.

How do I define a dialog box class?

Create a dialog box through the sub-classes of dialog, that is, an object of the word class is a dialog box.

The main method of the dialog class is as follows:

Dialog (frame F, string S)

Dialog (frame F, string S, Boolean B)

Gettitle ()

Settitle (string S)

Setmodal (Boolean)

Setsize ()

Setvisible (Boolean B)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.