?? loginframe.java
字號:
package exam.gui;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
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.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import exam.model.Course;
import exam.model.Student;
import exam.web.ExamClient;
/**
* 登錄界面
* @author 董曉煒
*
*/
public class LoginFrame extends JFrame{
private static final long serialVersionUID = 2272140086458982067L;
private JFrame jf;
private JTextField jtf;
private JPasswordField jpf;
private JButton jb1,jb2;
private ExamClient ec;
private Student sd;
public JTextField getJtf() {
return jtf;
}
public void setJtf(JTextField jtf) {
this.jtf = jtf;
}
public JPasswordField getJpf() {
return jpf;
}
public void setJpf(JPasswordField jpf) {
this.jpf = jpf;
}
public LoginFrame(ExamClient ec){
this.ec=ec;
jf=new JFrame("考生登錄");
jtf=new JTextField(10);
jpf=new JPasswordField(10);
jb1=new JButton("登錄");
jb2=new JButton("取消");
init();
addEventHandler();
showMe();
}
private void addEventHandler(){
jb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
sd=ec.login(jtf,jpf);
if(sd==null){
JOptionPane.showMessageDialog(jf,"該用戶不存在");
}
else if(sd.getId().equals("1001")){
JOptionPane.showMessageDialog(jf, "你已考過一次了");
return;
}else if(sd.getId().equals("1002")){
JOptionPane.showMessageDialog(jf, "服務器暫停中。。。");
}else{
Course[] courses=ec.getCourses();
if(courses==null){JOptionPane.showMessageDialog(jf, "服務器暫停中。。。");return;}
jf.setVisible(false);
new SelectSubjectFrame(ec,courses);
}
}
});
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
ec.close();
System.exit(0);
}
});
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent arg0) {
ec.close();
System.exit(0);
}
});
}
private void init(){
JPanel center=new JPanel();
JLabel jl=new JLabel("考生登錄");
jl.setHorizontalAlignment(JLabel.CENTER);
center.setLayout(new GridBagLayout());
GridBagConstraints gbc1=new GridBagConstraints();
gbc1.gridx=0;
gbc1.gridy=0;
center.add(new JLabel("學號"),gbc1);
GridBagConstraints gbc2=new GridBagConstraints();
gbc2.gridx=0;
gbc2.gridy=1;
center.add(new JLabel("密碼"),gbc2);
GridBagConstraints gbc3=new GridBagConstraints();
gbc3.gridx=1;
gbc3.gridy=0;
center.add(jtf,gbc3);
GridBagConstraints gbc4=new GridBagConstraints();
gbc4.gridx=1;
gbc4.gridy=1;
center.add(jpf,gbc4);
JPanel south=new JPanel();
south.add(jb1);
south.add(jb2);
jf.add(jl,BorderLayout.NORTH);
jf.add(center,BorderLayout.CENTER);
jf.add(south,BorderLayout.SOUTH);
}
private void showMe(){
jf.pack();
jf.setLocation(200, 200);
jf.setResizable(false);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -