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 contentPane;
|
|
private JButton buttonRefresh;
|
|
private JPanel pictureBox;
|
|
private IDrawingObject first;
|
|
private IDrawingObject second;
|
|
private IDrawingObject third;
|
|
|
|
private final EntityWithRollers<EntityArtillery, IDrawingRollers> storage;
|
|
|
|
public FormGallery() {
|
|
setTitle("Галлерея");
|
|
setContentPane(contentPane);
|
|
|
|
storage = new EntityWithRollers<>(20);
|
|
|
|
for(int i = 0; i < 20; i++) {
|
|
if (rnd.nextBoolean()) {
|
|
storage.add(new EntityAdvancedArtillery(
|
|
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 EntityArtillery(
|
|
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.constructArtillery();
|
|
second = storage.constructArtillery();
|
|
third = storage.constructArtillery();
|
|
|
|
first.setObject(0, 10, pictureBox.getWidth(), pictureBox.getHeight());
|
|
second.setObject(90, 10, pictureBox.getWidth(), pictureBox.getHeight());
|
|
third.setObject(190, 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.drawingObject(g2g);
|
|
second.drawingObject(g2g);
|
|
third.drawingObject(g2g);
|
|
}
|
|
}
|
|
}
|