ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

【Java】图形界面设计实战练习

2021-02-17 17:58:53  阅读:243  来源: 互联网

标签:实战 Java 300 图形界面 add new jp2 public MyFrame


图形化界面设计(GUI)实战练习

学生成绩管理系统实战练习之登陆界面

学生成绩管理系统 2.0(图形界面)

实例一

在这里插入图片描述
代码:

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);
    }
}

实例二

在这里插入图片描述

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);


    }
}

实例三

在这里插入图片描述
代码:

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);



    }
}

实例四

在这里插入图片描述
代码:

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);



    }
}

实例五

在这里插入图片描述
代码:

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());



    }
}

标签:实战,Java,300,图形界面,add,new,jp2,public,MyFrame
来源: https://blog.csdn.net/weixin_48180029/article/details/113832942

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有