[Java] Graphical interface design practical exercises

Graphical Interface Design (GUI) Practical Practice

The login interface of the student performance management system for practical exercises

Student performance management system 2.0 (graphic interface)

Example one

Insert picture description here
Code:

package Gui;

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

public class MyFrame extends JFrame {
    
    
    JPanel jP1,jp2,jp3;
    JLabel label1,label2;
    JButton button1,button2;
    JTextField text;
    JPasswordField password;

    public static void main(String[] args) {
    
    
        MyFrame myFrame = new MyFrame();
    }

    public MyFrame(){
    
    
        init();
        setTitle("登录界面");
        setBounds(300,300,250,150);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    void init(){
    
    
        setLayout(new GridLayout(3,1));
        jP1 = new JPanel();
        jp2 = new JPanel();
        jp3 = new JPanel();

        label1 = new JLabel("用户名");
        label2 = new JLabel("密 码");


        text = new JTextField(10);
        password = new JPasswordField(10);


        button1 = new JButton("登录");
        button2 = new JButton("取消");

        jP1.add(label1);
        jP1.add(text);

        jp2.add(label2);
        jp2.add(password);

        jp3.add(button1);
        jp3.add(button2);

        add(jP1);
        add(jp2);
        add(jp3);
    }
}

Example two

Insert picture description here

package Gui;

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

public class MyFrame extends JFrame {
    
    
    JPanel jp1,jp2,jp3;
    JCheckBox checkBox1,checkBox2,checkBox3;
    ButtonGroup group;
    JRadioButton radioM,radioF;
    JLabel label1,label2;
    JButton button1,button2;

    public static void main(String[] args) {
    
    
        MyFrame myFrame = new MyFrame();
    }

    public MyFrame(){
    
    
        init();
        setTitle("用户注册界面");
        setBounds(300,300,300,200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    void init(){
    
    
        setLayout(new GridLayout(3,1));
        jp1 = new JPanel();
        jp2 = new JPanel();
        jp3 = new JPanel();

        label1 = new JLabel("你喜欢的运动");
        label2 = new JLabel("你的性别");

        checkBox1 = new JCheckBox("足球");
        checkBox2= new JCheckBox("篮球");
        checkBox3 = new JCheckBox("网球");

        radioM = new JRadioButton("男");
        radioF = new JRadioButton("女");

        button1 = new JButton("注册用户");
        button2 = new JButton("取消用户");

        group = new ButtonGroup();
        group.add(radioM);
        group.add(radioF);

        jp1.add(label1);
        jp1.add(checkBox1);
        jp1.add(checkBox2);
        jp1.add(checkBox3);

        jp2.add(label2);
        jp2.add(radioM);
        jp2.add(radioF);

        jp3.add(button1);
        jp3.add(button2);

        add(jp1);
        add(jp2);
        add(jp3);


    }
}

Example three

Insert picture description here
Code:

package Gui;

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

public class MyFrame extends JFrame {
    
    
    JPanel jp1,jp2,jp3;
    JLabel label1,label2;
    JComboBox comboBox;
    JList list;
    JScrollPane jScrollPane;

    public static void main(String[] args) {
    
    
        MyFrame myFrame = new MyFrame();
    }

    public MyFrame(){
    
    
        init();
        setTitle("下拉框练习");
        setBounds(300,300,300,300);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    void init(){
    
    
        setLayout(new GridLayout(3,1));
        jp1 = new JPanel();
        jp2 = new JPanel();
        jp3 = new JPanel();

        label1 = new JLabel("你的籍贯是");
        label2 = new JLabel("你喜欢旅游的地区是");


        String []str1 = {
    
    "北京","上海","天津","重庆","江苏"};
        comboBox = new JComboBox(str1);

        String []str2 = {
    
    "黄山","故宫","长城","九寨沟","天安门","火星"};
        list = new JList(str2);
        list.setVisibleRowCount(1);
        jScrollPane = new JScrollPane(list);

        jp1.add(label1);
        jp1.add(comboBox);

        jp2.add(label2);
        jp2.add(jScrollPane);

        add(jp1);
        add(jp3);
        add(jp2);



    }
}

Example four

Insert picture description here
Code:

package Gui;

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

public class MyFrame extends JFrame {
    
    
    JSplitPane jSplitPane;
    JList list;
    JLabel label;

    public static void main(String[] args) {
    
    
        MyFrame myFrame = new MyFrame();
    }

    public MyFrame(){
    
    
        init();
        setBounds(300,300,400,300);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    void init(){
    
    
        String []words = {
    
    "boy","gril","bird","box"};
        list = new JList(words);

        label = new JLabel(new ImageIcon("idea_test/2.jpg"));
        jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,list,label);
        jSplitPane.setOneTouchExpandable(true);

        add(jSplitPane);



    }
}

Example 5

Insert picture description here
Code:

package Gui;

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

public class MyFrame extends JFrame {
    
    
    JSplitPane jSplitPane;
    JTextArea area;
    JTextField text;
    JComboBox comboBox;
    JButton button;
    JPanel jPanel;

    public static void main(String[] args) {
    
    
        MyFrame myFrame = new MyFrame();
    }

    public MyFrame(){
    
    
        init();
        setTitle("QQ登录");
        setBounds(300,300,300,200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    void init(){
    
    
        String str[] = {
    
    "北京","上海","南京","合肥","洛阳","哈尔滨"};
        comboBox = new JComboBox(str);
        area = new JTextArea();
        add(new JScrollPane(area));

        text = new JTextField(10);
        button = new JButton("发送");
        jPanel = new JPanel();
        jPanel.add(comboBox);
        jPanel.add(text);
        jPanel.add(button);

        add(jPanel,BorderLayout.SOUTH);
        //设置左上角小头像
        setIconImage((new ImageIcon("idea_test\\2.jpg")).getImage());



    }
}

Guess you like

Origin blog.csdn.net/weixin_48180029/article/details/113832942