2022-10-22 16:12:48 +04:00
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class FormEntityWithExtraGallery extends JComponent {
|
|
|
|
private DrawningLocomotive _locomotiveFirst;
|
|
|
|
private DrawningLocomotive _locomotiveSecond;
|
|
|
|
private DrawningLocomotive _locomotiveThird;
|
|
|
|
EntityWithExtraCreator<EntityLocomotive, IDrawningExtra> entityWithExtraCreator;
|
|
|
|
|
|
|
|
public FormEntityWithExtraGallery() {
|
|
|
|
JFrame formFrame = new JFrame("Gallery");
|
2022-10-25 16:54:14 +04:00
|
|
|
formFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
2022-10-22 16:12:48 +04:00
|
|
|
formFrame.setSize(900, 500);
|
|
|
|
formFrame.setLocationRelativeTo(null);
|
|
|
|
|
|
|
|
Panel statusPanel = new Panel();
|
|
|
|
statusPanel.setBackground(Color.WHITE);
|
|
|
|
statusPanel.setLayout(new FlowLayout());
|
|
|
|
setLayout(new BorderLayout());
|
|
|
|
add(statusPanel, BorderLayout.SOUTH);
|
|
|
|
|
|
|
|
|
2022-10-25 16:54:14 +04:00
|
|
|
|
|
|
|
JButton showRandomEntity = new JButton("Create entity from parts");
|
|
|
|
showRandomEntity.addActionListener(e -> {
|
|
|
|
|
2022-10-22 16:12:48 +04:00
|
|
|
Random random = new Random();
|
2022-10-25 16:54:14 +04:00
|
|
|
if (entityWithExtraCreator == null) {
|
|
|
|
entityWithExtraCreator = new EntityWithExtraCreator<EntityLocomotive, IDrawningExtra>(20, 20);
|
|
|
|
for (int i = 0; i < 20; i ++) {
|
|
|
|
if (random.nextBoolean()) {
|
|
|
|
entityWithExtraCreator.Insert(new EntityLocomotive(random.nextInt(100), random.nextInt(100),
|
2022-10-22 16:12:48 +04:00
|
|
|
new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255))));
|
2022-10-25 16:54:14 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
entityWithExtraCreator.Insert(new EntityWarmlyLocomotive(random.nextInt(100), random.nextInt(100),
|
|
|
|
new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255)),
|
|
|
|
new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255)),
|
|
|
|
random.nextBoolean(), random.nextBoolean()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 20; i ++) {
|
|
|
|
int extraRand = random.nextInt(3);
|
|
|
|
switch (extraRand) {
|
|
|
|
case 0:
|
|
|
|
entityWithExtraCreator.Insert(new ExtraWheelsDraw(random.nextInt(3),
|
|
|
|
new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255))));
|
|
|
|
break;
|
2022-10-22 16:12:48 +04:00
|
|
|
|
2022-10-25 16:54:14 +04:00
|
|
|
case 1:
|
|
|
|
entityWithExtraCreator.Insert(new ExtraStarWheelDraw(random.nextInt(3),
|
|
|
|
new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255))));
|
|
|
|
break;
|
2022-10-22 16:12:48 +04:00
|
|
|
|
2022-10-25 16:54:14 +04:00
|
|
|
case 2:
|
|
|
|
entityWithExtraCreator.Insert(new ExtraRoundWheelDraw(random.nextInt(3),
|
|
|
|
new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255))));
|
|
|
|
break;
|
|
|
|
}
|
2022-10-22 16:12:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_locomotiveFirst = entityWithExtraCreator.getEntityWithExtra();
|
|
|
|
_locomotiveFirst.SetPosition(200, 200, formFrame.getWidth(), formFrame.getHeight() - 75);
|
|
|
|
|
|
|
|
_locomotiveSecond = entityWithExtraCreator.getEntityWithExtra();
|
|
|
|
_locomotiveSecond.SetPosition(400, 200, formFrame.getWidth(), formFrame.getHeight() - 75);
|
|
|
|
|
|
|
|
_locomotiveThird = entityWithExtraCreator.getEntityWithExtra();
|
|
|
|
_locomotiveThird.SetPosition(600, 200, formFrame.getWidth(), formFrame.getHeight() - 75);
|
|
|
|
repaint();
|
|
|
|
});
|
|
|
|
statusPanel.add(showRandomEntity);
|
|
|
|
|
|
|
|
|
|
|
|
formFrame.getContentPane().add(this);
|
2022-10-25 16:54:14 +04:00
|
|
|
|
|
|
|
formFrame.setVisible(true);
|
2022-10-22 16:12:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void paintComponent(Graphics g) {
|
|
|
|
super.paintComponent(g);
|
|
|
|
Graphics2D g2 = (Graphics2D)g;
|
|
|
|
if (_locomotiveFirst != null) _locomotiveFirst.DrawTransport(g2);
|
|
|
|
if (_locomotiveSecond != null) _locomotiveSecond.DrawTransport(g2);
|
|
|
|
if (_locomotiveThird != null) _locomotiveThird.DrawTransport(g2);
|
|
|
|
super.repaint();
|
|
|
|
}
|
|
|
|
}
|