📄 exammainframe.java
字号:
package exam.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import exam.model.Paper;
import exam.model.Student;
/**
* 考试主界面
* @author Administrator
*
*/
public class ExamMainFrame {
private JFrame jf;
private JPanel north,center,south,east,west;
private JLabel label,time;
private JScrollPane jsp;
private JButton b1,b2,b3;
private JTextField keyField;
private Box operationBox;
private Student student;
private Paper paper;
public ExamMainFrame(){
jf= new JFrame("考试系统");
jf.setLayout(new BorderLayout());
south = new JPanel();
north = new JPanel();
center = new JPanel();
east = new JPanel();
west = new JPanel();
init();
jf.add(north,BorderLayout.NORTH);
jf.add(center,BorderLayout.CENTER);
jf.add(jsp,BorderLayout.CENTER);
jf.add(south,BorderLayout.SOUTH);
jf.add(east,BorderLayout.EAST);
jf.add(west,BorderLayout.WEST);
}
private void init(){
initSouth();
initCenter();
initNorth();
initWest();
initEast();
}
private void initSouth(){
keyField = new JTextField(5);
label = new JLabel("请选择:");
south.add(label);
ButtonGroup bg = new ButtonGroup();
JRadioButton jrba=new JRadioButton("A");
jrba.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
keyField.setText("A");
}
});
JRadioButton jrbb=new JRadioButton("B");
JRadioButton jrbc=new JRadioButton("C");
JRadioButton jrbd=new JRadioButton("D");
jrbb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
keyField.setText("B");
}
});
jrbc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
keyField.setText("C");
}
});
jrbd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
keyField.setText("D");
}
});
bg.add(jrba); bg.add(jrbb);
bg.add(jrbc);bg.add(jrbd);
south.add(jrba);south.add(jrbb);
south.add(jrbc);south.add(jrbd);
b1 = new JButton("上一题");
b2 = new JButton("下一题");
b3 = new JButton("交卷");
b2.setEnabled(false);
// b2.addActionListener(this);
south.add(keyField);
south.add(b1);
b2.addActionListener(new actionHandel());
south.add(b2);
south.add(b3);
}
private void initCenter(){
JTextArea jta= new JTextArea(30,30);
center.add(jta);
jsp= new JScrollPane (jta);
}
private void initNorth(){
JLabel label1=new JLabel("欢迎进入考试系统:");
label1.setFont(new Font("",Font.BOLD,24));
JLabel label2= new JLabel("考生编号:");
JLabel label3= new JLabel("考生姓名:");
JLabel label4= new JLabel("考生科目:");
north.add(label1);
north.add(label2);
north.add(label3);
north.add(label4);
}
private void initWest(){
JLabel label1=new JLabel("剩余试题:");
west.add(label1);
}
private void initEast(){
JLabel label1=new JLabel("剩余时间:");
east.add(label1);
time=new JLabel("120");
new Thread(){
public void run(){
while(true){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
time.setText((Integer.parseInt(time.getText())-1)+"");
}
}
}.start();
east.add(time);
east.add(new JLabel("秒"));
}
private class actionHandel implements ActionListener{
public void actionPerformed(ActionEvent e) {
ButtonGroup b=(ButtonGroup)e.getSource();
if(b.getSelection().isEnabled()){
}else if(false){
}
}
}
private void showMe(){
jf.setLocation(200,300);
jf.setSize(600,400);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new ExamMainFrame().showMe();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -