From 41e6816ee51a4bb2f65f072e91192dd7923af910 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Tue, 29 Nov 2022 00:13:32 +0400 Subject: [PATCH] Modified object --- DrawningAirbus.java | 53 +++++++++++++++++++++++++++++++++++++++++++++ DrawningPlane.java | 17 ++++++++++----- EntityAirbus.java | 27 +++++++++++++++++++++++ FormPlane.form | 32 +++++++++++++++++---------- FormPlane.java | 24 +++++++++++++++----- 5 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 DrawningAirbus.java create mode 100644 EntityAirbus.java diff --git a/DrawningAirbus.java b/DrawningAirbus.java new file mode 100644 index 0000000..98c9a28 --- /dev/null +++ b/DrawningAirbus.java @@ -0,0 +1,53 @@ +import java.awt.*; + +public class DrawningAirbus extends DrawningPlane{ + + public DrawningAirbus(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine) + { + super(speed, weight, bodyColor, 140, 70); + Plane = new EntityAirbus(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); + } + @Override + public void DrawTransport(Graphics g) + { + if (! (Plane instanceof EntityAirbus Airbus)) + { + return; + } + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + g2d.setColor(Color.BLACK); + _startPosX += 10; + _startPosY += 5; + super.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 5; + if (Airbus.BodyKit) + { + g.drawRect(_startPosX + 70, _startPosY + 50, 22, 16); + g.drawRect(_startPosX + 8, _startPosY + 18, 22, 16); + g.drawOval(_startPosX, _startPosY + 18, 16, 16); + g.drawOval(_startPosX + 62, _startPosY + 50, 16, 16); + + g2d.setPaint(Airbus.DopColor); + g.fillRect(_startPosX + 70, _startPosY + 50, 22, 16); + g.fillOval(_startPosX + 84, _startPosY + 50, 16, 16); + g.fillOval(_startPosX + 24, _startPosY + 18, 16, 16); + g.fillRect(_startPosX + 8, _startPosY + 18, 22, 16); + + g2d.setPaint(Color.BLACK); + g.fillOval(_startPosX, _startPosY + 18, 16, 16); + g.fillOval(_startPosX + 62, _startPosY + 50, 16, 16); + } + if (Airbus.Wing) + { + g.drawLine(_startPosX + 70, _startPosY + 20, _startPosX + 70, _startPosY + 35); + g.drawLine(_startPosX + 70, _startPosY + 20, _startPosX + 90, _startPosY + 35); + } + if (Airbus.SportLine) + { + g.drawOval(_startPosX + 110, _startPosY + 40, 9, 9); + g.fillOval(_startPosX + 110, _startPosY + 40, 9, 9); + } + } +} diff --git a/DrawningPlane.java b/DrawningPlane.java index 2eb0c65..561078e 100644 --- a/DrawningPlane.java +++ b/DrawningPlane.java @@ -5,19 +5,19 @@ import java.util.random.RandomGenerator; public class DrawningPlane extends JPanel { - private EntityPlane Plane; + EntityPlane Plane; public EntityPlane GetPlane(){ return Plane; } - private int _startPosX; - private int _startPosY; + protected int _startPosX; + protected int _startPosY; public DrawningIlluminator IlluminatorDraw; public Integer _pictureWidth = null; public Integer _pictureHeight = null; - private final int _PlaneWidth = 130; - private final int _PlaneHeight = 70; + private int _PlaneWidth = 130; + private int _PlaneHeight = 70; public void SetIlluminator() { Random r = new Random(); @@ -78,6 +78,13 @@ public class DrawningPlane extends JPanel { } } + protected DrawningPlane(int speed, float weight, Color bodyColor, int planeWidth, int planeHeight) + { + this(speed, weight, bodyColor); + _PlaneWidth = planeWidth; + _PlaneHeight = planeHeight; + } + public void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) { return; diff --git a/EntityAirbus.java b/EntityAirbus.java new file mode 100644 index 0000000..396d409 --- /dev/null +++ b/EntityAirbus.java @@ -0,0 +1,27 @@ +import java.awt.*; + +public class EntityAirbus extends EntityPlane{ + + public Color DopColor; + public Color GetDopColor() { + return DopColor; + } + + public boolean BodyKit; + public boolean GetBodyKit(){ return BodyKit; } + + public boolean Wing; + public boolean GetWing(){ return Wing; } + + public boolean SportLine; + public boolean GetSportLine(){ return SportLine; } + + + public EntityAirbus(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine) { + super(speed, weight, bodyColor); + DopColor = dopColor; + BodyKit = bodyKit; + Wing = wing; + SportLine = sportLine; + } +} diff --git a/FormPlane.form b/FormPlane.form index 2a60811..2426924 100644 --- a/FormPlane.form +++ b/FormPlane.form @@ -1,6 +1,6 @@
- + @@ -13,7 +13,7 @@ - + @@ -25,7 +25,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -50,7 +50,7 @@ - + @@ -62,11 +62,6 @@ - - - - - @@ -77,7 +72,7 @@ - + @@ -85,7 +80,7 @@ - + @@ -95,6 +90,19 @@ + + + + + + + + + + + + + diff --git a/FormPlane.java b/FormPlane.java index e87eb23..ac34cbb 100644 --- a/FormPlane.java +++ b/FormPlane.java @@ -1,12 +1,13 @@ 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.awt.image.BufferedImage; import java.util.Random; + +import static java.lang.Boolean.parseBoolean; + public class FormPlane extends JFrame{ public JPanel Mainpanel; private JButton ButtonCreate; @@ -17,6 +18,7 @@ public class FormPlane extends JFrame{ protected DrawningPlane _plane; private JPanel PictureBox; private JToolBar StatusStrip; + private JButton ButtonModif; private final JLabel JLabelSpeed = new JLabel(); private final JLabel JLabelWeight = new JLabel(); private final JLabel JLabelColor = new JLabel(); @@ -36,6 +38,13 @@ public class FormPlane extends JFrame{ } validate(); } + private void SetData(){ + Random random = new Random(); + _plane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), PictureBox.getWidth(), PictureBox.getHeight()); + JLabelSpeed.setText("Cкорость: " + _plane.GetPlane().GetSpeed() + " "); + JLabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " "); + JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " ")); + } public FormPlane() { Box LabelBox = Box.createHorizontalBox(); LabelBox.setMinimumSize(new Dimension(1, 20)); @@ -58,10 +67,13 @@ public class FormPlane extends JFrame{ ButtonCreate.addActionListener(e -> { Random random = new Random(); _plane = new DrawningPlane(random.nextInt(100, 300),random.nextInt(1000, 2000),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256))); - _plane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), PictureBox.getWidth(), PictureBox.getHeight()); - JLabelSpeed.setText("Cкорость: " + _plane.GetPlane().GetSpeed() + " "); - JLabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " "); - JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " ")); + SetData(); + Draw(); + }); + ButtonModif.addActionListener(e -> { + Random random = new Random(); + _plane = new DrawningAirbus(random.nextInt(100, 300), random.nextInt(1000, 2000), 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(), random.nextBoolean()); + SetData(); Draw(); }); PictureBox.addComponentListener(new ComponentAdapter() {