final version

final version
This commit is contained in:
weiyuqing committed 2020-06-26 17:08:38 +08:00
1 parent 7c7166c6b7
commit 67e90a7679
15 files changed
+150 -59

No files matched your search

-20
View File
@@ -1,20 +0,0 @@
/*
* Copyright (c) 2020 魏遇卿 All Rights Reserved.
* FileName: a.java
* @author: 魏遇卿@date: 2020/6/19 下午8:02@version: 1.0
* E-mail:358614401@qq.com
* Code with UTF-8
*/
package autoScore;
public class a {
public static void main(String[] args) {
int a=1;
if (a <10) {
a++;
}
System.out.println(a);
}
}
+6
View File
@@ -13,5 +13,11 @@ public class mainDo{
public static void main(String[] args) throws IOException {
//int score=0;
mainGUI gui=new mainGUI();
/* new Timer().schedule(new TimerTask() {
@Override
public void run() {
System.out.println("stop question");
}
},1000);*/
}
}
+90 -16
View File
@@ -20,6 +20,9 @@ import static autoScore.score.getScore;
import static autoScore.score.scoreToTxt;
public class mainGUI extends JFrame implements ActionListener {
int whatQuestionW;
int scoreUser = 0;
int whatQuestion;
// public static JTextField questionStudent;
JTextField questionStudent = new JTextField("问题的位置");
//GridBagLayout questionText =new GridBagLayout();
@@ -92,20 +95,19 @@ public class mainGUI extends JFrame implements ActionListener {
/*private class panelABCD extends JPanel implements ActionListener{
}*/
@Override
public void actionPerformed(ActionEvent e) {
//int用来存储现在是第几题
int whatQuestionW = 0;
int scoreUser =0 ;
if (whatQuestionW < 1) {
//int whatQuestionW;
// for (whatQuestionW = 0; whatQuestionW < 1; whatQuestionW++) {
//int whatQuestionW =0;
String str = new String();
if (e.getActionCommand().equals("A")) {
str = "A";
/*scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);
whatQuestionW++;
scoreUser = chooseDo(str, whatQuestionW, scoreUser);
whatQuestion = whatQuestionW++;
whatQuestionW=whatQuestionW++;
//actionPerformed(ActionEvent e);
}
/*str = "A";
@@ -127,16 +129,86 @@ public class mainGUI extends JFrame implements ActionListener {
}*/
if (e.getActionCommand().equals("B")) {
str = "B";
/*scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++;
scoreUser = chooseDo(str, whatQuestionW, scoreUser);
whatQuestion = whatQuestionW++;
whatQuestionW=whatQuestionW++;
// System.out.println(whatQuestionW);
}
if (e.getActionCommand().equals("C")) {
str = "C";
/*scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++;
scoreUser = chooseDo(str, whatQuestionW, scoreUser);
whatQuestion = whatQuestionW++;
whatQuestionW=whatQuestionW++;
}
if (e.getActionCommand().equals("D")) {
str = "D";
/* scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++;
scoreUser = chooseDo(str, whatQuestionW, scoreUser);
whatQuestion=whatQuestionW++;
whatQuestionW=whatQuestionW++;
}
//whatQuestionW++;
// }
//这里写最后结果被写入文件夹啊
try {
String studetnNum=new String();
scoreToTxt(userIn.getStudentNumber(),scoreUser);
System.out.println(userIn.getStudentNumber());
} catch (IOException ioException) {
ioException.printStackTrace();
System.out.println("抛出异常1");
}
}
/*@Override
public void actionPerformed(ActionEvent e) {
//int用来存储现在是第几题
int whatQuestionW = 0;
int scoreUser =0 ;
if (whatQuestionW <= 1) {
//int whatQuestionW =0;
String str = new String();
if (e.getActionCommand().equals("A")) {
str = "A";
scoreUser=chooseDo(str, whatQuestionW,scoreUser);
whatQuestionW++;
//actionPerformed(ActionEvent e);
}
*/
/*str = "A";
char ch[] = str.toCharArray();
char answer = ch[0];
try {
getScore(score, answer, readFireAnswer(whatQuestionW));
} catch (IOException ioException) {
ioException.printStackTrace();
}
whatQuestionW++;
System.out.println(whatQuestionW);
try {
questionStudent.setText(readFile(1));
} catch (IOException ioException) {
ioException.printStackTrace();
}
}*//*
if (e.getActionCommand().equals("B")) {
str = "B";
scoreUser=chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++;
// System.out.println(whatQuestionW);
}
if (e.getActionCommand().equals("C")) {
str = "C";
scoreUser=chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++;
}
if (e.getActionCommand().equals("D")) {
str = "D";
scoreUser=chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++;
}
whatQuestionW++;
} else {
@@ -149,10 +221,10 @@ public class mainGUI extends JFrame implements ActionListener {
}
}
}
}*/
//按键之后要做的事
public int chooseDo(String str, int whatQuestionW,int score) {
public int chooseDo(String str, int whatQuestionW, int score) {
//str = "A";
char ch[] = str.toCharArray();
char answer = ch[0];
@@ -163,14 +235,16 @@ public class mainGUI extends JFrame implements ActionListener {
ioException.printStackTrace();
System.out.println("抛出异常2");
}
whatQuestionW++;
//System.out.println(whatQuestionW);
System.out.println(score);
whatQuestionW++;//题号计算方式不同
System.out.println("quention" + whatQuestionW);
System.out.println("score" + score);
try {
questionStudent.setText(readFile(1));
} catch (IOException ioException) {
ioException.printStackTrace();System.out.println("抛出异常3");
}return score;
ioException.printStackTrace();
System.out.println("抛出异常3");
}
return score;
//mainGUI=new mainGUI();
//actionPerformed(ActionEvent e);
//chooseDo(str,whatQuestionW);
+4 -4
View File
@@ -13,8 +13,8 @@ import java.io.FileWriter;
import java.io.IOException;
public class score {
public static int getScore(int score, char choose, char anwser) {
if (choose == anwser) {
public static int getScore(int score, char choose, char answer) {
if (choose == answer) {
score++;
return score;
} else {
@@ -22,11 +22,11 @@ public class score {
}
}
public static void scoreToTxt(/*String name*,*/int score) throws IOException {
public static void scoreToTxt(String name,int score) throws IOException {
File writename = new File("D:\\WindowsCToD\\fire\\GeneticsMultipleChoice\\Score\\output.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件
writename.createNewFile();
BufferedWriter out = new BufferedWriter(new FileWriter(writename));
out.write(/*name+*/"score:" + score + "\r\n"); // \r\n即为换行
out.write("studentID: "+name+" score: " + score + "\r\n"); // \r\n即为换行
out.flush();
out.close();
}
+1
View File
@@ -11,5 +11,6 @@ package autoScore;
public class useInDemo {
public static void main(String[] args) {
userIn GUI=new userIn();
//System.out.println(userIn.getStudentNumber());
}
}
+49 -19
View File
@@ -11,7 +11,6 @@ package autoScore;
import javax.swing.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
@@ -22,18 +21,18 @@ public class userIn extends JFrame implements ActionListener {
//设置组件
private JButton
//创建窗体
login = new JButton("login");
login /*= new JButton("login")*/;
private JTextField
//创建组件
admin = new JTextField(),
password = new JTextField();
private JPanel contentPanel=new JPanel();
private JPanel contentPanel = new JPanel();
public userIn() {
super("Auto score to exam");
/* this.setBounds(100,100,100,100);*/
//获取主容器并设置为网格组布局
// contentPanel = this.getContentPane();
// contentPanel = this.getContentPane();
contentPanel.setLayout(null);
this.setVisible(true);
this.setSize(500, 350);//设置窗口大小
@@ -48,41 +47,41 @@ public class userIn extends JFrame implements ActionListener {
contentPanel.setLayout(null);
add(admin);
add(password);
add(login);
//add(login);
//组件位置
admin.setBounds(95,130,300,25);
password.setBounds(95,154,300,25);
login.setBounds(315,225,90,20);
admin.setBounds(95, 130, 300, 25);
password.setBounds(95, 154, 300, 25);
//login.setBounds(315, 225, 90, 20);
//显示组件
admin.setOpaque(false);
password.setOpaque(false);
login.setOpaque(false);
// login.setOpaque(false);
//设置监听(鼠标点击之后输入密码
admin.addMouseListener(new MouseAdapter(){
admin.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e){
public void mouseClicked(MouseEvent e) {
int c = e.getButton();
if(c == MouseEvent.BUTTON1 && admin.getText().equals("学号") &&e.getClickCount()==1) {
if (c == MouseEvent.BUTTON1 && admin.getText().equals("学号") && e.getClickCount() == 1) {
admin.setText(null);
/* password.setText("password");*/
/* password.setText("password");*/
}
}
});
admin.addCaretListener(new CaretListener(){
admin.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e){
public void caretUpdate(CaretEvent e) {
}
});
password.addMouseListener(new MouseAdapter(){
password.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e){
public void mouseClicked(MouseEvent e) {
int c = e.getButton();
if(c == MouseEvent.BUTTON1 && password.getText().equals("password") &&e.getClickCount()==1) {
if (c == MouseEvent.BUTTON1 && password.getText().equals("password") && e.getClickCount() == 1) {
password.setText(null);
/* admin.setText("学号");*/
/* admin.setText("学号");*/
}
}
});
@@ -92,12 +91,43 @@ public class userIn extends JFrame implements ActionListener {
mainGUI a=new mainGUI();
}
});*/
login = new JButton("login");
login.addActionListener(this);
this.add(login);
login.setBounds(315, 225, 90, 20);
}
static String studentNumber = new String();
static String studentPassword="111";
static String studentNum=new String();
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("login")) {
//login to do
//password and in password to return
if (password.getText().equals(studentPassword) == true) {
String studentNumber = admin.getText();
studentNum=studentNumber;
// String studentName=
System.out.println(studentNumber);
try {
dispose();
mainGUI gui=new mainGUI();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
if (password.getText().equals(studentPassword) ==false) {
System.out.println("your password false,try again");
}
}
public static String getStudentNumber() {
System.out.println(studentNum);
return studentNum;
}
}