GUI (graphical user interface), gui graphical user interface

Source: Internet
Author: User

GUI (graphical user interface), gui graphical user interface

AWT Overview

The full name of GUI is Graphical User Interface, which is a Graphical User Interface provided by an application for User operations, including windows, menus, buttons, toolbar, and other graphic Interface elements.

The GUI Design provides a wide range of class libraries, which are located in the java. awt and javax. swing packages.
Swing not only implements all the functions in AWT, but also provides richer components and functions to meet all the requirements of GUI Design.

AWT event processing
Event Processing Mechanism
The event processing mechanism is used to respond to user operations. For example, if you want to respond to user operations such as clicking the mouse or pressing the keyboard, you need to use the AWT event processing mechanism.

Common event categories
Form event
WindowEvent is used to represent these form events. In an application, when processing form events, you must first define a class to implement the WindowListener interface as the form listener, and then use addWindowListener () method: bind the form object to the form listener

Mouse events
The MouseEvent class is used to represent mouse events. Almost all components can generate mouse events, including mouse clicking, mouse releasing, and mouse clicking.
To handle mouse events, you can implement the MouseListener interface or inherit the adapter MouseAdapter class, and then call the addMouseListener () method to bind the listener to the event source object.

Keyboard Events
Keyboard operations are also the most common user interaction methods, such as pressing and releasing the keyboard. These operations are defined as Keyboard Events.
The KeyEvent class indicates a keyboard event. The Listener object for processing the KeyEvent event must implement the KeyListener interface or inherit the KeyAdapter class.

Action event
In Java, Action events are represented by the ActionEvent class. The Listener object for processing ActionEvent events must implement the ActionListener interface, it does not process the mouse movement and click details like a mouse event, but processes "meaningful" events like "button Press.

Layout manager
FlowLayout streaming layout manager
When you use the FlowLayout layout manager, the container places the components from left to right in the order of addition. When the container boundary is reached, the component is automatically placed at the beginning of the next line. These components can be left-aligned, center-aligned (default), or right-aligned

BorderLayout border layout manager
Is a more complex layout, which divides containers into five areas, namely EAST, SOUTH, WEST, and NORTH) CENTER ). The component can be placed in any of the five regions.

GridLayout grid layout manager
Use a vertical line to divide the container into n rows and m columns of the same size grid, and place a component in each grid.

GridBagLayout grid package layout manager
Similar to the GridLayout layout manager, it allows components in the grid to be different in size and one component to span one or more grids.

CardLayout card layout manager
View the interface as a series of cards. At any time, only one card is visible and occupies the entire area of the container.

BoxLayout box layout manager

Do not use layout manager
If you do not want to use the layout manager to layout the container, you can call the setLayout (null) method of the container to cancel the layout manager.
When the layout manager is not used, the program must call the setSize () and setLocation () methods of each component in the container or the setBounds () method (this method receives four parameters, are the x and y coordinates in the upper left corner and the length and width of the component) to locate these components in the container.

Swing


Programming Philosophy

MVC Mode
Model M (data) and view V (Display) are separated, and the two are loosely coupled through controller C.
Observer Mode
Dimit Law

Listener (interface callback)
Anonymous internal class (interface object for local instantiation)
The window class implements the listener interface and overwrites the callback method.
Internal class implements listener interface and overwrites callback Method
Create an internal class object as a listener for one or more controls
Internal classes can access private members (Controls) of external classes)

Default Adapter
MouseListener/MouseMotionListener/MouseWheelListener
MouseAdapter

KeyListener
KeyAdapter

WindowListener
WindowAdapter

Window
JFrame
JFrame and Frame are independent top-level windows and cannot be placed in other containers. JFrame supports all basic functions of common windows, such as window minimization and window size setting.

JDialog
JDialog is another top-level window of Swing. It represents the Dialog box like Dialog.
The JDialog dialog box can be divided into two types: Modal Dialog Box and non-modal dialog box.
Non-Modal Dialog Box
Allows users to interact with other windows while handling the dialog box
Modal Dialog Box
The user can continue to interact with other windows only after the dialog box is processed.

JInternalFrame multi-document window (subwindow)
JWindow borderless window

Intermediate container

JPanel
The method is basically the same as that of the Panel component in AWT. It is a non-border Panel that cannot be moved, zoomed in, zoomed out, or closed. Its default layout manager is FlowLayout. You can also use the constructor JPanel (LayoutManager layout) or its setLayout () method to create a layout manager for it.

JScrollPane with scroll bar
A panel container with a scroll bar, and only one component can be added to this Panel. To add multiple components to the JScrollPane panel, add the components to the JPanel first, and then add the JPanel to the JScrollPane.

JSplitPane with Splitters
JTabbedPane with tabs)
Jsf-toppane can be placed in a subwindow

Text Components
It is used to receive or display user input information, including text boxes (JTextField) and text fields (JTextArea). They all have a common parent class JTextComponent and JTextComponent is an abstract class, it provides common methods for text Components

The JTextComponent class has two subclasses: JTextField and JTextArea.
JTextField is called a text box. It can only receive single-line text input.
JTextArea: called a text field, JTextArea can receive input from multiple lines of text.

Button Components
Common button components include JButton, JCheckBox, and JRadioButton. They are directly or indirectly subclasses of the AbstractButton class.

The JCheckBox component is called a check box. It has two statuses: Select (yes) and unselected (non). If you want to receive only the "yes" and "Non" inputs ", you can use the check box to switch the status. If there are multiple check boxes, you can select one or more of them.

The JRadioButton component is called a single-choice button. Unlike the JCheckBox check box, only one single-choice button can be selected, just like the radio selection button on the radio. When one is clicked, the previously pressed button automatically pops up. For the JRadioButton button, when a button is selected, the previously selected button is automatically deselected.

JComboBox
It is called a combo box or drop-down list box. It folds all options and adds them to the Favorites list. By default, it displays the first added option. When you click the combo box, a drop-down list is displayed. You can select and display one of them.

Menu Components
Menu components include drop-down menus and pop-up menus.
The drop-down menu includes JMenuBar, JMenu, and JMenuItem)

JMenuBar: indicates a horizontal menu bar, which is used to manage menus and does not participate in interactive operations with users.
JMenu: indicates a menu, which is used to integrate and manage menu items. A menu can be a single-level structure or a multi-level structure.
JMenuItem: JMenuItem indicates a menu item, which is the most basic component in the menu system. Like the JMenu menu, when creating a JMenuItem menu item, the JMenumItem (String text) constructor is usually used to specify text content for the menu item.

To create a drop-down menu, follow these steps:
1. Create a JMenuBar menu bar object and place it at the top of the JFrame window.
2. Create a JMenu object and add it to the JMenuBar menu bar.
3. Create a JMenuItem menu item and add it to the JMenu menu.

In the Swing component of Java, the pop-up menu is represented by JPopupMenu.
The JPopupMenu pop-up menu and drop-down menu are both added by calling the add () method, but it is invisible by default. If you want to display it, the show (Component invoker, int x, int y) method must be called.

Common controls

Basic controls
JLabel label
Icon
Font
JButton
JTextField text box
JPasswordField Password box
JRadioButton single choice button ButtonGroup
JCheckBox check box
JCombBox drop-down list ListCellRender
JList ListCellRender
JTextArea text field
JOptionPane pop-up mode dialog box
JFileChooser file Selector
JColorChooser color selector
Advanced controls
JMenu menu JMenuItem menu item
JPopupMenu context menu (right-click menu) JMenuItem menu item
JToolBar Toolbar
JEditorPane editing panel
JProgressBar progress bar
JSlider Slider
JSpinner Debugger
JTable TableCellRender
JTree TreeCellRender

AWT plotting
Update (Graphics g)
Repaint ()
Paint (Graphics g)

Swing plotting
PaintComponent (Graphics g)
PaintBorder (Graphics g)
PaintChildren (Graphics g)

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.