📄 serverlogin.java
字号:
import java.awt.HeadlessException;
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.JPasswordField;
import javax.swing.JTextField;
public class ServerLogin extends JFrame implements ActionListener {
private JLabel jLabel1;
private JLabel jLabel2;
private JPasswordField password;
private JLabel jLabel3;
private JButton jButton2;
private JButton jButton1;
private JTextField name;
public ServerLogin() throws HeadlessException {
this.setTitle("网络考试系统-服务端");
this.setResizable(false);
{
getContentPane().setLayout(null);
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1);
jLabel1.setText("\u7528\u6237\u540d");
jLabel1.setBounds(50, 69, 51, 15);
}
{
jLabel2 = new JLabel();
getContentPane().add(jLabel2);
jLabel2.setText("\u5bc6 \u7801");
jLabel2.setBounds(50, 104, 36, 22);
}
{
name = new JTextField();
getContentPane().add(name);
name.setBounds(107, 65, 121, 22);
}
{
password = new JPasswordField();
getContentPane().add(password);
password.setBounds(107, 104, 121, 22);
}
{
jButton1 = new JButton();
getContentPane().add(jButton1);
jButton1.setText("\u767b\u9646");
jButton1.setBounds(50, 148, 74, 22);
jButton1.addActionListener(this);
}
{
jButton2 = new JButton();
getContentPane().add(jButton2);
jButton2.setText("\u9000\u51fa");
jButton2.setBounds(163, 148, 76, 22);
}
{
jLabel3 = new JLabel();
getContentPane().add(jLabel3);
jLabel3.setText(" 管理员登陆");
jLabel3.setBounds(0, 0, 302, 53);
jButton2.addActionListener(this);
jLabel3.setBackground(new java.awt.Color(192, 192, 192));
jLabel3.setFont(new java.awt.Font("宋体", 1, 18));
jLabel3.setOpaque(true);
jLabel3.setDoubleBuffered(true);
jLabel3.setAutoscrolls(true);
}
}
{
this.setSize(303, 225);
this.setLocation(300, 180);
this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
validate();
}
}
public void actionPerformed(ActionEvent e) {
StudentManager st = new StudentManager();
if (e.getSource() == jButton1) {
String adminName = this.name.getText();
String adminPassword = new String(password.getPassword());
if (adminName == null || adminName.trim().equals("")) {
JOptionPane.showMessageDialog(this, "用户名不能为空");
this.name.setText(null);
this.password.setText(null);
return;
}
Admin admin = new Admin();
admin.setName(adminName);
admin.setPassword(adminPassword);
if (st.isLoginByAdmin(admin)) {
// JOptionPane.showMessageDialog(this,"登陆成功");
this.setVisible(false);
MainFrame mf = new MainFrame();
this.name.setText(null);
this.password.setText(null);
this.dispose();
} else {
JOptionPane.showMessageDialog(this, "用户名及密码错误");
this.name.setText(null);
this.password.setText(null);
return;
}
}
if (e.getSource() == jButton2) {
System.exit(0);
}
}
public static void main(String[] args) {
ServerLogin l = new ServerLogin();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -