Week Twelve Java learning summary

summarize:

This week a major learning event handling and other containers

1. form events (WindowListener) common interface method voidwindowActivated / windowDeactivated (WindowEvent e) ### voidwindowClosed / Closing / Iconified (WindoowEvent e) // when the window is closed up / shutting down / trigger monitor adapter 3. Adapter minimized : the user can override the inherited class after the method according to their own needs, you do not need to override all the abstract methods in the interface of the ###. 4. action event listener and handling ActionListener: handling button action events, so the button becomes more meaningful. voidactionPerFormed (ActionEvent e)

2. monitor adapter:

Monitor interface has many abstract method, when the implementation of the interface, you need to rewrite all of the methods, but often only use one or two of them, this is certainly a superfluous. So for purposes of simplicity, there are multiple methods for each listener interface adapter ### is equipped with a class that implements all interface methods, but each method does not do anything. Adapter classes by inheritance, which requires the use of a method of rewriting, without having to rewrite all of the methods, simple and convenient.

3.JPanel

A plurality of components may be added to the JPanel to implement complex arrangement, only one interface can have a JFrame form component, but there may be a plurality of JPanel panel assembly, but may also be used on JPanel FlowLayout, BorderLayout, GridLayout other # ## layout manager, which can be used in combination, to achieve a more complex layout effects.

4.JSplitPane

JSplitPane divided into two parts for windows. JSplitPane provide two constants in the end is to let you set the split vertically or horizontally split. These two constants are: HORIZONTAL_SPIT, VERTICAL_SPLIT

5.JTabbedPane

JTabbedPane can create a tab by clicking on the title or the icon to switch between tabs.

6.JScrollPane

The main function is to add a horizontal scroll bar for the displayed content.

7. Text components:

Single-line text input: JTextField

Password text entry box: JPasswordField

The basic idea of ​​java GUI program is based on JFrame that white object is a window screen window on the screen it is possible to maximize, minimize, close.

java graphical user interface (GUI) tool package containers in swing panel, contained in the javax.swing package, can be nested, function is to form the components having the same logic functions are combined, a lightweight containers, may be added to the JFrame form.

JLabel object can display text, images, or both simultaneously displayed. By setting the vertical and horizontal alignment, specify the label display area where the tag content aligned. By default, the label is aligned vertically centered in the display area. By default, only ### signed standard text is to start edge alignment. Display only the label level of the image centered.

JTextField # multi text input components: JTextArea

Java on the machine Code:

package swing;

import javax.swing.*;
import java.awt.*;

public class Java登录界面{
            
    JFrame frame;
    JButton reset,submit;
    JLabel namelb,passlb;
    JTextField name;
    JPasswordField jpf;
    
    public Java登录界面() {
        
        frame=new JFrame("登录界面");
        reset=new JButton("重置");
        submit=new JButton("登录");
        namelb=new JLabel("用户名");
        passlb=new JLabel("密码");
        name=new JTextField();
        jpf=new JPasswordField();
        
        namelb.setBounds(5,5,60,20);
        passlb.setBounds(5,30,60,20);
        name.setBounds(65,5,100,20);
        jpf.setBounds(65,30,100,20);
        submit.setBounds(165,5,60,20);
        reset.setBounds(165,30,60,20);
}

I did not do it and continue to do it;

1, GridBagLayout GridBagLayout
evolved in GridLayout, based on more flexible than GridLayout. . The most powerful, but also the most complex
2, CardLayout card layout
all of the components container (usually containers) as a stack of cards, only one card (component a);

Guess you like

Origin www.cnblogs.com/tengziqiang/p/11872325.html