-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSemafor.java
68 lines (56 loc) · 1.59 KB
/
Semafor.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
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author lacal
*/
public class Semafor extends JComponent {
public int j = 0;
public Semafor() {
setBounds(getX(), getY(), 300, 300);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
vykresli(g);
}
public void farby() {
j++;
if (j > 4) {
j = 1;
}
repaint();
}
public void vykresli(Graphics g) { // vykreslenie
// telo
g.setColor(Color.DARK_GRAY);
g.fillRect(100, 100, 100, 200);
g.setColor(Color.GRAY);
if (j == 1 || j == 2) { // svieti červena
g.setColor(Color.red);
if (j == 1) {
System.err.println("Červená");
}
}
g.fillOval(130, 120 + 0 * 50, 40, 40);
g.setColor(Color.GRAY);
if (j == 2 || j == 4) { // svieti žlta
g.setColor(Color.YELLOW);
System.err.println("Žltá");
}
g.fillOval(130, 120 + 1 * 50, 40, 40);
g.setColor(Color.GRAY);
if (j == 3) { // svieti zelena
g.setColor(Color.green);
System.err.println("Zelená");
}
g.fillOval(130, 120 + 2 * 50, 40, 40);
g.setColor(Color.GRAY);
}
}