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);
|
}
|
|
}
|