From f25feff68b902db07789f244dbe06f83f7cb81c3 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Wed, 2 Nov 2022 08:51:14 +0300 Subject: [PATCH] add setCount in DrawingEngines --- Canvas.java | 6 +++--- DrawingEngines.java | 7 +++++-- Form.java | 5 +++++ FormAircraft.java | 5 +++-- 4 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 Form.java diff --git a/Canvas.java b/Canvas.java index be5f0df..6421b3a 100644 --- a/Canvas.java +++ b/Canvas.java @@ -2,14 +2,14 @@ import javax.swing.*; import java.awt.*; public class Canvas extends JComponent { - FormAircraft form; - public Canvas(FormAircraft form) { + Form form; + public Canvas(Form form) { this.form = form; } @Override public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; - form.draw(g2); + form.Draw(g2); } } diff --git a/DrawingEngines.java b/DrawingEngines.java index 9878094..baa2d39 100644 --- a/DrawingEngines.java +++ b/DrawingEngines.java @@ -5,11 +5,14 @@ public class DrawingEngines { private Color color; public void Init(int count, Color bodyColor) { + setCount(count); + color = bodyColor; + } + + public void setCount(int count) { if(count <= 2) enginesCount = EnginesCount.Two; else if(count >= 6) enginesCount = EnginesCount.Six; else enginesCount = EnginesCount.Four; - - color = bodyColor; } public void draw(Graphics2D g, int startPosX, int startPosY) { diff --git a/Form.java b/Form.java new file mode 100644 index 0000000..0347fbb --- /dev/null +++ b/Form.java @@ -0,0 +1,5 @@ +import java.awt.*; + +public interface Form { + void Draw(Graphics2D g); +} diff --git a/FormAircraft.java b/FormAircraft.java index 9441cf7..e53b6af 100644 --- a/FormAircraft.java +++ b/FormAircraft.java @@ -5,7 +5,7 @@ import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.util.Random; -public class FormAircraft { +public class FormAircraft implements Form { private JButton createButton; private JButton upButton; private JButton rightButton; @@ -88,7 +88,8 @@ public class FormAircraft { }); } - public void draw(Graphics2D g) { + @Override + public void Draw(Graphics2D g) { if(_airFighter == null) return; _airFighter.DrawTransport(g); }