99 lines
4.2 KiB
Java
99 lines
4.2 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class FormAirbus extends JComponent
|
|
{
|
|
private DrawingAirbus _airbus;
|
|
private DrawingAirbus SelectedAirbus;
|
|
public DrawingAirbus getSelectedAirbus() {
|
|
return SelectedAirbus;
|
|
}
|
|
public FormAirbus(JDialog caller) {
|
|
Panel statusPanel = new Panel();
|
|
statusPanel.setBackground(Color.WHITE);
|
|
statusPanel.setLayout(new GridLayout());
|
|
setLayout(new BorderLayout());
|
|
add(statusPanel, BorderLayout.SOUTH);
|
|
|
|
Label speedLabel = new Label("Speed:");
|
|
Label weightLabel = new Label("Weight:");
|
|
Label colorLabel = new Label("Color:");
|
|
|
|
JButton createButton = new JButton("Create");
|
|
|
|
createButton.addActionListener(e -> {
|
|
Random rand = new Random();
|
|
Color colorFirst = JColorChooser.showDialog(null, "Color", new Color(rand.nextInt(256), rand.nextInt(256),rand.nextInt(256)));
|
|
_airbus = new DrawingAirbus(rand.nextInt( 400 + rand.nextInt(200)), 1000 + rand.nextInt(1000), colorFirst);
|
|
_airbus.SetPosition(10 + rand.nextInt(90), 10 + rand.nextInt(90), 800, 500 - 75);
|
|
speedLabel.setText("Speed: " + _airbus.Airbus.getSpeed());
|
|
weightLabel.setText("Weight: " + (int) _airbus.Airbus.getWeight());
|
|
colorLabel.setText("Color: " + _airbus.Airbus.getBodyColor().getRed() + " " + _airbus.Airbus.getBodyColor().getGreen() + " " + _airbus.Airbus.getBodyColor().getBlue() );
|
|
repaint();
|
|
});
|
|
JButton modifiedButton = new JButton("Modified");
|
|
modifiedButton.addActionListener(e -> {
|
|
Random rand = new Random();
|
|
|
|
Color colorFirst = JColorChooser.showDialog(null, "Color", new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
|
|
Color colorSecond = JColorChooser.showDialog(null, "Color", new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
|
|
_airbus = new DrawingAdvancedAirbus(rand.nextInt(200) + 100, rand.nextInt(1000) + 1000,
|
|
colorFirst,
|
|
colorSecond,
|
|
rand.nextBoolean(),
|
|
rand.nextBoolean());
|
|
_airbus.SetPosition(10 + rand.nextInt(90), 10 + rand.nextInt(90), 500, 500 - 75);
|
|
speedLabel.setText("Speed: " + _airbus.Airbus.getSpeed());
|
|
weightLabel.setText("Weight: " + (int) _airbus.Airbus.getWeight());
|
|
colorLabel.setText("Color: " + _airbus.Airbus.getBodyColor().getRed() + " " + _airbus.Airbus.getBodyColor().getGreen() + " " + _airbus.Airbus.getBodyColor().getBlue() );
|
|
repaint();
|
|
});
|
|
JButton selectAirbusButton = new JButton("Select");
|
|
selectAirbusButton.addActionListener(e -> {
|
|
SelectedAirbus = _airbus;
|
|
caller.dispose();
|
|
});
|
|
statusPanel.add(modifiedButton);
|
|
statusPanel.add(createButton);
|
|
statusPanel.add(speedLabel);
|
|
statusPanel.add(weightLabel);
|
|
statusPanel.add(colorLabel);
|
|
statusPanel.add(selectAirbusButton);
|
|
|
|
JButton moveRightButton = new JButton(">");
|
|
moveRightButton.addActionListener(e -> {
|
|
if (_airbus != null) _airbus.MoveTransport(Direction.Right);
|
|
repaint();
|
|
});
|
|
JButton moveLeftButton = new JButton("<");
|
|
moveLeftButton.addActionListener(e -> {
|
|
if (_airbus != null) _airbus.MoveTransport(Direction.Left);
|
|
repaint();
|
|
});
|
|
JButton moveUpButton = new JButton("^");
|
|
moveUpButton.addActionListener(e -> {
|
|
if (_airbus != null) _airbus.MoveTransport(Direction.Up);
|
|
repaint();
|
|
});
|
|
JButton moveDownButton = new JButton("v");
|
|
moveDownButton.addActionListener(e -> {
|
|
if (_airbus != null) _airbus.MoveTransport(Direction.Down);
|
|
repaint();
|
|
});
|
|
|
|
statusPanel.add(moveRightButton);
|
|
statusPanel.add(moveLeftButton);
|
|
statusPanel.add(moveUpButton);
|
|
statusPanel.add(moveDownButton);
|
|
|
|
}
|
|
@Override
|
|
protected void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
Graphics2D g2 = (Graphics2D)g;
|
|
if (_airbus != null) _airbus.DrawTransport(g2);
|
|
super.repaint();
|
|
}
|
|
}
|