-
Notifications
You must be signed in to change notification settings - Fork 2
/
Modify.java
142 lines (134 loc) · 4.34 KB
/
Modify.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
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Modify extends JFrame implements ActionListener
{
String subject;
JLabel l1;
JButton b1, b2;
JTextField text1;
FileWriter fw1, fw2;
BufferedWriter bw1, bw2;
FileReader fr, frcnt;
BufferedReader br, brcnt;
ArrayList<String>al;
public Modify(String s)
{
subject = s;
setTitle("Choosing the question to modify");
setSize(400,400);
setLayout(null);
setLocationRelativeTo(null);
setVisible(true);
l1 = new JLabel("Enter question number");
l1.setBounds(50,50,150,30);
add(l1);
text1 = new JTextField();
text1.setBounds(200,50, 100,30);
add(text1);
b1 = new JButton("Click to view and modify");
b1.setBounds(100,250, 200,30);
b1.addActionListener(this);
add(b1);
b2 = new JButton("Go back");
b2.setBounds(100,300,200,30);
b2.addActionListener(this);
add(b2);
}
public void actionPerformed(ActionEvent e)
{
al=new ArrayList<>();
if(e.getSource()==b1)
{
try
{
String ques=text1.getText();
frcnt= new FileReader(subject+"Counter.txt");
int quesnumber=0;
brcnt = new BufferedReader(frcnt);
String qu=brcnt.readLine();
quesnumber=Integer.parseInt(qu);
if(Integer.parseInt(ques)>quesnumber||Integer.parseInt(ques)<1)
{
throw new Exception();
}
else
{
String numbertomodify=text1.getText();
fr= new FileReader(subject+".txt");
br= new BufferedReader(fr);
int quescounter=1;
int flag =0;
String s=br.readLine();
String ans1="";
String ans2="";
String ans3="";
while(s!=null)
{
int digitsofques=0;
int i=9;
String curr="";
while((int)s.charAt(i)>=48&&(int)s.charAt(i)<=57)
{
digitsofques++;
curr+=s.charAt(i);
i++;
}
String add=Integer.toString(quescounter);
String sa=s.substring(0,9)+add+s.substring(digitsofques+9);
String sb=br.readLine();
String sc=br.readLine();
if(Integer.parseInt(curr)==Integer.parseInt(numbertomodify)&&flag==0)
{
flag=1;
ans1=sa;
ans2=sb;
ans3=sc;
break;
}
quescounter++;
s=br.readLine();
}
if(flag==0)
throw new Exception();
fr.close();
br.close();
text1.setText("");
ModifyQuestion m1 = new ModifyQuestion(subject,ans1,ans2,ans3,Integer.parseInt(ques));
}
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(this,"Question not available");
text1.setText("");
}
}
if(e.getSource()==b2)
{
dispose();
try
{
if(subject.equals("Physics"))
{
dispose();
new Physics();
}
else if(subject.equals("Chemistry"))
{
dispose();
new Chemistry();
}
else
{
dispose();
new Mathematics();
}
}
catch(Exception e1)
{
}
}
}
}