-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo2.java
More file actions
111 lines (97 loc) · 2.7 KB
/
Demo2.java
File metadata and controls
111 lines (97 loc) · 2.7 KB
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
package GUI;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Demo2 extends JFrame {
private JTextField textField;
private boolean isXOrZero = false;
/**
* Launch the application.
*/
public static void main(String[] args) {
Demo2 frame = new Demo2();
frame.setVisible(true);
}
/**
* Create the frame.
*/
public Demo2() {
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
Demo2.this.setVisible(false);
Demo2.this.dispose();
}
});
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setBounds(100, 100, 450, 300);
getContentPane().setLayout(null);
JButton btnCancel = new JButton("Cancel");
btnCancel.setFont(new Font("Tahoma", Font.BOLD, 18));
JButton btnOk = new JButton("Ok");
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnCancel.setText("Hello");
textField.setText("Hi");
}
});
btnOk.setForeground(Color.RED);
btnOk.setFont(new Font("Tahoma", Font.BOLD, 16));
btnOk.setBounds(66, 210, 89, 23);
getContentPane().add(btnOk);
btnCancel.setBounds(216, 209, 161, 23);
getContentPane().add(btnCancel);
textField = new JTextField();
textField.setFont(new Font("Tahoma", Font.BOLD, 18));
textField.setBounds(56, 145, 200, 50);
getContentPane().add(textField);
textField.setColumns(10);
JButton one = new JButton("");
one.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
xorZero(one);
}
});
one.setFont(new Font("Tahoma", Font.BOLD, 18));
one.setBounds(20, 28, 119, 50);
getContentPane().add(one);
JButton two = new JButton("");
two.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
xorZero(two);
}
});
two.setFont(new Font("Tahoma", Font.BOLD, 18));
two.setBounds(163, 28, 119, 50);
getContentPane().add(two);
JButton three = new JButton("");
three.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
xorZero(three);
}
});
three.setFont(new Font("Tahoma", Font.BOLD, 18));
three.setBounds(305, 28, 119, 50);
getContentPane().add(three);
}
void xorZero(JButton b1) {
if (b1.getText().trim().length() == 0) {
if (isXOrZero) {
b1.setText("0");
} else {
b1.setText("X");
}
isXOrZero = !isXOrZero;
}
}
}