-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create two buttons which display information
135 lines (135 loc) · 3.49 KB
/
Create two buttons which display information
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
/**** Main.java ****/
import java.awt.*;
import java.awt.event.*;
public class Main extends Frame implements ActionListener {
Button btnInfo, btnCGPA;
Main() {
super("Student Details");
btnInfo = new Button("A");
btnInfo.setBounds(25, 125, 450, 100);
btnInfo.addActionListener(this);
this.add(btnInfo);
btnCGPA = new Button("B");
btnCGPA.setBounds(25, 300, 450, 100);
btnCGPA.addActionListener(this);
this.add(btnCGPA);
this.setSize(500, 500);
this.setLayout(null);
this.setVisible(true);
this.setLocationRelativeTo(null);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
public static void main(String[] args) {
new Main();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnInfo) {
new Information(
"SUDIPTO GHOSH",
"BSc (Hons) Computer Science",
"19/78003",
"ARSD College"
);
} else if (e.getSource() == btnCGPA) {
new CGPA("9.73");
}
}
}
/**** Information.java ****/
import java.awt.*;
import java.awt.event.*;
class Information extends Frame {
Button btnClose;
Panel panelForm;
Label labelName, labelCourse, labelRollNo, labelCollege;
TextField fieldName, fieldCourse, fieldRollNo, fieldCollege;
Information(String name, String course, String rollNo, String college) {
super("Personal Information");
labelName = new Label("Name:");
labelName.setBounds(20, 20, 80, 30);
labelCourse = new Label("Course:");
labelCourse.setBounds(20, 50, 80, 30);
labelRollNo = new Label("Roll No.:");
labelRollNo.setBounds(20, 80, 80, 30);
labelCollege = new Label("College:");
labelCollege.setBounds(20, 110, 80, 30);
fieldName = new TextField(name);
fieldName.setBounds(100, 22, 200, 24);
fieldName.setEditable(false);
fieldCourse = new TextField(course);
fieldCourse.setBounds(100, 52, 200, 24);
fieldCourse.setEditable(false);
fieldRollNo = new TextField(rollNo);
fieldRollNo.setBounds(100, 82, 200, 24);
fieldRollNo.setEditable(false);
fieldCollege = new TextField(college);
fieldCollege.setBounds(100, 112, 200, 24);
fieldCollege.setEditable(false);
btnClose = new Button("Close");
btnClose.setBounds(100, 150, 125, 30);
btnClose.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
panelForm = new Panel();
panelForm.setLayout(null);
panelForm.add(labelName);
panelForm.add(fieldName);
panelForm.add(labelCourse);
panelForm.add(fieldCourse);
panelForm.add(labelRollNo);
panelForm.add(fieldRollNo);
panelForm.add(labelCollege);
panelForm.add(fieldCollege);
panelForm.add(btnClose);
this.add(panelForm);
this.setSize(350, 250);
this.setVisible(true);
this.setLayout(null);
this.setLocationRelativeTo(null);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
}
/**** CGPA.java ****/
import java.awt.*;
import java.awt.event.*;
class CGPA extends Frame {
Label l;
Button btnClose;
CGPA(String cgpa) {
super("Previous Year CGPA");
l = new Label("Your CGPA was: " + cgpa);
l.setBounds(10, 50, 280, 30);
l.setAlignment(Label.CENTER);
btnClose = new Button("Close");
btnClose.setBounds(20, 85, 260, 30);
btnClose.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
this.add(l);
this.add(btnClose);
this.setSize(300, 150);
this.setLayout(null);
this.setVisible(true);
this.setLocationRelativeTo(null);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
}