1.Java Graphical user Interface Programming Overview
Two sets of components are available in JAVAAPI to support the writing of graphical user interfaces: AWT (Abstract window package) and swing
2. Containers (Container): Heavy-weight containers and lightweight containers (one container can be placed in multiple containers)
A. Heavyweight container (top-level container): cannot be contained in any other container, each containing level must start with a heavyweight container and inherit from AWT's container
Heavyweight containers in swing: JFrame (Form), JDialog (dialog box), Jwindom (window), JApplet (applet)
B. Lightweight containers: can be nested with each other and inherit from the jcomponent of the Swing class
Lightweight containers in Swing: JPanel (panel), JSplitPane (divider pane), JScrollPane (scroll pane), JTable (tab pane), JToolBar (toolbars)
3. Components (Component)
A.swing Components: JButton (Button), Jradiobutton (radio button), Jcheckbox (check box), JComboBox (combo box), JList (list box), JTextField (text box), JTextArea (plain text area), JMenu (menu), JTable (table), JTree (tree) B. Three elements of a component: content, appearance, behavior c. Layout of components in containers (using the SetLayout () method to set the layout manager)
A. Layout Manager Category: Streaming layout manager (FlowLayout), Border layout Manager (borderlayout), Grid layout Manager (GridLayout), Box layout Manager (BoxLayout)
4. Create a simple application interface view
Step 1: Create a form (JFrame)
JFrame JF = new JFrame ("Landing");
JFrame methods: SetSize (), SetBounds (), setvisible (), setresizable (), setlocationrelative (), etc.
Step 2: Set up layout management
GridLayout la = new GridLayout (1,3,4,4);
This.setlyout (LA);
Step 3: Add components
JButton JB = new JButton ("");//button
This.add (jb,borderlayout.west);//Add button
JPanel JP = new JPanel ();//panel
5. Event-driven programming: How code is programmed to execute based on event occurrence
A. Event: Used to describe what happened ...
B. Event Source: A component that generates an event and triggers it
6. Event listeners, registering and handling events
A. Event listener: An event source triggers an event, but the event source itself does not handle the event, but instead delegates to the object that is interested in the event, which is called the event listener by the object being delegated to handle the event.
B. For an object, to be a listener for an event on an event source, two events are required:
A. Creating a listener object (the Listener object must be an instance of the corresponding event listener interface) B. Registering the Listener object on the event source
7. Optional methods for defining listener classesA. Defining a listener class in a separate Class B. Let the GUI program itself implement the listener interface C. Defining listener classes with member internal Classes D. Defining classes with anonymous inner classes
8. Model
SWINGMVC Model:
The basic idea of MVC: model, view part, control part
Java Graphical user interface programming