Java graphic user interface programming and java Graphic Programming
1. Java graphical user interface programming Overview
Java API provides two sets of components to support the compilation of graphical user interfaces: AWT (Abstract Window package) and Swing
2. Container: heavyweight Container and lightweight Container (one Container can hold multiple containers)
A. heavyweight Container (top-level Container): cannot be contained in any other Container. Each contained level must start from the heavyweight Container and inherit from the AWT Container.
Heavyweight containers in Swing: JFrame (form), Jdialog (dialog box), JWindom (window), JApplet (applet)
B. Lightweight containers: they can be nested with each other and inherit from the Jcomponent of the Swing class.
Lightweight containers in Swing: JPanel, JSplitPane, JScrollpane, JTable, and JToolBar)
3. Component)
A. swing components: JButton, JRadioButton, JCheckBOx, JComboBox, JList, JTextField, and JTextArea), JMenu, JTable, and JTree B. three elements of components: content, visual display, and behavior C. layout of components in the container (use setLayout () to set the layout manager)
A. layout manager classification: FlowLayout, BorderLayout, GridLayout, and BoxLayout)
4. Create a simple application interface View
Step 1: create a form (JFrame)
JFrame jf = new JFrame ("login ");
JFrame Methods: setSize (), setBounds (), setVisible (), setResizable (), setLocationRelative (), etc.
Step 2: Set layout management
GridLayout la = new GridLayout (1, 3, 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: code execution based on events
A. Event: used to describe what happened...
B. Event Source: component that generates an event and triggers it
6. Event listener, registering and handling events
A. event listener: The Event source triggers an event. However, the event source does not process the event, but delegates it to an object interested in the event for processing, the object entrusted to process the event is called the event listener.
B. For an object to be an event listener on an event source, two events are required:
A. Create a listener object (the listener object must be an instance of the corresponding event listener Interface) B. register the listener object to the event source.
7. Optional methods for defining listener classesA. Define the listener class in A separate class B. Let the GUI program itself implement the listener Interface C. Define the listener class using the internal class of the member D. Use the anonymous internal class definition class
8. Model
SwingMVC model:
The basic idea of MVC: model, view, and control