diff --git a/Project/src/DrawingAirbus.java b/Project/src/DrawingAirbus.java index 8dab024..5d8009b 100644 --- a/Project/src/DrawingAirbus.java +++ b/Project/src/DrawingAirbus.java @@ -2,11 +2,14 @@ import java.awt.*; public class DrawingAirbus extends DrawingPlane { + private Color addColor; + //Конструктор - public DrawingAirbus(int speed, int weight, Color corpusColor, Color addColor, boolean addCompartment, boolean addEngine) + public DrawingAirbus(int speed, int weight, Color corpusColor, int countWindow, Color addColor, boolean addCompartment, boolean addEngine) { - super(speed, weight, corpusColor, 70, 30); + super(speed, weight, corpusColor, countWindow, 70, 30); Plane = new EntityAirbus(speed, weight, corpusColor, addColor, addCompartment, addEngine); + this.addColor = addColor; } //Второй конструктор @@ -16,6 +19,22 @@ public class DrawingAirbus extends DrawingPlane Plane = plane; } + public void SetAddColor(Color color) + { + var temp = (EntityAirbus) Plane; + Plane = new EntityAirbus(temp.GetSpeed(), temp.GetWeight(), temp.GetColor(), color, + temp.AddCompartment(), temp.AddEngine()); + addColor = color; + } + + @Override + public void SetColor(Color color) + { + var temp = (EntityAirbus) Plane; + addColor = addColor == null ? Color.WHITE : addColor; + Plane = new EntityAirbus(temp.GetSpeed(), temp.GetWeight(), color, addColor, temp.AddCompartment(), temp.AddEngine()); + } + @Override public void DrawTransport(Graphics g) { @@ -35,21 +54,23 @@ public class DrawingAirbus extends DrawingPlane _startPosY -= 5; //дополнительный пассажирский отсек - if (airbus.AddСompartment) + if (airbus.AddCompartment()) { - g2d.setPaint(airbus.AddColor); + g2d.setPaint(airbus.AddColor()); g2d.fillRect((int)_startPosX + 30, (int)_startPosY + 12, 14, 3); g2d.setPaint(Color.BLACK); g2d.drawRect((int)_startPosX + 30, (int)_startPosY + 12, 14, 3); } //дополнительный двигатель - if (airbus.AddEngine) + if (airbus.AddEngine()) { - g2d.setPaint(airbus.AddColor); + g2d.setPaint(airbus.AddColor()); g2d.fillOval((int)_startPosX + 24, (int)_startPosY + 22, 10, 5); g2d.setPaint(Color.BLACK); g2d.drawOval((int)_startPosX + 24, (int)_startPosY + 22, 10, 5); } + + super.repaint(); } } diff --git a/Project/src/DrawingPlane.java b/Project/src/DrawingPlane.java index fe40eed..c3c1822 100644 --- a/Project/src/DrawingPlane.java +++ b/Project/src/DrawingPlane.java @@ -5,42 +5,6 @@ import java.util.Random; public class DrawingPlane extends JPanel { - protected EntityPlane Plane; //класс-сущность - public IAdditionalDrawingObject _airplaneWindow; //для дополнительной отрисовки - - public void SetAddEnum() - { - Random rnd = new Random(); - int numbEnum = rnd.nextInt(1, 4); - _airplaneWindow.SetAddEnum(numbEnum); - } - - public void SetFormEnum() - { - Random rnd = new Random(); - int numbEnum = rnd.nextInt(1, 4); - - if(numbEnum == 1) - { - _airplaneWindow = new DrawingAirplaneWindow(); - } - - if(numbEnum == 2) - { - _airplaneWindow = new DrawingTriangleAirplaneWindow(); - } - - if(numbEnum == 3) - { - _airplaneWindow = new DrawingRectAirplaneWindow(); - } - } - - public EntityPlane GetPlane() - { - return Plane; - } - protected float _startPosX; //левая координата отрисовки protected float _startPosY; //верхняя координата отрисовки private Integer _pictureWidth = null; //ширина окна отрисовки @@ -48,18 +12,52 @@ public class DrawingPlane extends JPanel protected int _airbusWidth = 50; //ширина отрисовки самолёта protected int _airbusHeight = 16; //высота отрисовки самолёта - //конструктор - public DrawingPlane(int speed, float weight, Color corpusColor) + protected EntityPlane Plane; //класс-сущность + public IAdditionalDrawingObject _airplaneWindow; //для дополнительной отрисовки + + public void SetColor(Color color) { - Plane = new EntityPlane(speed, weight, corpusColor); - SetFormEnum(); - SetAddEnum(); + Plane = new EntityPlane(Plane.GetSpeed(), Plane.GetWeight(), color); + } + + public void SetTypeWindow(int countWindow, IAdditionalDrawingObject window) + { + _airplaneWindow = window; + _airplaneWindow.SetAddEnum(countWindow); + } + + public EntityPlane GetPlane() + { + return Plane; } //конструктор - public DrawingPlane(int speed, float weight, Color corpusColor, int planeWidth, int planeHeight) + public DrawingPlane(int speed, float weight, Color corpusColor, int countWindow) { - this(speed, weight, corpusColor); + Random rnd = new Random(); + int randomTypeWindow = rnd.nextInt(3); + Plane = new EntityPlane(speed, weight, corpusColor); + + if(randomTypeWindow == 1) + { + _airplaneWindow = new DrawingAirplaneWindow(); + } + else if(randomTypeWindow == 2) + { + _airplaneWindow = new DrawingRectAirplaneWindow(); + } + else + { + _airplaneWindow = new DrawingTriangleAirplaneWindow(); + } + + _airplaneWindow.SetAddEnum(countWindow); + } + + //конструктор + public DrawingPlane(int speed, float weight, Color corpusColor, int countWindow, int planeWidth, int planeHeight) + { + this(speed, weight, corpusColor, countWindow); _airbusWidth = planeWidth; _airbusHeight = planeHeight; } diff --git a/Project/src/EntityAirbus.java b/Project/src/EntityAirbus.java index 10cfcfe..af6603c 100644 --- a/Project/src/EntityAirbus.java +++ b/Project/src/EntityAirbus.java @@ -3,20 +3,32 @@ import java.awt.*; public class EntityAirbus extends EntityPlane { //Дополнительный цвет - public Color AddColor; + public Color addColor; + public Color AddColor() + { + return addColor; + } //Признак наличия дополнительно пассажирского отсека - public boolean AddСompartment; + public boolean addСompartment; + public boolean AddCompartment() + { + return addСompartment; + } //Признак наличия дополнительных двигателей - public boolean AddEngine; + public boolean addEngine; + public boolean AddEngine() + { + return addEngine; + } //Инициализация свойств public EntityAirbus(int speed, float weight, Color corpusColor, Color addColor, boolean addCompartment, boolean addEngine) { super(speed, weight, corpusColor); - AddColor = addColor; - AddСompartment = addCompartment; - AddEngine = addEngine; + this.addColor = addColor; + this.addСompartment = addCompartment; + this.addEngine = addEngine; } } diff --git a/Project/src/FormMapWithSetPlanesGeneric.java b/Project/src/FormMapWithSetPlanesGeneric.java index cc74529..88b52b3 100644 --- a/Project/src/FormMapWithSetPlanesGeneric.java +++ b/Project/src/FormMapWithSetPlanesGeneric.java @@ -10,7 +10,7 @@ import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.util.HashMap; -public class FormMapWithSetPlanesGeneric { +public class FormMapWithSetPlanesGeneric extends JFrame{ public JPanel MainPanel; private JPanel PictureBoxPlane; private JPanel GroupBoxTools; @@ -44,6 +44,7 @@ public class FormMapWithSetPlanesGeneric { public FormMapWithSetPlanesGeneric() { + super("Хранилище"); CreateWindow(); _mapsCollection = new MapsCollection(730, 650); ComboBoxSelectorMap.removeAllItems(); @@ -186,30 +187,36 @@ public class FormMapWithSetPlanesGeneric { } }); - //добавление самолёта + //добавление самолёта с использованием делегата ButtonAddPlane.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if(ListBoxMaps.getSelectedIndex() == -1) - { - return; - } + FormPlaneConfig form = new FormPlaneConfig(); - FormPlane form = new FormPlane(); - form.setSize(700,400); + form.AddEvent(newPlane ->{ + if(ListBoxMaps.getSelectedIndex() == -1) + { + return; + } + + if(newPlane != null) + { + DrawningObjectPlane plane = new DrawningObjectPlane(newPlane); + + if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Add(plane) != -1) + { + JOptionPane.showMessageDialog(null, "Объект добавлен"); + UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet()); + } + else + { + JOptionPane.showMessageDialog(null, "Не удалось добавить объект"); + } + } + }); + + form.setSize(975, 360); form.setVisible(true); - form.setModal(true); - DrawningObjectPlane plane = new DrawningObjectPlane(form.GetSelectedShip()); - - if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Add(plane) != -1) - { - JOptionPane.showMessageDialog(null,"Объект добавлен"); - UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet()); - } - else - { - JOptionPane.showMessageDialog(null,"Не удалось добавить объект"); - } } }); @@ -359,7 +366,8 @@ public class FormMapWithSetPlanesGeneric { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); - if ((c < '0') || (c > '9')) { + if ((c < '0') || (c > '9')) + { e.consume(); } } diff --git a/Project/src/FormPlane.java b/Project/src/FormPlane.java index dabac37..5700e0a 100644 --- a/Project/src/FormPlane.java +++ b/Project/src/FormPlane.java @@ -134,7 +134,7 @@ public class FormPlane extends JDialog Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null); _plane = new DrawingPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), - colorSimple); + colorSimple, rnd.nextInt(3)); SetData(); @@ -156,7 +156,7 @@ public class FormPlane extends JDialog Color colorModif = JColorChooser.showDialog(null, "Выберите цвет", null); _plane = new DrawingAirbus(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), - colorSimple, colorModif, rnd.nextBoolean(), rnd.nextBoolean()); + colorSimple, rnd.nextInt(3), colorModif, rnd.nextBoolean(), rnd.nextBoolean()); SetData(); diff --git a/Project/src/FormPlaneConfig.form b/Project/src/FormPlaneConfig.form new file mode 100644 index 0000000..e0549e8 --- /dev/null +++ b/Project/src/FormPlaneConfig.form @@ -0,0 +1,417 @@ + +
diff --git a/Project/src/FormPlaneConfig.java b/Project/src/FormPlaneConfig.java new file mode 100644 index 0000000..6a6cce7 --- /dev/null +++ b/Project/src/FormPlaneConfig.java @@ -0,0 +1,311 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.awt.image.BufferedImage; +import java.util.function.Consumer; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.function.Consumer; + +public class FormPlaneConfig extends JFrame{ + private JButton ButtonAddObject; + private JButton ButtonCancel; + private JPanel GroupBoxConfig; + private JPanel PanelObject; + private JPanel GroupBoxColors; + private JPanel PanelRed; + private JPanel PanelGreen; + private JPanel PanelBlue; + private JPanel PanelYellow; + private JPanel PanelPurple; + private JPanel PanelBlack; + private JPanel PanelGray; + private JPanel PanelWhite; + private JLabel LabelSimpleObject; + private JLabel LabelModifiedObject; + private JLabel LabelBaseColor; + private JLabel LabelAddColor; + private JLabel LabelSpeed; + private JLabel LabelWeight; + private JSpinner NumericUpDownWeight; + private JSpinner NumericUpDownSpeed; + private JCheckBox CheckBoxAddСompartment; + private JCheckBox CheckBoxAddEngine; + private JPanel GroupBoxSelectPlaneWindow; + private JPanel GroubBoxSelectedCountWindow; + private JSpinner NumericUpDownCountWindow; + private JPanel MainPanel; + private JLabel LabelSimpleWindow; + private JLabel LabelRectWindow; + private JLabel LabelTriangleWindow; + private JPanel PictureBoxPlane; + + //переменная-выбранный самолёт + DrawingPlane _plane; + + //событие + Consumer