-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTimer.java
More file actions
58 lines (43 loc) · 1.37 KB
/
STimer.java
File metadata and controls
58 lines (43 loc) · 1.37 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
package Scientific_Calculate;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
/**
*
* @author syz
*/
class STimer extends JFrame
implements ActionListener{
private JTextField secsField,minsField;
private JLabel secsLabel,minsLabel;
private int ticks=0;
private Timer timer;
public void createGUI(){
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
Container window=getContentPane();
window.setLayout(new FlowLayout());
JButton jb=new JButton("GOT IT");
minsLabel=new JLabel("minutes");
window.add(minsLabel);
minsField=new JTextField("0",5);
window.add(minsField);
secsLabel=new JLabel("seconds");
window.add(secsLabel);
secsField=new JTextField("0",5);
window.add(secsField);
window.add(jb);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();
}
});
timer=new Timer(1000,this);
timer.start();
}
public void actionPerformed(ActionEvent event){
minsField.setText(Integer.toString(ticks/60));
secsField.setText(Integer.toString(ticks%60));
ticks++;
}
}