Java Graphical user interface programming

Source: Internet
Author: User
Tags event listener

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

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.