-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPanelCreator.java
36 lines (34 loc) · 1.18 KB
/
PanelCreator.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
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class PanelCreator extends Thread {
JPanel desk;
Window window;
JLabel score;
public PanelCreator(JPanel desk, Window window, JLabel score) {
this.desk = desk;
this.window = window;
this.score = score;
}
public void run() {
while (!window.gameOver) {
Random rand = new Random();
int random=rand.nextInt(200);
JPanel panelTop = new JPanel();
JPanel panelBottom = new JPanel();
panelTop.setBounds(500, 0, 30, random);
panelBottom.setBounds(500, 250, 30, random+500);
panelTop.setBackground(Color.green);
panelBottom.setBackground(Color.green);
desk.add(panelTop);
desk.add(panelBottom);
PanelMovement panelMovement = new PanelMovement(desk, panelTop, panelBottom, window, score);
panelMovement.start();
try {
Thread.sleep(2000); // Delay between obstacles
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}