forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.java
109 lines (91 loc) · 2.16 KB
/
sample.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
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class sample extends Frame implements WindowListener,ActionListener
{
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowClosing(WindowEvent e) { System.exit(0); }
public void windowClosed(WindowEvent e) { }
public void windowOpened(WindowEvent e) { }
TextArea t1;
Checkbox c1,c2,c3;
CheckboxGroup g;
Button b1,b2;
Connection c;
Statement s;
ResultSet rs;
int i=0;
int marks=0;
int j=0;
public static void main(String args[]) throws Exception
{
sample s= new sample(); // Create a new frame
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()== b2) // Start
{
try{
rs.next();
t1.setText(rs.getString(1));
c1.setLabel(rs.getString(2));
c2.setLabel(rs.getString(3));
c3.setLabel(rs.getString(4));
}catch(Exception e) { System.out.println(e); }
}
if(ae.getSource()== b1) // Submit
{
try{
t1.setText(rs.getString(1));
c1.setLabel(rs.getString(2));
c2.setLabel(rs.getString(3));
c3.setLabel(rs.getString(4));
if(c1.getState()==true) j=1;
if(c2.getState()==true) j=2;
if(c3.getState()==true) j=3;
String ans=rs.getString(5);
int k=Integer.parseInt(ans);
if(j==k)
marks=marks+2;
else
marks=marks-1;
System.out.println("ANS IS " + k);
System.out.println("J IS " + j);
System.out.println(marks);
rs.next();
}catch(Exception e) { System.out.println(e); }
}
}
sample()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c= DriverManager.getConnection( "jdbc:odbc:abc","root","root");
s=c.createStatement();
rs= s.executeQuery("select * from exam");
}catch(Exception e) { System.out.println(e); }
b1= new Button("Submit");
b2= new Button("Start");
b1.addActionListener(this);
b2.addActionListener(this);
t1= new TextArea(100,100);
g= new CheckboxGroup();
c1= new Checkbox("Option1",g, true);
c2= new Checkbox("Option2",g, false);
c3= new Checkbox("Option3",g, false);
add(t1);
add(c1);
add(c2);
add(c3);
add(b1);
add(b2);
setLayout( new GridLayout(4,4));
addWindowListener(this);
setVisible(true);
setSize(400,400);
setLocation(0,0);
}
}