📄 login.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Login {
JFrame jf;
JLabel lab1, lab2;
JTextField text;
JPasswordField pw;
JButton jb1, jb2;
public static void main(String[] args) throws Exception {
new Login();
}
public Login() {
jf = new JFrame("登陆界面");
lab1 = new JLabel("请输入用户名:");
lab2 = new JLabel("请输入用户密码:");
pw = new JPasswordField(12);
text = new JTextField();
jf.setLayout(new GridLayout(3, 2));
jf.setSize(300, 120);
jf.setLocation(400, 300);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jb1 = new JButton("确定");
jb2 = new JButton("取消");
Container container = jf.getContentPane();
container.add(lab1);
container.add(text);
container.add(lab2);
container.add(pw);
container.add(jb1);
container.add(jb2);
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (text.getText().trim().equals("")) {
JOptionPane.showMessageDialog(null, "请输入用户名!");
return;
}
if (new String(pw.getPassword()).equals("")) {
JOptionPane.showMessageDialog(null, "请输入密码!");
}
if (new String(pw.getPassword()).equals("1234")) {
JFrame newframe = new theMain();
newframe.setSize(400, 400);
newframe.setLocation(340,250);
newframe.setVisible(true);
jf.dispose();
}else
{
JOptionPane.showMessageDialog(null,"密码错误");
}
}
});
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -