-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonListener.java
More file actions
109 lines (93 loc) · 2.96 KB
/
ButtonListener.java
File metadata and controls
109 lines (93 loc) · 2.96 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
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ButtonListener implements ActionListener
{
private JLabel l;
public ButtonListener(JLabel label)
{
l = label;
}
public void actionPerformed(ActionEvent e)
{
String[] vargu = {"2", "3"};
String text = "";
if (!l.getText().equals("0"))
{
text = l.getText();
}
if(Detyra.count != 240)
{
if (e.getActionCommand().equals("+") && !l.getText().equals("0") && !l.getText().equals(""))
{
Detyra.shenja = "+";
Detyra.numrat.add(Integer.parseInt(text));
l.setText("");
}
if (e.getActionCommand().equals("x") && !l.getText().equals("0") && !l.getText().equals(""))
{
Detyra.shenja = "x";
Detyra.numrat.add(Integer.parseInt(text));
l.setText("");
}
for (String s : vargu)
{
if (e.getActionCommand().equals(s))
{
text = text + s;
l.setText(text);
}
}
if (e.getActionCommand().equals("=") && !l.getText().equals("0") && !l.getText().equals(""))
{
Detyra.numrat.add(Integer.parseInt(text));
if (Detyra.shenja.equals("+"))
{
l.setText(operation("+") + "");
Detyra.numrat.add(operation("+"));
}
if (Detyra.shenja.equals("x"))
{
l.setText(operation("x") + "");
Detyra.numrat.add(operation("x"));
}
}
if (e.getActionCommand().equals("C"))
{
l.setText("0");
Detyra.numrat.clear();
}
if(e.getActionCommand().equals("Reset"))
{
Detyra.reset_boolean = true;
Detyra.stopwatch.stop();
Detyra.count = 240;
Detyra.timer_label.setText("Time remaining: 04:00");
}
}
if(e.getActionCommand().equals("Start"))
{
Detyra.count = 240;
Detyra.startTimer(240);
}
if(e.getActionCommand().equals("Try Again") || e.getActionCommand().equals("Play Again"))
{
End_Panel.again = true;
}
}
public int operation(String shenja)
{
int result = 0;
int a = Detyra.numrat.get(Detyra.numrat.size()-1);
int b = Detyra.numrat.get(Detyra.numrat.size()-2);
if(shenja.equals("+"))
{
result = a+b;
}
if(shenja.equals("x"))
{
result = a*b;
}
return result;
}
}