IT AINT BROKEN NOW (jar still broken)

This commit is contained in:
LinlyBoi
2023-03-04 12:06:25 +02:00
commit 1dc7909a90
20 changed files with 614 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
package org.bootcamp.TrafficLights;
import java.awt.Color;
/** greenlight */
public class Greenlight extends Light {
Greenlight() {
super(5, Color.GREEN);
}
}

View File

@@ -0,0 +1,83 @@
/** light */
package org.bootcamp.TrafficLights;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.concurrent.TimeUnit;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
public class Light extends JPanel implements Runnable {
int radius;
int top;
int bottom;
int timeout;
int length = 100;
Color color;
Light() {
// this.setPreferredSize(new Dimension(250, 250));
this.setPreferredSize(new Dimension(length, length));
top = (length - radius) / 2;
bottom = (length - radius) / 2;
radius = length / 2;
setVisible(true);
timeout = 5;
}
Light(int timeout, Color color) {
this();
this.timeout = timeout;
this.color = color;
this.setBorder(BorderFactory.createLineBorder(Color.BLACK, 10));
setVisible(false);
setBackground(Color.BLACK);
}
public void run() {
setVisible(true);
try {
TimeUnit.SECONDS.sleep(timeout);
} catch (InterruptedException e) {
e.printStackTrace();
}
setVisible(false);
// flicker();
}
public void flicker() {
for (int i = 0; i < 4; i++) {
try {
setVisible(false);
TimeUnit.MILLISECONDS.sleep(500);
setVisible(true);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
setVisible(false);
}
@Override
public void paint(Graphics g) {
// GOTTA DO THIS
super.paint(g);
setOpaque(true);
setBorder(BorderFactory.createLineBorder(Color.WHITE));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2D = (Graphics2D) g;
g2D.setPaint(color);
g2D.setStroke(new BasicStroke(5));
g2D.fillOval(top, bottom, radius, radius);
}
}

View File

@@ -0,0 +1,9 @@
package org.bootcamp.TrafficLights;
import java.awt.Color;
public class Redlight extends Light {
Redlight() {
super(5, Color.RED);
}
}

View File

@@ -0,0 +1,21 @@
package org.bootcamp.TrafficLights;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
/** Sign */
public class Sign extends JFrame {
Light TestLight;
Sign() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridLayout(4, 1));
this.setPreferredSize(new Dimension(300, 300));
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setBackground(Color.BLACK);
}
}

View File

@@ -0,0 +1,42 @@
package org.bootcamp.TrafficLights;
import javax.swing.JButton;
public class Traffic {
public static boolean pressed = false;
public static void main(String[] args) {
// Lights
Redlight redlight = new Redlight();
Yellowlight yellowlight = new Yellowlight();
Greenlight greenlight = new Greenlight();
// Container for the lights and button to stop
Sign Traffic_Sign = new Sign();
Traffic_Sign.add(redlight, 0);
Traffic_Sign.add(yellowlight, 1);
Traffic_Sign.add(greenlight, 2);
// Threads
Thread red_thread = new Thread(redlight);
Thread yellow_thread = new Thread(yellowlight);
Thread green_thread = new Thread(greenlight);
// Button
JButton StopButton = new JButton("STOP");
StopButton.addActionListener(
e -> {
pressed = true;
});
Traffic_Sign.add(StopButton, 3);
while (true) {
red_thread.run();
if (pressed) break;
yellow_thread.run();
if (pressed) break;
green_thread.run();
if (pressed) break;
}
}
}

View File

@@ -0,0 +1,10 @@
package org.bootcamp.TrafficLights;
import java.awt.Color;
public class Yellowlight extends Light {
Yellowlight() {
super(5, Color.YELLOW);
}
}

View File

@@ -0,0 +1,9 @@
package org.bootcamp.template;
import org.junit.jupiter.api.Test;
class TemplateTest {
@Test
void firstCase() {}
}