📄 login.java
字号:
package Java;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Toolkit;
public class Login extends JFrame implements ActionListener {
JLabel _jlid,_jlpass;
JTextField _jfid;
JPasswordField _jfpass;
JButton _jbsub,_jbcan;
JPanel _jp,_jp2,_jp3;
String userpopedom = "admin";
public Login() {
super("欢迎登录");
JLabel imagelabel = new JLabel();
ImageIcon icon = new ImageIcon("images/train.jpg");
imagelabel.setIcon(icon);
repaint();
_jlid = new JLabel(" ID号码 :");
_jlpass = new JLabel(" 密 码 :");
_jfid = new JTextField(8);
_jfid.addActionListener(this);
_jfpass = new JPasswordField(8);
_jfpass.addActionListener(this);
_jbsub = new JButton("提交");
_jbsub.addActionListener(this);
_jbcan = new JButton("取消");
_jbcan.addActionListener(this);
_jp = new JPanel();
_jp2 = new JPanel(new GridLayout(2,2));
_jp3 = new JPanel();
_jp.add(imagelabel);
_jp2.add(_jlid);
_jp2.add(_jfid);
JPanel _p2 = new JPanel();
_jp2.add(_jlpass);
_jp2.add(_jfpass);
_p2.add(_jp2);
_jp3.add(_jbsub);
_jp3.add(_jbcan);
this.add(_jp,"North");
this.add(_p2,"Center");
this.add(_jp3,"South");
pack();
setVisible(true);
setResizable(false);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
int W = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
int H = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
this.setLocation((W-this.getWidth())/2,(H-this.getHeight())/2);
}
public static void main (String[] args) {
new Login();
}
public void actionPerformed(ActionEvent e)
{
Conn conn = new Conn();
if(e.getSource()==_jbsub)
{
String username = _jfid.getText().trim();
String userpassword = new String(_jfpass.getPassword()).trim();
if(conn.Login(username,userpassword))
{
if(conn.ifadmin(username,userpassword,userpopedom))
{
dispose();
JOptionPane.showMessageDialog(this,"欢迎管理员登录!");
new Manage(username,userpassword,userpopedom);
}else
{
new Trainticket(username,userpassword);
}
dispose();
}else{
JOptionPane.showMessageDialog(this,"登录失败,请检查密码是否正确!");
}
}
if(e.getSource()==_jbcan)
{
System.exit(0);
}
if(e.getSource()==_jfid)
{
_jfpass.requestFocus(true);
}
if(e.getSource()==_jfpass)
{
_jbsub.requestFocus(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -