Java上机实验报告(7)

实验 (7) 项目名称:组件及事件处理-注册页面

一、 实验报告内容一般包括以下几个内容:

  1. 实验项目名称 实验7 组件及事件处理-注册页面

  2. 实验目的和要求
    本实验的目的:
    本实验的目的是让学生掌握常用的组件类JButton,JTextField,JTextArea,JLabel,JCheckBox,JRadioButton, JPasswordField。
    实验具体要求:
    设计如下的注册界面:
    在这里插入图片描述

  3. 实验原理

  4. 主要仪器设备
    (1)学生每人一台PC机;
    (2)互联网环境。
    实验解答:
    Demo.java

package data20240418;

public class Demo {
    public static void main(String[] args) {
        new WinLogin();
    }
}

WinLogin.java

package data20240418;

import javax.swing.*;

public class WinLogin extends JFrame
{
    public WinLogin()
    {
        setLayout(null);
        init_name();//设置用户名和密码
        init_sex();//设置性别
        init_hobby();//设置爱好
        init_country();//设置国家
        init_self();//自我评价
        init_testpass();//验证码
        init_button();
        setTitle("注册界面");
        setBounds(500,200,400,350);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setVisible(true);
    }
    void init_name()
    {
        JLabel username=new JLabel("用户名");
        JLabel passwordOne=new JLabel("密码");
        JLabel passwordTwo=new JLabel("确认密码");
        JTextField nameText=new JTextField();
        JTextField passwordOneText=new JTextField();
        JTextField passwordTwoText=new JTextField();

        username.setBounds(30,20,100,20);
        passwordOne.setBounds(30,40,100,20);
        passwordTwo.setBounds(30,60,100,20);

        nameText.setBounds(100,20,150,20);
        passwordOneText.setBounds(100,40,150,20);
        passwordTwoText.setBounds(100,60,150,20);
        add(username);
        add(passwordOne);
        add(passwordTwo);
        add(nameText);
        add(passwordOneText);
        add(passwordTwoText);

    }
    void init_sex()
    {
        JLabel sex=new JLabel("性别");
        JRadioButton radioM=new JRadioButton("男");
        JRadioButton radioF=new JRadioButton("女");
        sex.setBounds(30,80,100,20);
        radioM.setBounds(100,80,50,20);
        radioF.setBounds(160,80,50,20);
        ButtonGroup group=new ButtonGroup();
        group.add(radioF);
        group.add(radioM);
        add(sex);
        add(radioM);
        add(radioF);
    }
    void init_hobby()
    {
        JLabel hobby = new JLabel("爱好");
        JCheckBox checkBox1,checkBox2,checkBox3,checkBox4;
        checkBox1 = new JCheckBox("唱歌");
        checkBox2 = new JCheckBox("跳舞");
        checkBox3 = new JCheckBox("篮球");
        checkBox4 = new JCheckBox("游戏");
        hobby.setBounds(30,100,100,20);
        checkBox1.setBounds(100,100,50,20);
        checkBox2.setBounds(150,100,50,20);
        checkBox3.setBounds(200,100,50,20);
        checkBox4.setBounds(250,100,50,20);
        add(hobby);
        add(checkBox1);
        add(checkBox2);
        add(checkBox3);
        add(checkBox4);
    }
    void init_country()
    {
        JLabel country = new JLabel("国籍");
        JComboBox<String> comBox= new JComboBox<>();
        country.setBounds(30,120,100,20);
        comBox.addItem("中国");
        comBox.addItem("美国");
        comBox.addItem("俄罗斯");
        comBox.setBounds(100,120,100,20);
        add(country);
        add(comBox);
    }
    void init_self()
    {
        JLabel talk_self = new JLabel("自我评价");
        JTextArea textArea = new JTextArea();
        talk_self.setBounds(30,140,100,20);
        textArea.setBounds(100,140,150,60);
        add(talk_self);
        add(textArea);
    }
    void init_testpass()
    {
        JLabel testpass = new JLabel("验证码");
        JTextField textField = new JTextField();
        JButton button = new JButton("获取验证码");
        testpass.setBounds(30,220,100,20);
        textField.setBounds(100,220,120,20);
        button.setBounds(200,220,120,20);
        add(testpass);
        add(textField);
        add(button);
    }
    void init_button()
    {
        JButton button1 = new JButton("提交");
        JButton button2 = new JButton("验证");
        button1.setBounds(80,260,80,20);
        button2.setBounds(220,260,80,20);
        add(button1);
        add(button2);
    }
}

运行结果展示:
(没调背景色,因为加背景色太丑了)
在这里插入图片描述

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值