📄 testgui.java
字号:
/*
* 创建日期 2006-5-8
* 作者: 褚廷军
* 项目名称:学生考试系统;
* 项目要求:毕业设计;
* 模块名称:客户端考试界面
* 模块功能:考试系统的客户端考试界面
* 用户完成从服务器取题,分题目显示,答题,提交答案,读取分数等操作
* (未实现功能,用户对已经做完的题目进行修改)
*
* 更改所生成文件模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*/
package client;
import java.awt.*;
import javax.swing.border.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
public class TestGui extends Thread implements ActionListener{
private static final long serialVersionUID = -3891320231212656455L;
private boolean timeFlag = false;
private JSplitPane split_one;
private JButton search;
private JButton next;
private JButton previous;
private JMenuItem exit;
private JLabel dispTime;
private JLabel position = new JLabel();
private JComboBox subject;
private JComboBox kind;
private JButton beginExe;
private JMenuBar menubar;
private JMenu menu;
private Box leftBox;
private Box workBox;
private Box answerBox;
private Box operationBox;
private Box testBox;
private Box inputBox;
private Box bottomBox;
private Box answerAndWorkBox;
private JLabel lastTimeL;
private JTextField lastTimeF;
private JPanel lastTimeP;
private JLabel testLabel;
private JLabel stateLabel;
private JTextField stateField;
private JMenuItem stuLog;
private JButton callIP;
private JTextField ipField;
private JTextField stuinfo;
private JTextField testinfo;
private JTextField answerinfo;
private JButton enterButton;
private JMenuItem version;
private JButton startTest;
private JToolBar toolbar1;
private JButton exitButton;
private Socket socket = null;
private DataInputStream in = null;
private DataOutputStream out = null;
private JButton resetIP;
private JButton queryButton;
private JButton preview;
private JButton submit;
private JMenuItem techLog;
private JTextField userField;
private JPasswordField passField;
private String ip = "localhost";
private int port2 = 8002, port3 = 8003;
private String[] tempTest;
JFrame jf;
private JTextArea testArea;
private ButtonGroup keySelect;
private JTextField keyField;
private JButton readNext;
private JButton lookScore;
private JTextField otherinfo;
private static String tempStr1 = "";// 记录用户答案的变量
private static String uanswer = "";// 存储用户答案的数组
private static int n = 0;// 用户已经答题
private static int num = 1;// 试题个数
private static int enu = 0;
private static String sub;
private static int minute = 1;
private static int second = 60;
public static void main(String args[]) {
JFrame.setDefaultLookAndFeelDecorated(true);// 放弃windows窗体风格
new TestGui();
}
TestGui() {
jf = new JFrame("学生考试系统");
jf.setLocation(100, 100);
Toolkit tool=jf.getToolkit();
Image ima=tool.getImage("tubiao.jpg");
jf.setIconImage(ima);
jf.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container con = jf.getContentPane();
menuBarSetting();
jf.setJMenuBar(menubar);
topbarSetting();
leftBoxSetting();
workBoxSetting();
answerBoxSetting();
operationBoxSetting();
testBoxSetting();
con.add(toolbar1, "North");
split_one = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftBox,
testBox);
split_one.setSize(0, 50);
inputBoxSetting();
con.add(inputBox, BorderLayout.CENTER);
bottomBoxSetting();
con.add(bottomBox, BorderLayout.SOUTH);
jf.setSize(800, 600);
jf.setVisible(true);
jf.setResizable(true);
}
private void menuBarSetting() {
menubar = new JMenuBar();
menu = new JMenu("功能");
stuLog = new JMenuItem("学生登录");
stuLog.setToolTipText("Welcome to ctj_2's system");
stuLog.addActionListener(this);
techLog = new JMenuItem("教师登录");
techLog.setToolTipText("Welcome to ctj_2's system");
techLog.addActionListener(this);
version = new JMenuItem("版本信息");
version.setToolTipText("show the copyright ");
version.addActionListener(this);
exit = new JMenuItem("Exit", 'x');
exit.addActionListener(this);
exit.setToolTipText("click and exit");
exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
InputEvent.ALT_MASK));
menu.add(stuLog);
menu.addSeparator();
menu.add(techLog);
menu.addSeparator();
menu.add(version);
menu.addSeparator();
menu.add(exit);
menubar.add(menu);
}
private void topbarSetting() {
toolbar1 = new JToolBar("two");
Box toolButton = Box.createHorizontalBox();
enterButton = new JButton("进入考场");
enterButton.setEnabled(false);
enterButton.addActionListener(this);
enterButton.setToolTipText("click and login system");
exitButton = new JButton("退出");
exitButton.setToolTipText("click and exit");
exitButton.setEnabled(true);
exitButton.addActionListener(this);
toolButton.add(enterButton);
toolButton.add(Box.createHorizontalStrut(5));
toolButton.add(exitButton);
Box stateBox = Box.createHorizontalBox();
stateLabel = new JLabel("状 态:");
stateLabel.setFont(new Font("楷体_GB2312", Font.BOLD, 16));
stateLabel.setForeground(Color.RED);
stateField = new JTextField("欢迎你进入考试系统,请先登陆,然后选择服务", 20);
stateField.setToolTipText("show all the infomation about the system");
stateField.setFont(new Font("宋体", Font.BOLD, 12));
stateField.setForeground(Color.RED);
stateField.setEditable(false);
stateBox.add(Box.createHorizontalStrut(150));
stateBox.add(stateLabel);
stateBox.add(stateField);
stateBox.add(Box.createHorizontalGlue());
toolbar1.add(toolButton);
toolbar1.add(stateBox);
}
private void leftBoxSetting() {
Box snBox = Box.createHorizontalBox();
userField = new JTextField(20);
snBox.add(new JLabel("学号"));
userField.setToolTipText("input your studynumber");
snBox.add(Box.createHorizontalStrut(5));
snBox.add(userField);
snBox.add(Box.createHorizontalGlue());
Box ipBox = Box.createHorizontalBox();
ipField = new JTextField("127.0.0.1");
ipField.setToolTipText("input the server host");
ipBox.add(new JLabel("IP"));
ipBox.add(Box.createHorizontalStrut(18));
ipBox.add(ipField);
ipBox.add(Box.createHorizontalGlue());
Box passwordBox = Box.createHorizontalBox();
passField = new JPasswordField(20);
passwordBox.add(new JLabel("密码"));
passwordBox.add(Box.createHorizontalStrut(5));
passwordBox.add(passField);
passwordBox.add(Box.createHorizontalGlue());
Box callBox = Box.createHorizontalBox();
callIP = new JButton("呼叫ip");
callIP.addActionListener(this);
resetIP = new JButton("重置");
resetIP.addActionListener(this);
queryButton = new JButton("查询");
queryButton.setEnabled(false);
queryButton.addActionListener(this);
callBox.add(Box.createHorizontalStrut(20));
callBox.add(callIP);
callBox.add(Box.createHorizontalStrut(5));
callBox.add(resetIP);
callBox.add(Box.createHorizontalStrut(5));
callBox.add(queryButton);
callBox.add(Box.createHorizontalGlue());
Box stuinfoBox = Box.createVerticalBox();
stuinfo = new JTextField(20);
stuinfoBox.add(new JLabel("个人信息"));
stuinfoBox.add(Box.createVerticalStrut(5));
stuinfoBox.add(stuinfo);
stuinfoBox.add(Box.createVerticalGlue());
Box testinfoBox = Box.createVerticalBox();
testinfo = new JTextField(20);
testinfoBox.add(new JLabel("考试信息"));
testinfoBox.add(Box.createVerticalStrut(5));
testinfoBox.add(testinfo);
testinfoBox.add(Box.createVerticalGlue());
Box answerinfoBox = Box.createVerticalBox();
answerinfo = new JTextField(20);
answerinfoBox.add(new JLabel("答题信息"));
answerinfoBox.add(Box.createVerticalStrut(5));
answerinfoBox.add(answerinfo);
answerinfoBox.add(Box.createVerticalGlue());
Box otherinfoBox = Box.createVerticalBox();
otherinfo = new JTextField(20);
otherinfoBox.add(new JLabel("其它信息"));
otherinfoBox.add(Box.createVerticalStrut(5));
otherinfoBox.add(otherinfo);
otherinfoBox.add(Box.createVerticalGlue());
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
leftBox = Box.createVerticalBox();
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(ipBox);
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(snBox);
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(passwordBox);
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(callBox);
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(testinfoBox);
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(stuinfoBox);
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(answerinfoBox);
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(otherinfoBox);
leftBox.add(Box.createVerticalStrut(10));
leftBox.add(Box.createHorizontalGlue());
Border leftborder = BorderFactory.createTitledBorder(BorderFactory
.createLineBorder(Color.black, 1), "学生考试信息",
TitledBorder.CENTER, TitledBorder.ABOVE_TOP, new Font(
"楷体_GB2312", Font.BOLD, 16), Color.BLACK);
leftBox.setBorder(leftborder);
}
private void workBoxSetting() {
workBox = Box.createHorizontalBox();
workBox.add(new JLabel("生成试题"));
workBox.add(Box.createHorizontalStrut(5));
startTest = new JButton("开始考试");
startTest.setEnabled(false);
startTest.addActionListener(this);
workBox.add(startTest);
workBox.add(new JLabel("科目"));
subject = new JComboBox();
subject.addItem("数学");
subject.addItem("英语");
workBox.add(subject);
workBox.add(Box.createHorizontalStrut(5));
workBox.add(new JLabel("试题种类"));
kind = new JComboBox();
kind.addItem("选择");
kind.addItem("填空");
// kind.addItem("名词解释");
// kind.addItem("问答题");
// kind.addItem("名词解释");
// kind.addItem("论述");
workBox.add(kind);
workBox.add(Box.createHorizontalStrut(5));
beginExe = new JButton("生成试题");
beginExe.setEnabled(false);
beginExe.addActionListener(this);
beginExe.setActionCommand("beginExe");
workBox.add(beginExe);
// workBox.add(Box.createHorizontalGlue());
Border workborder = BorderFactory.createTitledBorder(BorderFactory
.createLineBorder(Color.black, 1), "", TitledBorder.CENTER,
TitledBorder.ABOVE_TOP, new Font("GB_2312", Font.BOLD, 16),
Color.BLACK);
workBox.setBorder(workborder);
}
private void answerBoxSetting() {
answerBox = Box.createHorizontalBox();
keyField = new JTextField(5);
keySelect = new ButtonGroup();
JRadioButton sk1 = new JRadioButton("A");
JRadioButton sk2 = new JRadioButton("B");
JRadioButton sk3 = new JRadioButton("C");
JRadioButton sk4 = new JRadioButton("D");
keySelect.add(sk1);
keySelect.add(sk2);
keySelect.add(sk3);
keySelect.add(sk4);
sk1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
keyField.setText("a");
}
});
sk2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
keyField.setText("b");
}
});
sk3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
keyField.setText("c");
}
});
sk4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
keyField.setText("d");
}
});
readNext = new JButton("下一题");
readNext.setEnabled(false);
readNext.addActionListener(this);
Box kjbbox = Box.createHorizontalBox();
kjbbox.add(keyField);
kjbbox.add(sk1);
kjbbox.add(sk2);
kjbbox.add(sk3);
kjbbox.add(sk4);
kjbbox.add(readNext);
answerBox.add(Box.createHorizontalStrut(5));
answerBox.add(kjbbox);
Border answerborder = BorderFactory.createTitledBorder(BorderFactory
.createLineBorder(Color.black, 1), "", TitledBorder.CENTER,
TitledBorder.BELOW_BOTTOM, new Font("GB_2312", Font.BOLD, 16),
Color.BLACK);
answerBox.setBorder(answerborder);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -