⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawgui.java

📁 校园卡模拟,实现校园卡的基本功能
💻 JAVA
字号:
//********************************************************************
//名称:校园卡DrawGUI
//作用:创建校园卡操作界面
//**********************************************************************

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

public class DrawGUI extends JFrame
{

		JButton btnLogin=new JButton("登陆 / 确定");                             //创建按钮

	    JButton btnUpdate=new JButton("重新注册");

	    JRadioButton radRepassword=new JRadioButton("修改密码");                //创建单选按钮
	    JRadioButton radAddmoney=new JRadioButton("添加金额");
	    JRadioButton radConsume=new JRadioButton("消----费");
	    JRadioButton radFind=new JRadioButton("查询余额");

        static   JTextField txtName=new JTextField();
        static   JTextField txtNumber=new JTextField();                        //创建文本框
        static   JPasswordField txtPassword=new  JPasswordField();
        static   JPasswordField txtNewpassword=new  JPasswordField();
        static   JTextField txtAddmoney=new JTextField();
        static   JTextField txtConsume=new JTextField();

        JLabel lbWelcome=new JLabel("欢迎您使用校园卡系统!!",JLabel.LEFT);   //创建标签
        JLabel lbChoice=new JLabel("选择操作",JLabel.LEFT);
        static JLabel lbCardtype=new JLabel("注册并登陆",JLabel.CENTER);
        static JLabel lbuser=new JLabel("",JLabel.RIGHT);
        static JLabel lbName=new JLabel("您的用户名:",JLabel.LEFT);
        static JLabel lbNumber=new JLabel("您 的 帐号:",JLabel.LEFT);
        static JLabel lbPassword=new JLabel("您 的 密码:",JLabel.LEFT);
        static JLabel lbNewpassword=new JLabel("您的新密码:",JLabel.LEFT);
        static JLabel lbAddmoney=new JLabel("添加 金额:",JLabel.LEFT);
        static JLabel lbConsume=new JLabel("消费 金额:",JLabel.LEFT);

        ButtonGroup radioGroup=new ButtonGroup();                                   //创建单选按钮组

        RadioButtonListener rbListener=new RadioButtonListener();                  //创建监视器实例对象
        LoginButtonListener lbListener=new LoginButtonListener();
        RestButtonListener ubListener=new RestButtonListener();
        FrameButtonListener fListener=new FrameButtonListener();

        DrawGUI()
        {

			Container c=getContentPane();                     //创建容器对象
			    c.setLayout(null);

			c.add(btnLogin);                                  //添加框架组件
			c.add(btnUpdate);

			c.add(txtName);
			c.add(txtNumber);
			c.add(txtPassword);
			c.add(txtNewpassword);
            c.add(txtAddmoney);
            c.add(txtConsume);

            c.add(lbWelcome);
            c.add(lbChoice);
            c.add(lbCardtype);
            c.add(lbuser);
            c.add(lbName);
            c.add(lbNumber);
            c.add(lbPassword);
            c.add(lbNewpassword);
            c.add(lbAddmoney);
            c.add(lbConsume);

            c.add(radRepassword);
            c.add(radAddmoney);
            c.add(radConsume);
            c.add(radFind);

            radioGroup.add(radRepassword);   //加单选按钮进单选按钮组
            radioGroup.add(radAddmoney);
            radioGroup.add(radConsume);
            radioGroup.add(radFind);

            lbWelcome.setFont(new Font("宋体",Font.BOLD,15));      //为三个标签加入字体大小设计
            lbChoice.setFont(new Font("宋体",Font.BOLD,15));
            lbCardtype.setFont(new Font("宋体",Font.BOLD,15));
            lbuser.setFont(new Font("宋体",Font.BOLD,20));


            txtNumber.setVisible(false);          //刚开始时帐号,新密码,添加金额和消费输入不可见
 			txtNewpassword.setVisible(false);
            txtAddmoney.setVisible(false);
            txtConsume.setVisible(false);
            lbNumber.setVisible(false);          //刚开始时帐号,新密码,添加金额和消费输入提示不可见
			lbNewpassword.setVisible(false);
			lbAddmoney.setVisible(false);
			lbConsume.setVisible(false);


           radRepassword.addActionListener(rbListener);  //创建监视器
           radAddmoney.addActionListener(rbListener);
           radConsume.addActionListener(rbListener);
           radFind.addActionListener(rbListener);

           btnLogin.addActionListener(lbListener);
           btnUpdate.addActionListener(ubListener);

           this.addWindowListener(fListener);


            radRepassword.setBounds(50,90,150,40);  //各个组件在框架中的固定布局
            radAddmoney.setBounds(50,140,150,40);
            radConsume.setBounds(50,190,150,40);
            radFind.setBounds(50,240,150,40);

            lbuser.setBounds(80,10,80,40);
            lbWelcome.setBounds(180,10,220,40);
            lbChoice.setBounds(70,50,200,40);
            lbCardtype.setBounds(200,50,200,40);
            lbName.setBounds(210,90,100,30);
            lbNumber.setBounds(210,130,100,30);
            lbPassword.setBounds(210,170,100,30);
            lbNewpassword.setBounds(210,210,100,30);
            lbAddmoney.setBounds(210,250,100,30);
            lbConsume.setBounds(210,290,100,30);

            txtName.setBounds(310,90,80,30);
            txtNumber.setBounds(310,130,80,30);
            txtPassword.setBounds(310,170,80,30);
            txtNewpassword.setBounds(310,210,80,30);
            txtAddmoney.setBounds(310,250,80,30);
            txtConsume.setBounds(310,290,80,30);

            btnLogin.setBounds(100,350,100,40);
            btnUpdate.setBounds(250,350,100,40);

            setSize(500,450);             //设置框架大小
            setTitle("校园卡系统");       //设置标题
            setVisible(true);             //使框架可见
            setResizable(false);          //防止用户设置框架大小
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -