📄 login.java
字号:
package yd.pethospital.login.view;
import java.awt.*; //导入包
import java.awt.event.*;
import javax.swing.*;
import yd.pethospital.login.business.*;
public class Login {
public static JFrame frame;
public static int Mess; //用于信息框
public static JButton BSure,BCancel; //确定和取消按钮
JLabel LCode,LPassword; //编号和密码的标签
public static JTextField TCode; //用户编号的文本框
public static JPasswordField TPassword; //密码框
public static Login login; //登陆对象
public Login(){
frame=new JFrame();
Toolkit Tk=Toolkit.getDefaultToolkit(); //得到屏幕大小
Dimension ScreenSize=Tk.getScreenSize();
int SWidth=ScreenSize.width;
int SHeight=ScreenSize.height;
frame.setBounds(SWidth/3, SHeight/3, 280, 220); //设置登陆窗体位置
frame.setLayout(null); //空布局
frame.setTitle("用户登陆"); //窗体标题
frame.setResizable(false); //不可改变窗体大小
frame.validate();
LCode=new JLabel("用户编号"); //实例化对象 标签
LCode.setBounds(25, 30, 80, 25); //标签的位置与大小
LCode.setFont(new Font(null,Font.BOLD,16)); //设置字体
frame.add(LCode); //将标签添加到窗体
LPassword=new JLabel("密 码");
LPassword.setBounds(25, 80, 80, 25);
LPassword.setFont(new Font(null,Font.BOLD,16));
frame.add(LPassword);
TCode=new JTextField(20); //实例化对象 文本框
TCode.setBounds(120,30,120,25);
TCode.setFont(new Font(null,Font.BOLD,14));
TCode.requestFocus(); //用于获得焦点
frame.add(TCode);
TPassword=new JPasswordField(20);
TPassword.setBounds(120,80,120,25);
TPassword.setFont(new Font(null,Font.BOLD,18));
TPassword.setEchoChar('*'); //使文本以“*”内容表现
frame.add(TPassword);
ImageIcon BIcon1=new ImageIcon("enter.png");
BSure=new JButton(BIcon1); //设置确定按钮
BSure.setBounds(40, 130, 60, 30);
BSure.setFont(new Font(null,Font.BOLD,12));
frame.add(BSure);
BSure.addActionListener(new ActionListener(){ //添加按钮的事件监听器
public void actionPerformed(ActionEvent e) {
new LoginBusiness(Login.frame);
}
});
ImageIcon BIcon2=new ImageIcon("exit.png");
BCancel=new JButton(BIcon2); //设置取消按钮
BCancel.setBounds(150, 130, 60, 30);
BCancel.setFont(new Font(null,Font.BOLD,12));
frame.add(BCancel);
BCancel.addActionListener(new ActionListener(){ //添加按钮的事件监听器
public void actionPerformed(ActionEvent arg0) {
Mess=JOptionPane.showConfirmDialog(null, "确认是否退出系统?", "系统信息提示", JOptionPane.YES_NO_OPTION); //确认信息对话框
if(Mess==JOptionPane.YES_OPTION){ //如果选择“确定”则退出系统
System.exit(0);
}
else{
TCode.requestFocus(); //否则返回登陆窗体 编号文本获得焦点
}
}
});
frame.setVisible(true); //设置窗体可视
}
public static void main(String[] args) {
login=new Login(); //为对象分配内存
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -