From aad104ad8ee95d0d30e17b3c1cdc80180c406774 Mon Sep 17 00:00:00 2001 From: dex_moth Date: Mon, 27 Nov 2023 10:20:47 +0400 Subject: [PATCH] it's all --- src/FormAirbusCollection.java | 1 + src/FormGenerationAirbus.java | 61 ++++++++++++++++++++++++--- src/Generics/GenericParametrized.java | 18 ++++---- 3 files changed, 65 insertions(+), 15 deletions(-) diff --git a/src/FormAirbusCollection.java b/src/FormAirbusCollection.java index d035024..da76684 100644 --- a/src/FormAirbusCollection.java +++ b/src/FormAirbusCollection.java @@ -70,6 +70,7 @@ public class FormAirbusCollection extends JFrame { @Override public void actionPerformed(ActionEvent e) { FormGenerationAirbus form = new FormGenerationAirbus(); + dispose(); } }; diff --git a/src/FormGenerationAirbus.java b/src/FormGenerationAirbus.java index 8df0409..03117cf 100644 --- a/src/FormGenerationAirbus.java +++ b/src/FormGenerationAirbus.java @@ -1,13 +1,22 @@ -import Drawnings.DrawningAirbus; +import Drawnings.*; +import Entities.EntityAirbus; +import Entities.EntityPlane; import Generics.AirbusGenericCollection; +import Generics.GenericParametrized; import MovementStrategy.DrawningObjectAirbus; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; import javax.swing.*; public class FormGenerationAirbus extends JFrame { Canvas canvas; + GenericParametrized generic; DrawningAirbus _airbus; + private int _width = 800; + private int _height = 500; JButton buttonGenerate; @@ -17,8 +26,10 @@ public class FormGenerationAirbus extends JFrame { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(null); + generic = new GenericParametrized<>(50, 50, _width, _height); + canvas = new FormGenerationAirbus.Canvas(); - canvas.setBounds(0 , 0, 800, 500); + canvas.setBounds(0 , 0, _width, _height); buttonGenerate = new JButton("Сгенерировать аэробус"); buttonGenerate.setMargin(new Insets(0, 0, 0, 0)); @@ -27,17 +38,53 @@ public class FormGenerationAirbus extends JFrame { add(canvas); add(buttonGenerate); setVisible(true); + + buttonGenerate.addActionListener(GenerateAirbus); } - class Canvas extends JComponent { - public AirbusGenericCollection _airbus; + ActionListener GenerateAirbus = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random rand = new Random(); + // генерация сущности + EntityAirbus entity; + if (rand.nextBoolean()) { + entity = new EntityAirbus( + rand.nextInt(200) + 100, rand.nextInt(2000) + 1000, + new Color(rand.nextInt(0, 256), rand.nextInt(0, 256), rand.nextInt(0, 256))); + } else { + entity = new EntityPlane(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000, + new Color(rand.nextInt(0, 256), rand.nextInt(0, 256), rand.nextInt(0, 256)), + new Color(rand.nextInt(0, 256), rand.nextInt(0, 256), rand.nextInt(0, 256)), + rand.nextBoolean(), rand.nextBoolean()); + } + generic.addAirbus(entity); + // генерация иллюминаторов + IDrawningPortholes potholes; + int n = rand.nextInt(3); + if (n == 0) + potholes = new DrawningPortholesCircle(); + else if (n == 1) + potholes = new DrawningPortholesHeart(); + else + potholes = new DrawningPortholesSquare(); + potholes.SetCount(rand.nextInt(1,4)*10); + generic.addPortholes(potholes); + // отрисовка + _airbus = generic.randomDrawingObject(); + _airbus.SetPosition(100, 100); + canvas.repaint(); + } + }; + + class Canvas extends JComponent { public Canvas() {} public void paintComponent(Graphics g) { super.paintComponents(g); - if (_airbus.ShowAirbus() != null) { - g.drawImage(_airbus.ShowAirbus(), 0, 0, this); - } + Graphics2D g2d = (Graphics2D)g; + if (_airbus != null) + _airbus.DrawTransport(g2d); super.repaint(); } } diff --git a/src/Generics/GenericParametrized.java b/src/Generics/GenericParametrized.java index 5637449..0767a63 100644 --- a/src/Generics/GenericParametrized.java +++ b/src/Generics/GenericParametrized.java @@ -24,6 +24,8 @@ public class GenericParametrized(); + _portholes = new ArrayList(); } public boolean addAirbus(T airbus) @@ -52,14 +54,7 @@ public class GenericParametrized