From e5a1bec005a24af42c18740d1c58411af5427b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 29 Nov 2022 00:17:16 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrawingShip.java | 13 ++++++++++--- FormShip.form | 44 +++++++++++++++++++++++++++----------------- FormShip.java | 27 +++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/DrawingShip.java b/DrawingShip.java index f504d6e..f39d47d 100644 --- a/DrawingShip.java +++ b/DrawingShip.java @@ -3,14 +3,14 @@ import java.awt.*; import java.util.*; public class DrawingShip extends JPanel { - private EntityWarmlyShip warmlyShip; //Класс-сущность + public EntityWarmlyShip warmlyShip; //Класс-сущность public EntityWarmlyShip GetWarmlyShip(){return warmlyShip;} public float _startPosX; //Координаты отрисовки по оси x public float _startPosY; //Координаты отрисовки по оси y private Integer _pictureWidth = null; //Ширина окна private Integer _pictureHeight = null; //Высота окна - private final int _warmlyShipWidth = 125; //Ширина отрисовки корабля - private final int _warmlyShipHeight = 50; //Высота отрисовки корабля + protected int _warmlyShipWidth = 125; //Ширина отрисовки корабля + protected int _warmlyShipHeight = 50; //Высота отрисовки корабля private int deckCount = 1; private DrawDeck dd = new DrawDeck(); @@ -23,6 +23,13 @@ public class DrawingShip extends JPanel { dd.SetDeckCount(random.nextInt(1, 4)); } + protected DrawingShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight) + { + this(speed, weight, bodyColor); + _warmlyShipWidth = warmlyWidth; + _warmlyShipHeight = warmlyHeight; + } + //Начальные коордитанты public void SetPosition(int x, int y, int width, int height) { diff --git a/FormShip.form b/FormShip.form index 42e407f..d356abf 100644 --- a/FormShip.form +++ b/FormShip.form @@ -1,6 +1,6 @@
- + @@ -13,7 +13,7 @@ - + @@ -25,7 +25,7 @@ - + @@ -38,7 +38,7 @@ - + @@ -50,7 +50,7 @@ - + @@ -62,16 +62,6 @@ - - - - - - - - - - @@ -84,7 +74,7 @@ - + @@ -96,12 +86,32 @@ - + + + + + + + + + + + + + + + + + + + + + diff --git a/FormShip.java b/FormShip.java index 7fa214a..707cf9c 100644 --- a/FormShip.java +++ b/FormShip.java @@ -15,6 +15,7 @@ public class FormShip extends JFrame{ private JButton buttonUp; private JButton buttonDown; private JPanel GraphicsOutput; + private JButton buttonCreateModif; private JLabel JLabelSpeed = new JLabel(); private JLabel JLabelWeight = new JLabel(); private JLabel JLabelColor = new JLabel(); @@ -36,6 +37,15 @@ public class FormShip extends JFrame{ validate(); } + private void SetData() + { + Random random = new Random(); + ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), GraphicsOutput.getWidth(), GraphicsOutput.getHeight()); + JLabelSpeed.setText("Cкорость: " + ship.GetWarmlyShip().GetSpeed() + " "); + JLabelWeight.setText("Вес: " + ship.GetWarmlyShip().GetWeight() + " "); + JLabelColor.setText(("Цвет: " + ship.GetWarmlyShip().GetBodyColor() + " ")); + } + private void ButtonMove_Click(String name) { if (ship == null) return; @@ -84,10 +94,7 @@ public class FormShip extends JFrame{ public void actionPerformed(ActionEvent e) { Random random = new Random(); ship = new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256))); - ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), GraphicsOutput.getWidth(), GraphicsOutput.getHeight()); - JLabelSpeed.setText("Cкорость: " + ship.GetWarmlyShip().GetSpeed() + " "); - JLabelWeight.setText("Вес: " + ship.GetWarmlyShip().GetWeight() + " "); - JLabelColor.setText(("Цвет: " + ship.GetWarmlyShip().GetBodyColor() + " ")); + SetData(); Draw(); } }); @@ -125,5 +132,17 @@ public class FormShip extends JFrame{ Draw(); } }); + buttonCreateModif.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random random = new Random(); + ship = new DrawningMotorShip(random.nextInt(100, 300), random.nextInt(1000, 3000), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), + random.nextBoolean(), random.nextBoolean()); + SetData(); + Draw(); + } + }); } }