-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtidtest.java
90 lines (64 loc) · 1.51 KB
/
tidtest.java
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
/*****************************************************
TNM040 - GUI project
Group 1:
Dag Hansson
Mathias Bergqvist
Henrik Gunnarsson
*****************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class tidtest extends JFrame implements ActionListener{
private JButton knapp;
private javax.swing.Timer timer;
//Timer t;
private JLabel bild;
private ImageIcon var, var2;
tidtest(){
knapp = new JButton("tryck!");
knapp.addActionListener(this);
timer = new javax.swing.Timer(2000,this);
timer.addActionListener(this);
//t = new Timer();
var = new ImageIcon("Bilder/rättknapp.png");
var2 = new ImageIcon("Bilder/tomknapp");
bild = new JLabel();
//Container
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.setBackground(Color.white);
c.add(knapp);
c.add(bild);
setTitle("timer");
setSize(200,200);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void setBild()
{
while (timer.isRunning() == true)
{
bild.setIcon(var);
//bild.setIcon(var2);
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == knapp)
{
timer.setRepeats(false);
timer.start();
//setBild();
//bild.setIcon(var);
bild.setIcon(var);
}
else if (e.getSource() == timer)
{
bild.setIcon(var2);
}
}
public static void main(String[] args) {
tidtest blabla = new tidtest();
}
}