67 lines
2.3 KiB
Java
67 lines
2.3 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class FormGallery extends JFrame {
|
|
private static final Random rnd = new Random();
|
|
private JPanel contentPanel;
|
|
private JButton buttonRefresh;
|
|
private JPanel pictureBox;
|
|
private IDrawningObject first;
|
|
private IDrawningObject second;
|
|
private IDrawningObject third;
|
|
|
|
private final EntityWithRollers<EntityTracktor, IDrawningRollers> storage;
|
|
|
|
public FormGallery() {
|
|
setTitle("Галлерея");
|
|
setContentPane(contentPanel);
|
|
|
|
storage = new EntityWithRollers<>(20);
|
|
|
|
for(int i = 0; i < 20; i++) {
|
|
if (rnd.nextBoolean()) {
|
|
storage.add(new EntityTrackedVehicle(
|
|
rnd.nextInt(100, 300),
|
|
rnd.nextInt(1000, 2000),
|
|
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
|
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
|
rnd.nextBoolean(),
|
|
rnd.nextBoolean()
|
|
));
|
|
} else {
|
|
storage.add(new EntityTracktor(
|
|
rnd.nextInt(100, 300),
|
|
rnd.nextInt(1000, 2000),
|
|
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256))
|
|
));
|
|
}
|
|
storage.add(RollersType.random(rnd.nextInt(4, 7), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256))));
|
|
}
|
|
|
|
buttonRefresh.addActionListener(e -> {
|
|
first = storage.constructTracktor();
|
|
second = storage.constructTracktor();
|
|
third = storage.constructTracktor();
|
|
|
|
first.setObject(0, 10, pictureBox.getWidth(), pictureBox.getHeight());
|
|
second.setObject(150, 10, pictureBox.getWidth(), pictureBox.getHeight());
|
|
third.setObject(300, 10, pictureBox.getWidth(), pictureBox.getHeight());
|
|
|
|
repaint();
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void paint(Graphics g) {
|
|
super.paint(g);
|
|
Graphics2D g2g = (Graphics2D) pictureBox.getGraphics();
|
|
|
|
if (first != null && second != null && third != null) {
|
|
first.drawningObject(g2g);
|
|
second.drawningObject(g2g);
|
|
third.drawningObject(g2g);
|
|
}
|
|
}
|
|
}
|