parent
0259c085c0
commit
6c95990baa
@ -0,0 +1,132 @@
|
||||
package view;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import dao.GuanliyuanDao;
|
||||
import dao.impl.GuanliyuanImpl;
|
||||
import entity.Guanliyuan;
|
||||
|
||||
public class LoginUI extends JFrame {
|
||||
|
||||
GuanliyuanDao dao = new GuanliyuanImpl();
|
||||
public static String username;
|
||||
public static String role;
|
||||
private JPanel contentPane;
|
||||
private JTextField textField;
|
||||
private JPasswordField textField_1;
|
||||
private JComboBox comboBox;
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
LoginUI frame = new LoginUI();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public LoginUI() {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 508);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
setTitle("家庭收支管理系统");
|
||||
JLabel label = new JLabel("用户名");
|
||||
label.setFont(new Font("楷体", Font.PLAIN, 20));
|
||||
label.setBounds(104, 125, 110, 32);
|
||||
contentPane.add(label);
|
||||
|
||||
textField = new JTextField();
|
||||
textField.setBounds(224, 119, 227, 38);
|
||||
contentPane.add(textField);
|
||||
textField.setColumns(10);
|
||||
|
||||
JLabel label_1 = new JLabel("密码");
|
||||
label_1.setFont(new Font("楷体", Font.PLAIN, 20));
|
||||
label_1.setBounds(104, 210, 110, 32);
|
||||
contentPane.add(label_1);
|
||||
|
||||
textField_1 = new JPasswordField();
|
||||
textField_1.setColumns(10);
|
||||
textField_1.setBounds(224, 204, 227, 38);
|
||||
contentPane.add(textField_1);
|
||||
|
||||
JButton button = new JButton("登录");
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Guanliyuan gl = dao.findByUsername(textField.getText());
|
||||
if(gl!=null){
|
||||
if(gl.getMimayc().equals(textField_1.getText())){
|
||||
username=gl.getYonghumingyc();
|
||||
role=gl.getJiaoseyc();
|
||||
if(!role.equals(comboBox.getSelectedItem().toString())){
|
||||
JOptionPane.showMessageDialog(null, "用户名或密码错误,登录失败");
|
||||
return;
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "登录成功");
|
||||
MainUI frame = new MainUI();
|
||||
frame.setVisible(true);
|
||||
setVisible(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(null, "用户名或密码错误,登录失败");
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("楷体", Font.PLAIN, 20));
|
||||
button.setBounds(175, 371, 105, 38);
|
||||
contentPane.add(button);
|
||||
JButton button_1 = new JButton("注册");
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
RegistUI frame = new RegistUI();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("楷体", Font.PLAIN, 20));
|
||||
button_1.setBounds(332, 371, 105, 38);
|
||||
contentPane.add(button_1);
|
||||
JLabel lblNewLabel = new JLabel("家庭收支管理系统");
|
||||
lblNewLabel.setFont(new Font("楷体", Font.PLAIN, 28));
|
||||
lblNewLabel.setBounds(235, 28, 497, 55);
|
||||
contentPane.add(lblNewLabel);
|
||||
|
||||
JLabel label_2 = new JLabel("角色");
|
||||
label_2.setFont(new Font("楷体", Font.PLAIN, 20));
|
||||
label_2.setBounds(104, 291, 110, 32);
|
||||
contentPane.add(label_2);
|
||||
|
||||
comboBox = new JComboBox();
|
||||
comboBox.setModel(new DefaultComboBoxModel(new String[] {"管理员"}));
|
||||
comboBox.setBounds(224, 291, 227, 32);
|
||||
contentPane.add(comboBox);
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue