-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhysicsInsertTrueFalseQuest.java
180 lines (146 loc) · 6.04 KB
/
PhysicsInsertTrueFalseQuest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author abhiram
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class PhysicsInsertTrueFalseQuest extends java.awt.Frame {
/**
* Creates new form InsertPhyTrueFalseQuest
*/
public PhysicsInsertTrueFalseQuest() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
lblStatement = new java.awt.Label();
lblAction = new java.awt.Label();
lblTrueFalse = new java.awt.Label();
txtStatement = new java.awt.TextField();
btnInsert = new java.awt.Button();
btnBack = new java.awt.Button();
txtTrueFalse = new java.awt.TextField();
setName("Insert Physics True or False Question"); // NOI18N
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
setLayout(new FlowLayout());
setSize(1000,1000);
lblStatement.setText("Statement");
add(lblStatement);
lblStatement.setBounds(37, 77, 60, 20);
lblAction.setText("Insert True or False Question");
add(lblAction);
lblAction.setBounds(105, 38, 164, 20);
add(txtStatement);
txtStatement.setBounds(124, 77, 223, 20);
lblTrueFalse.setText("True or False");
add(lblTrueFalse);
lblTrueFalse.setBounds(37, 124, 77, 20);
btnInsert.setLabel("Insert Question");
btnInsert.setActionCommand("insert");
add(btnInsert);
btnInsert.setBounds(105, 209, 100, 24);
btnInsert.addActionListener(new ButtonClickListener());
btnBack.setLabel("Back");
btnBack.addActionListener(new ButtonClickListener());
add(btnBack);
btnBack.setBounds(304, 243, 43, 24);
btnBack.setActionCommand("back");
txtTrueFalse.setText("Enter True or False");
add(txtTrueFalse);
txtTrueFalse.setBounds(124, 124, 123, 20);
setLayout(null);
}// </editor-fold>//GEN-END:initComponents
/**
* Exit the Application
*/
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PhysicsInsertTrueFalseQuest().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Button btnBack;
private java.awt.Button btnInsert;
private java.awt.Label lblAction;
private java.awt.Label lblStatement;
private java.awt.Label lblTrueFalse;
private java.awt.TextField txtStatement;
private java.awt.TextField txtTrueFalse;
String filenameQuest ;
String filenameAns;
// End of variables declaration//GEN-END:variables
public class ButtonClickListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String command = e.getActionCommand();
if(command.equals("back")){
btnBack.getParent().setVisible(false);
new PhysicsInsertQuestion().setVisible(true);
}
else{
if(Subject.Subject.equals("phy")){
filenameQuest = ("PhysicsQuestions.txt");
filenameAns = ("PhysicsAnswers.txt");
}
if(Subject.Subject.equals("chem")){
filenameQuest = ("ChemistryQuestions.txt");
filenameAns = ("ChemAnswers.txt");
}
try{
FileReader fileReaderQuest = new FileReader(filenameQuest);
BufferedReader bufferedReaderQuest = new BufferedReader(fileReaderQuest);
FileWriter fileWriterQuest = new FileWriter(filenameQuest,true);
BufferedWriter bufferedWriterQuest = new BufferedWriter(fileWriterQuest);
int questionNumber = 1;
String lineQuest;
while((lineQuest = bufferedReaderQuest.readLine()) !=null){
questionNumber++;
}
//bufferedWriter.write(questionNumber + "." +);
bufferedWriterQuest.write((questionNumber) + "." + txtStatement.getText().toString() + " -True/False");
bufferedWriterQuest.newLine();
bufferedWriterQuest.close();
//Inserting answer into File
FileReader fileReaderAns = new FileReader(filenameAns);
BufferedReader bufferedReaderAns= new BufferedReader(fileReaderAns);
FileWriter fileWriterAns = new FileWriter(filenameAns,true);
BufferedWriter bufferedWriterAns = new BufferedWriter(fileWriterAns);
int answerNumber = 1;
String lineAns;
while((lineAns = bufferedReaderAns.readLine()) !=null){
answerNumber++;
}
//bufferedWriter.write(questionNumber + "." +);
bufferedWriterAns.write((answerNumber) + "." + txtTrueFalse.getText().toString());
bufferedWriterAns.newLine();
bufferedWriterAns.close();
}
catch(IOException ex){
System.out.println("error");
}
}
}
}
}