-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonWithState.java
More file actions
89 lines (82 loc) · 1.45 KB
/
ButtonWithState.java
File metadata and controls
89 lines (82 loc) · 1.45 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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonWithState
{
static JButton button = new JButton("Change");
static String state = "X";
public static void main(String[] args)
{
JFrame frame = new JFrame("Changes");
frame.setSize(400,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//inner class inside main
class StateListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
button.setText(state);
changeState();
}
}
button.addActionListener(new StateListener());
button.setFont(new Font("SanSerif",0,60));
frame.add(button);
frame.setVisible(true);
}
public static void changeState()
{
if (state.equals("X"))
state = "a";
else if
state = "b";
else if
state = "c";
else if
state = "d";
else if
state = "e";
else if
state = "f";
else if
state = "g";
else if
state = "h";
else if
state = "i";
else if
state = "j";
else if
state = "k";
else if
state = "l";
else if
state = "m";
else if
state = "n";
else if
state = "o";
else if
state = "p";
else if
state = "q";
else if
state = "r";
else if
state = "s";
else if
state = "t";
else if
state = "u";
else if
state = "v";
else if
state = "w";
else if
state = "x";
else if
state = "y";
else if
state = "z";
}
}