77 lines
2.3 KiB
Java
77 lines
2.3 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class formAircraftGenerator implements Form {
|
|
private JButton generateButton;
|
|
private JPanel drawPanel;
|
|
private JPanel mainPanel;
|
|
private Canvas canv = new Canvas(this);
|
|
|
|
private DrawingAircraft aircraft;
|
|
private AircraftMixer<EntityAircraft, IDrawingEngines> mixer = new AircraftMixer<>(10, 20);
|
|
private JFrame jframe = getFrame();
|
|
|
|
private JFrame getFrame() {
|
|
JFrame frame = new JFrame();
|
|
frame.setVisible(true);
|
|
frame.setBounds(300, 100, 400, 300);
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
return frame;
|
|
}
|
|
|
|
public void run() {
|
|
jframe.add(mainPanel);
|
|
drawPanel.add(canv);
|
|
|
|
Random rnd = new Random();
|
|
|
|
for(int i = 0; i < 10; ++i) {
|
|
if(rnd.nextBoolean()) {
|
|
mixer.add(new EntityAircraft(rnd.nextInt(100, 250), rnd.nextInt(1000, 2000),
|
|
new Color(
|
|
rnd.nextInt(0, 255),
|
|
rnd.nextInt(0, 255),
|
|
rnd.nextInt(0, 255)
|
|
)));
|
|
continue;
|
|
}
|
|
|
|
mixer.add(new EntityModernAircraft(rnd.nextInt(100, 250), rnd.nextInt(1000, 2000),
|
|
new Color(
|
|
rnd.nextInt(0, 255),
|
|
rnd.nextInt(0, 255),
|
|
rnd.nextInt(0, 255)
|
|
),
|
|
new Color(
|
|
rnd.nextInt(0, 255),
|
|
rnd.nextInt(0, 255),
|
|
rnd.nextInt(0, 255)
|
|
),
|
|
rnd.nextBoolean(), rnd.nextBoolean()
|
|
));
|
|
}
|
|
|
|
for(int i = 0; i < 20; ++i) {
|
|
Color randomColor = new Color(
|
|
rnd.nextInt(0, 255),
|
|
rnd.nextInt(0, 255),
|
|
rnd.nextInt(0, 255));
|
|
|
|
mixer.add(EnginesFabric.createRandom(randomColor));
|
|
}
|
|
|
|
generateButton.addActionListener(e -> {
|
|
Dimension canvSize = canv.getSize();
|
|
aircraft = mixer.constructAircraft(canvSize.width, canvSize.height);
|
|
canv.repaint();
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void Draw(Graphics2D g) {
|
|
if(aircraft == null) return;
|
|
aircraft.DrawTransport(g);
|
|
}
|
|
}
|