From b500486bd03b155da6b72c5ff0e5175ada5f818d Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Oct 2022 17:28:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=D1=82=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/FormArmoredCar.form | 18 +++++++++++++----- src/main/java/FormArmoredCar.java | 31 +++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/main/java/FormArmoredCar.form b/src/main/java/FormArmoredCar.form index e82df6d..5cbc8f9 100644 --- a/src/main/java/FormArmoredCar.form +++ b/src/main/java/FormArmoredCar.form @@ -22,7 +22,7 @@ - + @@ -40,7 +40,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -69,7 +69,7 @@ - + @@ -77,6 +77,14 @@ + + + + + + + + diff --git a/src/main/java/FormArmoredCar.java b/src/main/java/FormArmoredCar.java index 923ab88..cfea465 100644 --- a/src/main/java/FormArmoredCar.java +++ b/src/main/java/FormArmoredCar.java @@ -17,6 +17,7 @@ public class FormArmoredCar extends JFrame{ private JLabel labelSpeed; private JLabel labelWeight; private JLabel labelColor; + private JButton buttonCreate_Modif; private DrawingArmoredCar armoredCar; @@ -45,12 +46,7 @@ public class FormArmoredCar extends JFrame{ armoredCar = new DrawingArmoredCar(rnd.nextInt(100,300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))); - armoredCar.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), - drawPanel.getWidth(), drawPanel.getHeight()); - - labelSpeed.setText("Скорость: " + armoredCar.getArmoredCar().getSpeed()); - labelWeight.setText("Вес: " + armoredCar.getArmoredCar().getWeight()); - labelColor.setText("Цвет: " + armoredCar.getArmoredCar().getBodyColor().getRGB()); + setData(); } }); @@ -93,6 +89,20 @@ public class FormArmoredCar extends JFrame{ setContentPane(mainPanel); setVisible(true); + buttonCreate_Modif.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random rnd = new Random(); + armoredCar = new DrawingTank(rnd.nextInt(100, 300), rnd.nextInt(1000, + 2000), + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, + 256)), + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, + 256)), + 1==rnd.nextInt(0, 2), 1==rnd.nextInt(0, 2)); + setData(); + } + }); } private void createUIComponents() { @@ -108,4 +118,13 @@ public class FormArmoredCar extends JFrame{ } }; } + + private void setData() + { + Random rnd = new Random(); + armoredCar.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), drawPanel.getWidth(), drawPanel.getHeight()); + labelSpeed.setText("Скорость: " + armoredCar.getArmoredCar().getSpeed()); + labelWeight.setText("Вес: " + armoredCar.getArmoredCar().getWeight()); + labelColor.setText("Цвет: " + armoredCar.getArmoredCar().getBodyColor().getRGB()); + } } \ No newline at end of file