2022-11-27 15:16:31 +04:00

81 lines
3.3 KiB
Java
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Random;
public class FormPlane {
public JPanel Mainpanel;
private JButton ButtonCreate;
private JButton ButtonLeft;
private JButton ButtonUp;
private JButton ButtonDown;
private JButton ButtonRight;
protected DrawningPlane PictureBoxPlane;
private JToolBar StatusStrip;
private final JLabel JLabelSpeed = new JLabel();
private final JLabel JLabelWeight = new JLabel();
private final JLabel JLabelColor = new JLabel();
public void Draw() {
if (PictureBoxPlane.GetPlane() == null) {
return;
}
PictureBoxPlane.DrawTransport();
}
public FormPlane() {
Box LabelBox = Box.createHorizontalBox();
LabelBox.setMinimumSize(new Dimension(1, 20));
LabelBox.add(JLabelSpeed);
LabelBox.add(JLabelWeight);
LabelBox.add(JLabelColor);
StatusStrip.add(LabelBox);
try {
Image img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowUp.jpg"));
ButtonUp.setIcon(new ImageIcon(img));
img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowDown.jpg"));
ButtonDown.setIcon(new ImageIcon(img));
img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowLeft.jpg"));
ButtonLeft.setIcon(new ImageIcon(img));
img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowRight.jpg"));
ButtonRight.setIcon(new ImageIcon(img));
} catch (Exception ex) {
System.out.println(ex);
}
ButtonCreate.addActionListener(e -> {
Random random = new Random();
PictureBoxPlane.Init(random.nextInt(100, 300),random.nextInt(1000, 2000),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
PictureBoxPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
JLabelSpeed.setText("орость: " + PictureBoxPlane.GetPlane().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + PictureBoxPlane.GetPlane().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + PictureBoxPlane.GetPlane().GetBodyColor() + " "));
Draw();
});
PictureBoxPlane.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
PictureBoxPlane.ChangeBorders(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
Draw();
}
});
ButtonUp.addActionListener(e -> {
PictureBoxPlane.MoveTransport(Direction.Up);
Draw();
});
ButtonDown.addActionListener(e -> {
PictureBoxPlane.MoveTransport(Direction.Down);
Draw();
});
ButtonRight.addActionListener(e -> {
PictureBoxPlane.MoveTransport(Direction.Right);
Draw();
});
ButtonLeft.addActionListener(e -> {
PictureBoxPlane.MoveTransport(Direction.Left);
Draw();
});
}
}