Начало 5-й лабораторной.
This commit is contained in:
parent
afd1982969
commit
e520452540
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -186,20 +186,21 @@ public class FormMapWithSetPlanesGeneric {
|
||||
}
|
||||
});
|
||||
|
||||
//добавление самолёта
|
||||
//добавление самолёта с использованием делегата
|
||||
ButtonAddPlane.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FormPlaneConfig form = new FormPlaneConfig();
|
||||
|
||||
form.AddEvent(newPlane ->{
|
||||
if(ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormPlane form = new FormPlane();
|
||||
form.setSize(700,400);
|
||||
form.setVisible(true);
|
||||
form.setModal(true);
|
||||
DrawningObjectPlane plane = new DrawningObjectPlane(form.GetSelectedShip());
|
||||
if(newPlane != null)
|
||||
{
|
||||
DrawningObjectPlane plane = new DrawningObjectPlane(newPlane);
|
||||
|
||||
if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Add(plane) != -1)
|
||||
{
|
||||
@ -212,6 +213,10 @@ public class FormMapWithSetPlanesGeneric {
|
||||
}
|
||||
}
|
||||
});
|
||||
form.setSize(975, 360);
|
||||
form.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
//удаление самолёта
|
||||
ButtonRemovePlane.addActionListener(new ActionListener() {
|
||||
|
@ -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();
|
||||
|
||||
|
419
Project/src/FormPlaneConfig.form
Normal file
419
Project/src/FormPlaneConfig.form
Normal file
@ -0,0 +1,419 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormPlaneConfig">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="1067" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="f1a57" binding="GroupBoxConfig" layout-manager="GridLayoutManager" row-count="6" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none" title="Параметры"/>
|
||||
<children>
|
||||
<component id="dfd45" class="javax.swing.JLabel" binding="LabelModifiedObject">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="115" height="60"/>
|
||||
<preferred-size width="115" height="60"/>
|
||||
<maximum-size width="115" height="60"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Продвинутый"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f8990" class="javax.swing.JLabel" binding="LabelSimpleObject">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="115" height="60"/>
|
||||
<preferred-size width="115" height="60"/>
|
||||
<maximum-size width="115" height="60"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<text value="Простой"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="292bd" binding="GroupBoxColors" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="2" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none" title="Цвета"/>
|
||||
<children>
|
||||
<grid id="552b0" binding="PanelRed" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-65536"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="2be20" binding="PanelWhite" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="3404" binding="PanelGreen" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16711936"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="2bbb8" binding="PanelGray" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-8355712"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="15e6" binding="PanelBlue" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16776961"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="ebb95" binding="PanelBlack" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16777216"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="15b" binding="PanelYellow" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-256"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="23b87" binding="PanelPurple" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
<preferred-size width="40" height="40"/>
|
||||
<maximum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-8388480"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="d05e5" class="javax.swing.JLabel" binding="LabelSpeed">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Скорость:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b735d" class="javax.swing.JLabel" binding="LabelWeight">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Вес:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="76e8b" class="javax.swing.JSpinner" binding="NumericUpDownWeight">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="100" height="30"/>
|
||||
<preferred-size width="100" height="30"/>
|
||||
<maximum-size width="100" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="edff1" class="javax.swing.JSpinner" binding="NumericUpDownSpeed">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="100" height="30"/>
|
||||
<preferred-size width="100" height="30"/>
|
||||
<maximum-size width="100" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="68d82" class="javax.swing.JCheckBox" binding="CheckBoxAddСompartment">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Признак наличия дополнительного пассажирского отсека"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="70231" class="javax.swing.JCheckBox" binding="CheckBoxAddEngine">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Признак наличия дополнительного двигателя"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="26bf3" binding="GroubBoxSelectedCountWindow" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none" title="Количество иллюминаторов"/>
|
||||
<children>
|
||||
<component id="ba7f5" class="javax.swing.JSpinner" binding="NumericUpDownCountWindow">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<hspacer id="1d23b">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<hspacer id="3e617">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<hspacer id="5f58d">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="5692c" binding="GroupBoxSelectPlaneWindow" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none" title="Выбор формы иллюминаторов"/>
|
||||
<children>
|
||||
<component id="df250" class="javax.swing.JLabel" binding="LabelSimpleWindow">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Простая"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d29b7" class="javax.swing.JLabel" binding="LabelRectWindow">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Квадратная"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="739f2" class="javax.swing.JLabel" binding="LabelTriangleWindow">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Треугольная"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="4ef93" binding="PanelObject" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="dc389" class="javax.swing.JLabel" binding="LabelBaseColor">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="120" height="40"/>
|
||||
<preferred-size width="120" height="40"/>
|
||||
<maximum-size width="120" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Цвет"/>
|
||||
<verticalAlignment value="0"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d04af" class="javax.swing.JLabel" binding="LabelAddColor">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="120" height="40"/>
|
||||
<preferred-size width="120" height="40"/>
|
||||
<maximum-size width="120" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Доп. цвет"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="db00" binding="PictureBoxObject" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="da776" class="javax.swing.JLabel" binding="LabelTypeWindow">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Форма"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="d1cce" class="javax.swing.JButton" binding="ButtonAddObject">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="120" height="40"/>
|
||||
<preferred-size width="120" height="40"/>
|
||||
<maximum-size width="120" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Добавить"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1a616" class="javax.swing.JButton" binding="ButtonCancel">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="120" height="40"/>
|
||||
<preferred-size width="120" height="40"/>
|
||||
<maximum-size width="120" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Отмена"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="b4118">
|
||||
<constraints>
|
||||
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="10"/>
|
||||
<preferred-size width="-1" height="10"/>
|
||||
<maximum-size width="-1" height="10"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<vspacer id="e1b61">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="10"/>
|
||||
<preferred-size width="-1" height="10"/>
|
||||
<maximum-size width="-1" height="10"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<hspacer id="296b8">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="5" height="-1"/>
|
||||
<preferred-size width="5" height="-1"/>
|
||||
<maximum-size width="5" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<buttonGroups>
|
||||
<group name="ButtonGroup1">
|
||||
<member id="3c6c4"/>
|
||||
<member id="8a8c0"/>
|
||||
<member id="abb84"/>
|
||||
</group>
|
||||
</buttonGroups>
|
||||
</form>
|
237
Project/src/FormPlaneConfig.java
Normal file
237
Project/src/FormPlaneConfig.java
Normal file
@ -0,0 +1,237 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.beans.Expression;
|
||||
import java.rmi.server.ExportException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FormPlaneConfig extends JDialog{
|
||||
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 JPanel PictureBoxObject;
|
||||
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 LabelTypeWindow;
|
||||
private JLabel LabelSimpleWindow;
|
||||
private JLabel LabelRectWindow;
|
||||
private JLabel LabelTriangleWindow;
|
||||
|
||||
//переменная-выбранный самолёт
|
||||
DrawingPlane _plane;
|
||||
|
||||
//событие
|
||||
Consumer<DrawingPlane> EventAddPlane;
|
||||
|
||||
public void AddEvent(Consumer<DrawingPlane> ev){
|
||||
EventAddPlane = ev;
|
||||
}
|
||||
|
||||
//конструктор
|
||||
public FormPlaneConfig()
|
||||
{
|
||||
super(new Frame("Аэробус"));
|
||||
CreateWindow();
|
||||
setModal(true);
|
||||
getContentPane().add(MainPanel);
|
||||
}
|
||||
|
||||
public void Draw(DrawingPlane _plane)
|
||||
{
|
||||
PictureBoxObject.removeAll();
|
||||
BufferedImage bmp = new BufferedImage(250, 200, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
|
||||
gr.setColor(new Color(238, 238, 238));
|
||||
gr.fillRect(0, 0, 250, 200);
|
||||
|
||||
if (_plane.GetPlane() != null) {
|
||||
_plane.DrawTransport(gr);
|
||||
JLabel imageOfLogo = new JLabel();
|
||||
imageOfLogo.setPreferredSize(PictureBoxObject.getSize());
|
||||
imageOfLogo.setMinimumSize(new Dimension(1, 1));
|
||||
imageOfLogo.setIcon(new ImageIcon(bmp));
|
||||
PictureBoxObject.add(imageOfLogo, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
validate();
|
||||
}
|
||||
|
||||
public void CreateWindow()
|
||||
{
|
||||
setPreferredSize(new Dimension(1000, 700));
|
||||
getContentPane().add(MainPanel);
|
||||
|
||||
//рамки у Label
|
||||
LabelAddColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelTypeWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelBaseColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelModifiedObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelSimpleObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelSimpleWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelRectWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelTriangleWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
|
||||
//настройка значений у NumericUpDown
|
||||
NumericUpDownSpeed.setModel(new SpinnerNumberModel(1000, 1000, 3000, 1));
|
||||
NumericUpDownWeight.setModel(new SpinnerNumberModel(750, 100, 1500, 1));
|
||||
NumericUpDownCountWindow.setModel(new SpinnerNumberModel(1, 1, 3, 1));
|
||||
|
||||
MouseAdapter drag = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
Drop((JComponent) e.getSource());
|
||||
}
|
||||
};
|
||||
|
||||
MouseAdapter defCursor = new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
};
|
||||
|
||||
//настройки курсоров
|
||||
PictureBoxObject.addMouseListener(defCursor);
|
||||
LabelBaseColor.addMouseListener(defCursor);
|
||||
LabelAddColor.addMouseListener(defCursor);
|
||||
LabelTypeWindow.addMouseListener(defCursor);
|
||||
|
||||
PanelBlack.addMouseListener(drag);
|
||||
PanelPurple.addMouseListener(drag);
|
||||
PanelGray.addMouseListener(drag);
|
||||
PanelGreen.addMouseListener(drag);
|
||||
PanelRed.addMouseListener(drag);
|
||||
PanelWhite.addMouseListener(drag);
|
||||
PanelYellow.addMouseListener(drag);
|
||||
PanelBlue.addMouseListener(drag);
|
||||
|
||||
LabelSimpleObject.addMouseListener(drag);
|
||||
LabelModifiedObject.addMouseListener(drag);
|
||||
LabelSimpleWindow.addMouseListener(drag);
|
||||
LabelRectWindow.addMouseListener(drag);
|
||||
LabelTriangleWindow.addMouseListener(drag);
|
||||
|
||||
ButtonAddObject.addActionListener(e -> {
|
||||
EventAddPlane.accept(_plane);
|
||||
dispose();
|
||||
});
|
||||
|
||||
ButtonCancel.addActionListener(e -> dispose());
|
||||
}
|
||||
|
||||
public void Drop(JComponent dropItem)
|
||||
{
|
||||
if(dropItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(dropItem instanceof JPanel panel)
|
||||
{
|
||||
if(_plane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(LabelBaseColor.getMousePosition() != null)
|
||||
{
|
||||
_plane.SetColor(panel.getBackground());
|
||||
Draw(_plane);
|
||||
}
|
||||
|
||||
if(LabelAddColor.getMousePosition() != null && _plane instanceof DrawingAirbus airbus)
|
||||
{
|
||||
airbus.SetAddColor(panel.getBackground());
|
||||
Draw(_plane);
|
||||
}
|
||||
}
|
||||
|
||||
if(dropItem instanceof JLabel label && PictureBoxObject.getMousePosition() != null)
|
||||
{
|
||||
int speed = (int)NumericUpDownSpeed.getValue();
|
||||
int weight = (int)NumericUpDownWeight.getValue();
|
||||
int countWindow = (int)NumericUpDownCountWindow.getValue();
|
||||
boolean addCompartment = CheckBoxAddСompartment.isSelected();
|
||||
boolean addEngine = CheckBoxAddEngine.isSelected();
|
||||
|
||||
if(label == LabelSimpleObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
PictureBoxObject.remove(_plane);
|
||||
_plane = new DrawingPlane(speed, weight, Color.WHITE, countWindow);
|
||||
Draw(_plane);
|
||||
}
|
||||
catch(Exception ex) { }
|
||||
}
|
||||
else if(label == LabelModifiedObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
PictureBoxObject.remove(_plane);
|
||||
_plane = new DrawingAirbus(speed, weight, Color.WHITE, countWindow, Color.WHITE, addCompartment, addEngine);
|
||||
Draw(_plane);
|
||||
}
|
||||
catch (Exception ex) { };
|
||||
}
|
||||
|
||||
if(_plane != null)
|
||||
{
|
||||
_plane.SetPosition(PictureBoxObject.getWidth() - 200, PictureBoxObject.getHeight() - 150, PictureBoxObject.getWidth(), PictureBoxObject.getHeight());
|
||||
PictureBoxObject.add(_plane, BorderLayout.CENTER);
|
||||
Draw(_plane);
|
||||
}
|
||||
}
|
||||
else if(dropItem instanceof JLabel label && LabelTypeWindow.getMousePosition() != null && _plane != null)
|
||||
{
|
||||
if(label == LabelSimpleWindow)
|
||||
{
|
||||
_plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingAirplaneWindow());
|
||||
Draw(_plane);
|
||||
}
|
||||
|
||||
if(label == LabelRectWindow)
|
||||
{
|
||||
_plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingRectAirplaneWindow());
|
||||
Draw(_plane);
|
||||
}
|
||||
|
||||
if(label == LabelTriangleWindow)
|
||||
{
|
||||
_plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingTriangleAirplaneWindow());
|
||||
Draw(_plane);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user