-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.java
104 lines (84 loc) · 2.3 KB
/
test.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
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Frame extends JFrame {
private JButton btnTutup = new JButton("Tutup");
private JButton btnTambah = new JButton("Tambah");
private JTextField txtA = new JTextField();
private JTextField txtB = new JTextField();
private JTextField txtC = new JTextField();
private JLabel lblA = new JLabel("A :");
private JLabel lblB = new JLabel("B :");
private JLabel lblC = new JLabel("C :");
public MyFrame(){
setTitle("Add CLicker: Battle Royale");
setSize(400,200);
setLocation(new Point(300,200));
setLayout(null);
setResizable(false);
initComponent();
initEvent();
}
private void initComponent(){
btnTutup.setBounds(300,130, 80,25);
btnTambah.setBounds(300,100, 80,25);
txtA.setBounds(100,10,100,20);
txtB.setBounds(100,35,100,20);
txtC.setBounds(100,65,100,20);
lblA.setBounds(20,10,100,20);
lblB.setBounds(20,35,100,20);
lblC.setBounds(20,65,100,20);
add(btnTutup);
add(btnTambah);
add(lblA);
add(lblB);
add(lblC);
add(txtA);
add(txtB);
add(txtC);
}
private void initEvent(){
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(1);
}
});
btnTutup.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnTutupClick(e);
}
});
btnTambah.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnTambahClick(e);
}
});
}
private void btnTutupClick(ActionEvent evt){
System.exit(0);
}
private void btnTambahClick(ActionEvent evt){
Integer x,y,z;
try{
x = Integer.parseInt(txtA.getText());
y = Integer.parseInt(txtB.getText());
z = x + y;
txtC.setText(z.toString());
}catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null,
e.toString(),
"Error",
JOptionPane.ERROR_MESSAGE);
}
}
}