Java graphic user interface programming and java Graphic Programming

Source: Internet
Author: User

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

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.