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 JLabel JLabelSpeed = new JLabel(); private JLabel JLabelWeight = new JLabel(); private 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("Cкорость: " + 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(); }); } }