Xxxu
2021-03-12 bd79403602e2192d84e83855c13132af0e623948
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import api.APIUtils;
import api.PostUtils;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;
 
public class LoginPanel extends JFrame {
 
    LoginPanel(){
        setIconImage(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("icon.png")));
 
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        setLayout(null);
        setSize(300, 120);
        setLocationRelativeTo(null);
        setTitle("Ï£ÃÎÒôÖùÈí¼þ-µÇ¼");
        Container cp = getContentPane();
        cp.setLayout(null);
 
        JLabel jl=new JLabel("µÇ¼Â룺");
        jl.setBounds(10, 10, 200, 25);
        final JTextField name=new JTextField();
        name.setBounds(80, 10, 150, 25);
 
        cp.add(jl);
        cp.add(name);
 
        //È·¶¨°´Å¥
        JButton jb = new JButton("È·¶¨");
        jb.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent arg0) {
                jb.setEnabled(false);
                if(name.getText().trim().equals("")){
                    JOptionPane.showMessageDialog(null, "µÇ¼Âë²»ÄÜΪ¿Õ");
                    jb.setEnabled(true);
                    return;
                }
                Map result = APIUtils.login(
                    name.getText().trim()
                );
 
                Integer status = (Integer) result.get("code");
                if(status == 0) {
                    PostUtils.token = (String) result.get("token");
                    if(PostUtils.token == null) {
                        JOptionPane.showMessageDialog(null, "µÇ¼Âë´íÎó»ò¹ýÆÚ,ÇëÖØÐ»ñÈ¡");
                        jb.setEnabled(true);
                        return;
                    }
                    setVisible(false);
                    try {
                        LabelMain.generatePanel();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }else if(status == 500){
                    JOptionPane.showMessageDialog(null, "µÇ¼Âë´íÎó");
                    jb.setEnabled(true);
                    return;
                }else{
                    JOptionPane.showMessageDialog(null, "δ֪´íÎó");
                    jb.setEnabled(true);
                    return;
                }
 
            }
        });
        jb.setBounds(80, 40, 60, 25);
        cp.add(jb);
 
        //ÖØÖð´Å¥
        final JButton button = new JButton();
        button.setText("ÖØÖÃ");
        button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent arg0) {
                // TODO ×Ô¶¯Éú³É·½·¨´æ¸ù
                name.setText("");
            }
        });
        button.setBounds(150, 40, 60, 25);
        getContentPane().add(button);
        setVisible(true);
    }
 
}