TextField textField_1 = new TextField();
textField_1.setEchoChar('*');
/**
完整執行個體源代碼
*/
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Toolkit;
import javax.swing.JTextField;
import edu.gzu.stuManager.Dao.UserLoginValid;
import edu.gzu.stuManager.Domain.StudentInfo;
import edu.gzu.stuManager.View.StudentMainView;
import java.awt.Choice;
import java.awt.Font;
import java.awt.Button;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class MainUI {
private JFrame frame;
private JTextField textField;
private JTextField textField_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainUI window = new MainUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public MainUI() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setTitle("\u6210\u7EE9\u7BA1\u7406\u7CFB\u7EDF\uFF08\u767B\u5F55\uFF09");
frame.setIconImage(Toolkit.getDefaultToolkit().getImage(MainUI.class.getResource("/image/func_list7_privmana.png")));
frame.setBounds(400, 250, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("\u5B66\u751F\u6210\u7EE9\u7BA1\u7406\u7CFB\u7EDF\u7528\u6237\u767B\u5F55\uFF01");
lblNewLabel.setFont(new Font("宋體", Font.PLAIN, 16));
lblNewLabel.setBounds(111, 17, 287, 15);
frame.getContentPane().add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("\u7528\u6237\u540D\uFF1A");
lblNewLabel_1.setFont(new Font("宋體", Font.PLAIN, 14));
lblNewLabel_1.setBounds(87, 67, 67, 15);
frame.getContentPane().add(lblNewLabel_1);
textField = new JTextField();
textField.setBounds(154, 64, 141, 21);
frame.getContentPane().add(textField);
textField.setColumns(10);
JLabel label = new JLabel("\u5BC6 \u7801\uFF1A");
label.setFont(new Font("宋體", Font.PLAIN, 14));
label.setBounds(87, 108, 67, 15);
frame.getContentPane().add(label);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(154, 103, 141, 21);
frame.getContentPane().add(textField_1);
JLabel lblNewLabel_2 = new JLabel("\u6211\u7684\u8EAB\u4EFD\u662F\uFF1A");
lblNewLabel_2.setFont(new Font("宋體", Font.PLAIN, 14));
lblNewLabel_2.setBounds(105, 150, 97, 15);
frame.getContentPane().add(lblNewLabel_2);
final Choice choice = new Choice();
choice.setBounds(210, 147, 74, 21);
choice.add("學生");
choice.add("教師");
choice.add("系統管理者");
frame.getContentPane().add(choice);
Button button = new Button("\u767B\u5F55");
button.setBounds(87, 194, 76, 23);
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
String user=textField.getText();
String password=textField_1.getText();
String shenfen=choice.getSelectedItem();
if(user.equals("")||user==null){
JOptionPane.showMessageDialog(frame, shenfen+":您好,帳号不能為空!");
return;
}else if(password.equals("")||password==null){
JOptionPane.showMessageDialog(frame, shenfen+":您好,密碼不能為空!");
return;
}else{
StudentInfo stu=new StudentInfo(Integer.parseInt(user),
Integer.parseInt(password),shenfen);
UserLoginValid dao=new UserLoginValid();
String result=dao.isValid(stu);
if("登入成功!".equals(result)){
JOptionPane.showMessageDialog(frame,result);
StudentMainView index=new StudentMainView(stu);
JFrame frame2=index.getFrame();
frame2.setVisible(true);
frame.dispose();
}else{
JOptionPane.showMessageDialog(frame,result);
}
}
}
});
frame.getContentPane().add(button);
Button button_1 = new Button("\u53D6\u6D88");
button_1.setBounds(219, 194, 76, 23);
frame.getContentPane().add(button_1);
}
}
JOptionPane.showMessageDialog(frame, shenfen+":您好,帳号不能為空!");