88 lines
3.9 KiB
Java
88 lines
3.9 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
public class FormEntityWithExtraGallery extends JComponent
|
|
{
|
|
private DrawingAirbus _airbusFirst;
|
|
private DrawingAirbus _airbusSecond;
|
|
private DrawingAirbus _airbusThird;
|
|
EntityWithIlumCreator<EntityAirbus, IDrawingIlum> entityWithExtraCreator;
|
|
|
|
public FormEntityWithExtraGallery() {
|
|
JFrame formFrame = new JFrame("Gallery");
|
|
formFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
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);
|
|
|
|
JButton showRandomEntity = new JButton("Create entity from parts");
|
|
showRandomEntity.addActionListener(e -> {
|
|
|
|
Random random = new Random();
|
|
if (entityWithExtraCreator == null) {
|
|
entityWithExtraCreator = new EntityWithIlumCreator<EntityAirbus, IDrawingIlum>(20, 20);
|
|
for (int i = 0; i < 20; i ++) {
|
|
if (random.nextBoolean()) {
|
|
entityWithExtraCreator.Insert(new EntityAirbus(random.nextInt(100), random.nextInt(100),
|
|
new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255))));
|
|
}
|
|
else {
|
|
entityWithExtraCreator.Insert(new EntityAdvancedAirbus(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 DrawingIlum(random.nextInt(3),
|
|
new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255))));
|
|
break;
|
|
|
|
case 1:
|
|
entityWithExtraCreator.Insert(new DrawingPlusIlum(random.nextInt(3),
|
|
new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255))));
|
|
break;
|
|
|
|
case 2:
|
|
entityWithExtraCreator.Insert(new DrawingSquareIlum(random.nextInt(3),
|
|
new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255))));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
_airbusFirst = entityWithExtraCreator.getEntityWithExtra();
|
|
_airbusFirst.SetPosition(200, 200, formFrame.getWidth(), formFrame.getHeight() - 75);
|
|
|
|
_airbusSecond = entityWithExtraCreator.getEntityWithExtra();
|
|
_airbusSecond.SetPosition(400, 200, formFrame.getWidth(), formFrame.getHeight() - 75);
|
|
|
|
_airbusThird = entityWithExtraCreator.getEntityWithExtra();
|
|
_airbusThird.SetPosition(600, 200, formFrame.getWidth(), formFrame.getHeight() - 75);
|
|
repaint();
|
|
});
|
|
statusPanel.add(showRandomEntity);
|
|
|
|
formFrame.getContentPane().add(this);
|
|
|
|
formFrame.setVisible(true);
|
|
}
|
|
|
|
@Override
|
|
protected void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
Graphics2D g2 = (Graphics2D)g;
|
|
if (_airbusFirst != null) _airbusFirst.DrawTransport(g2);
|
|
if (_airbusSecond != null) _airbusSecond.DrawTransport(g2);
|
|
if (_airbusThird != null) _airbusThird.DrawTransport(g2);
|
|
super.repaint();
|
|
}
|
|
}
|