📄 denglu.java
字号:
package client;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import cmsc.c;
public class denglu extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
static denglu frm=new denglu();
static JTextField id;
static JPasswordField password;
static JLabel l1=new JLabel(""),l2=new JLabel(""),l3=new JLabel("");
static JButton denglu,chongzhi,sss;
public static void main(String[] args) {
frm.setTitle("用户登录");
frm.setSize(400,350);
frm.setLocation(340,200);
id=new JTextField(8);
password=new JPasswordField(8);
denglu=new JButton("登录");
chongzhi=new JButton("重置");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JPanel p5=new JPanel();
JPanel p6=new JPanel();
frm.setLayout(new GridLayout(6,1));
p1.add(l3);
p2.add(new JLabel("工号"));
p2.add(id);
p3.add(new JLabel("密码"));
p3.add(password);
p4.add(denglu);
p4.add(chongzhi);
p5.add(l1);
p6.add(l2);
frm.add(p1);
frm.add(p2);
frm.add(p5);
frm.add(p3);
frm.add(p6);
frm.add(p4);
denglu.addActionListener(frm);
chongzhi.addActionListener(frm);
frm.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});
frm.setResizable(false);
frm.setVisible(true);
}
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e){
sss=(JButton)e.getSource();
int idl=id.getText().length();
int pl=password.getPassword().length;
l1.setForeground(Color.red);
l2.setForeground(Color.red);
manager mg=new manager();
Cmanager ymg=new Cmanager();
if(sss==denglu){
if(idl==0){
l1.setText("*工号不能为空");
}else{
if(idl>10){
l1.setText("*工号不能大于4个字节");
}else{
l1.setText("");
}
}
if(pl==0){
l2.setText("*密码不能为空");
}else{
if(pl>8){
l2.setText("*密码不能大于6个字节");
}else{
l2.setText("");
}
}
if(idl<=10&&idl!=0&&pl<=8&&pl!=0){
c.i=1;
c.o=false;
c.id=id.getText().toString().trim();
c.password=password.getText().toString().trim();
new Client();
if(c.i==0){
System.out.println("连接服务器失败");
}else{
if(!c.o){
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}else{
if(Integer.parseInt(id.getText().toString().trim())<=10000){
mg.start();
}else{
ymg.start();
}
frm.setVisible(false);
}
}
}
}
else{
id.setText("");
password.setText("");
l1.setText("");
l2.setText("");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -