-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerWindow.java
More file actions
49 lines (46 loc) · 1022 Bytes
/
TimerWindow.java
File metadata and controls
49 lines (46 loc) · 1022 Bytes
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
package MemoryGrid;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
@SuppressWarnings("serial")
class TimerWindow extends JFrame implements ActionListener
{ //creation of an window using JFrame
private int start = 1;
private JButton jbtn; //creation of button inside the JFrame window
private Timer swingtimer; //swing timer instance
TimerWindow(int tm)
{
start += tm;
setTitle("Timer Window");
setLayout(new FlowLayout());
setTimer();
setSize(700,350);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void setTimer()
{
jbtn = new JButton("Staring Timer...");
add(jbtn);
swingtimer = new Timer(2222,this);
swingtimer.start();
}
public void actionPerformed(ActionEvent evnt)
{
start--;
if(start>=1)
{
jbtn.setText("Time : "+start); //changing the label of button as the timer decrases
}else{
jbtn.setText("Timeout... Now,Close the Window");
swingtimer.stop();
}
}
}
class Timerinswing
{
static public void main(String[] args)
{
TimerWindow tw = new TimerWindow(5);
}
}