Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
179f3ecb14 | |||
55364bb619 | |||
5d93c8bf38 | |||
80a4d1c7d7 | |||
e520452540 | |||
afd1982969 | |||
a8492395c5 | |||
f1c8991ad8 | |||
a881f5389e | |||
59ad3e8c05 | |||
194f28b701 | |||
d16579ac96 | |||
b1aa92cbec | |||
a58a16db28 | |||
01fa5bb153 | |||
c70f578cd4 | |||
df30a7abc5 | |||
612001e1db | |||
faae3cf525 | |||
f96d26add6 | |||
bf37aa4f29 | |||
3288b08c04 | |||
72d14716e7 | |||
dfe3807645 | |||
3ab8e81bd9 | |||
8320f6de72 | |||
186c08abd8 | |||
e4aca29884 | |||
fb505d1628 | |||
3818ea591b | |||
571b302e4b | |||
6474259b5f | |||
02db6481fc | |||
98cf530e89 | |||
08ea99c93e | |||
5adccc16a3 | |||
90ceb3ed94 | |||
6bdd753c33 |
@ -2,7 +2,9 @@
|
|||||||
<module type="JAVA_MODULE" version="4">
|
<module type="JAVA_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -14,18 +14,18 @@
|
|||||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
</item>
|
</item>
|
||||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
|
||||||
<initial-values>
|
|
||||||
<property name="text" value="RadioButton" />
|
|
||||||
</initial-values>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
<initial-values>
|
<initial-values>
|
||||||
<property name="text" value="Button" />
|
<property name="text" value="Button" />
|
||||||
</initial-values>
|
</initial-values>
|
||||||
</item>
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
<initial-values>
|
<initial-values>
|
||||||
|
3
Project/src/.idea/.gitignore
vendored
Normal file
3
Project/src/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
6
Project/src/.idea/misc.xml
Normal file
6
Project/src/.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
Project/src/.idea/modules.xml
Normal file
8
Project/src/.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/Project.iml" filepath="$PROJECT_DIR$/Project.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
Project/src/.idea/vcs.xml
Normal file
6
Project/src/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -1,49 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ChangeListManager">
|
|
||||||
<list default="true" id="5ae821da-b40c-40e0-b119-6eb7c1c5f4cc" name="Changes" comment="">
|
|
||||||
<change beforePath="$PROJECT_DIR$/../../.idea/Hard.iml" beforeDir="false" afterPath="$PROJECT_DIR$/../../.idea/Hard.iml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/../../.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../.idea/misc.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/../.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../.idea/misc.xml" afterDir="false" />
|
|
||||||
</list>
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
||||||
</component>
|
|
||||||
<component name="FileTemplateManagerImpl">
|
|
||||||
<option name="RECENT_TEMPLATES">
|
|
||||||
<list>
|
|
||||||
<option value="Class" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="Git.Settings">
|
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
|
|
||||||
</component>
|
|
||||||
<component name="MarkdownSettingsMigration">
|
|
||||||
<option name="stateVersion" value="1" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectId" id="2H35pnpNG1e0131fjsCOoqYsTJr" />
|
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
|
||||||
<component name="ProjectViewState">
|
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
|
||||||
<option name="showLibraryContents" value="true" />
|
|
||||||
</component>
|
|
||||||
<component name="PropertiesComponent">
|
|
||||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
|
||||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
|
||||||
<property name="last_opened_file_path" value="$PROJECT_DIR$/.." />
|
|
||||||
</component>
|
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
||||||
<component name="TaskManager">
|
|
||||||
<task active="true" id="Default" summary="Default task">
|
|
||||||
<changelist id="5ae821da-b40c-40e0-b119-6eb7c1c5f4cc" name="Changes" comment="" />
|
|
||||||
<created>1667501112705</created>
|
|
||||||
<option name="number" value="Default" />
|
|
||||||
<option name="presentableId" value="Default" />
|
|
||||||
<updated>1667501112705</updated>
|
|
||||||
</task>
|
|
||||||
<servers />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
187
Project/src/AbstractMap.java
Normal file
187
Project/src/AbstractMap.java
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public abstract class AbstractMap
|
||||||
|
{
|
||||||
|
private IDrawningObject _drawingObject = null;
|
||||||
|
protected int[][] _map = null;
|
||||||
|
protected int _width;
|
||||||
|
protected int _height;
|
||||||
|
protected float _size_x;
|
||||||
|
protected float _size_y;
|
||||||
|
protected Random _random = new Random();
|
||||||
|
protected int _freeRoad = 0;
|
||||||
|
protected int _barrier = 1;
|
||||||
|
|
||||||
|
public BufferedImage CreateMap(int width, int height, IDrawningObject drawningObject)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawingObject = drawningObject;
|
||||||
|
|
||||||
|
GenerateMap();
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
//проверка на "накладывание"
|
||||||
|
protected boolean CheckPosition(float Left, float Right, float Top, float Bottom)
|
||||||
|
{
|
||||||
|
int x_start = (int)(Left / _size_x);
|
||||||
|
int y_start = (int)(Right / _size_y);
|
||||||
|
int x_end = (int)(Top / _size_x);
|
||||||
|
int y_end = (int)(Bottom / _size_y);
|
||||||
|
|
||||||
|
for(int i = x_start; i <= x_end; i++)
|
||||||
|
{
|
||||||
|
for(int j = y_start; j <= y_end; j++)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
float[] cortege = _drawingObject.GetCurrentPosition();
|
||||||
|
int leftCell = (int)(cortege[0] / _size_x);
|
||||||
|
int upCell = (int)(cortege[1] / _size_y);
|
||||||
|
int downCell = (int)(cortege[3] / _size_y);
|
||||||
|
int rightCell = (int)(cortege[2] / _size_x);
|
||||||
|
int step = (int)_drawingObject.Step();
|
||||||
|
boolean canMove = true;
|
||||||
|
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Left:
|
||||||
|
for (int i = leftCell - (int)(step / _size_x) - 1 >= 0 ? leftCell - (int)(step / _size_x) - 1 : leftCell; i < leftCell; i++)
|
||||||
|
{
|
||||||
|
for (int j = upCell; j < downCell; j++)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
canMove = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Up:
|
||||||
|
for (int i = leftCell; i <= rightCell; i++)
|
||||||
|
{
|
||||||
|
for (int j = upCell - (int)(step / _size_x) - 1 >= 0 ? upCell - (int)(step / _size_x) - 1 : downCell - (int)(step / _size_x); j < downCell - (int)(step / _size_x); j++)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
canMove = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Down:
|
||||||
|
for (int i = leftCell; i <= rightCell; i++)
|
||||||
|
{
|
||||||
|
for (int j = downCell + (int)(step / _size_x) + 1 <= _map.length - 1 ? downCell + (int)(step / _size_x) + 1 : upCell; j > upCell; j--)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
canMove = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Right:
|
||||||
|
for (int i = rightCell + (int)(step / _size_x) + 1 <= _map.length - 1 ? rightCell + (int)(step / _size_x) + 1 : rightCell; i > rightCell; i--)
|
||||||
|
{
|
||||||
|
for (int j = upCell; j < downCell; j++)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
canMove = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canMove)
|
||||||
|
{
|
||||||
|
_drawingObject.MoveObject(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean SetObjectOnMap()
|
||||||
|
{
|
||||||
|
if(_drawingObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x = _random.nextInt(10);
|
||||||
|
int y = _random.nextInt(10);
|
||||||
|
_drawingObject.SetObject(x, y, _width, _height);
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
if(i * _size_x >= x && j * _size_y >= y &&
|
||||||
|
i * _size_x <= x + _drawingObject.GetCurrentPosition()[1] &&
|
||||||
|
j * _size_y <= j + _drawingObject.GetCurrentPosition()[2])
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BufferedImage DrawMapWithObject()
|
||||||
|
{
|
||||||
|
BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB);
|
||||||
|
|
||||||
|
if(_drawingObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics gr = bmp.getGraphics();
|
||||||
|
|
||||||
|
for(int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < _map[i].length; ++j)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _freeRoad)
|
||||||
|
{
|
||||||
|
DrawRoadPart(gr, i, j);
|
||||||
|
}
|
||||||
|
else if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
DrawBarrierPart(gr, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawingObject.DrawningObject(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void GenerateMap();
|
||||||
|
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||||
|
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||||
|
}
|
@ -10,7 +10,8 @@ public enum Additional_Enum {
|
|||||||
this.addEnum = i;
|
this.addEnum = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetAddEnum(){
|
public int GetAddEnum()
|
||||||
|
{
|
||||||
return addEnum;
|
return addEnum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
55
Project/src/DesertStormMap.java
Normal file
55
Project/src/DesertStormMap.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DesertStormMap extends AbstractMap
|
||||||
|
{
|
||||||
|
//цвет закрытого участка
|
||||||
|
private final Color barriedColor = new Color(139, 0, 0);
|
||||||
|
|
||||||
|
//цвет открытого участка
|
||||||
|
private final Color roadColor = new Color(255, 140, 0);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(roadColor);
|
||||||
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(barriedColor);
|
||||||
|
g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
public enum Direction {
|
//направление перемещения
|
||||||
|
public enum Direction
|
||||||
|
{
|
||||||
Up(1),
|
Up(1),
|
||||||
Down(2),
|
Down(2),
|
||||||
Left(3),
|
Left(3),
|
||||||
@ -6,7 +8,7 @@ public enum Direction {
|
|||||||
|
|
||||||
private final int DirectionCode;
|
private final int DirectionCode;
|
||||||
|
|
||||||
private Direction(int directionCode)
|
Direction(int directionCode)
|
||||||
{
|
{
|
||||||
this.DirectionCode = directionCode;
|
this.DirectionCode = directionCode;
|
||||||
}
|
}
|
||||||
|
76
Project/src/DrawingAirbus.java
Normal file
76
Project/src/DrawingAirbus.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingAirbus extends DrawingPlane
|
||||||
|
{
|
||||||
|
private Color addColor;
|
||||||
|
|
||||||
|
//Конструктор
|
||||||
|
public DrawingAirbus(int speed, int weight, Color corpusColor, int countWindow, Color addColor, boolean addCompartment, boolean addEngine)
|
||||||
|
{
|
||||||
|
super(speed, weight, corpusColor, countWindow, 70, 30);
|
||||||
|
Plane = new EntityAirbus(speed, weight, corpusColor, addColor, addCompartment, addEngine);
|
||||||
|
this.addColor = addColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Второй конструктор
|
||||||
|
public DrawingAirbus(EntityPlane plane, IAdditionalDrawingObject addWindows)
|
||||||
|
{
|
||||||
|
super(plane, addWindows);
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
EntityAirbus airbus;
|
||||||
|
|
||||||
|
if (!(GetPlane() instanceof EntityAirbus))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
airbus = (EntityAirbus) Plane;
|
||||||
|
_startPosX += 10;
|
||||||
|
_startPosY += 5;
|
||||||
|
super.DrawTransport(g);
|
||||||
|
_startPosX -= 10;
|
||||||
|
_startPosY -= 5;
|
||||||
|
|
||||||
|
//дополнительный пассажирский отсек
|
||||||
|
if (airbus.AddCompartment())
|
||||||
|
{
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,19 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingAirplaneWindow extends JComponent
|
public class DrawingAirplaneWindow extends JComponent implements IAdditionalDrawingObject
|
||||||
{
|
{
|
||||||
private Additional_Enum _airplaneWindowEnum;
|
private Additional_Enum _airplaneWindowEnum;
|
||||||
|
|
||||||
public void SetAddEnum(int decksAmount) {
|
@Override
|
||||||
|
public void SetAddEnum(int airplaneWindow)
|
||||||
|
{
|
||||||
for(Additional_Enum item : _airplaneWindowEnum.values())
|
for(Additional_Enum item : _airplaneWindowEnum.values())
|
||||||
{
|
{
|
||||||
if(item.GetAddEnum() == decksAmount)
|
if(item.GetAddEnum() == airplaneWindow)
|
||||||
{
|
{
|
||||||
_airplaneWindowEnum = item;
|
_airplaneWindowEnum = item;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -21,35 +24,31 @@ public class DrawingAirplaneWindow extends JComponent
|
|||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
switch(_airplaneWindowEnum.GetAddEnum())
|
if(_airplaneWindowEnum.GetAddEnum() >= 1)
|
||||||
{
|
{
|
||||||
case 1:
|
|
||||||
g2d.setPaint(colorWindow);
|
g2d.setPaint(colorWindow);
|
||||||
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
||||||
|
|
||||||
g2d.setPaint(Color.BLACK);
|
g2d.setPaint(Color.BLACK);
|
||||||
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
||||||
break;
|
}
|
||||||
case 2:
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 2)
|
||||||
|
{
|
||||||
g2d.setPaint(colorWindow);
|
g2d.setPaint(colorWindow);
|
||||||
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
|
||||||
g2d.fillOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
g2d.fillOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
||||||
|
|
||||||
g2d.setPaint(Color.BLACK);
|
g2d.setPaint(Color.BLACK);
|
||||||
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
|
||||||
g2d.drawOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
g2d.drawOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
||||||
break;
|
}
|
||||||
case 3:
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 3)
|
||||||
|
{
|
||||||
g2d.setPaint(colorWindow);
|
g2d.setPaint(colorWindow);
|
||||||
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
|
||||||
g2d.fillOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
|
||||||
g2d.fillOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
g2d.fillOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
||||||
|
|
||||||
g2d.setPaint(Color.BLACK);
|
g2d.setPaint(Color.BLACK);
|
||||||
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
|
||||||
g2d.drawOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
|
||||||
g2d.drawOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
g2d.drawOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
82
Project/src/DrawingEntities.java
Normal file
82
Project/src/DrawingEntities.java
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingEntities <T extends EntityPlane, U extends IAdditionalDrawingObject>
|
||||||
|
{
|
||||||
|
public T[] _arrPlane;
|
||||||
|
public U[] _arrWindow;
|
||||||
|
int countArrPlane = 0;
|
||||||
|
int countArrWindows = 0;
|
||||||
|
String _x_index;
|
||||||
|
String _y_index;
|
||||||
|
|
||||||
|
//конструктор
|
||||||
|
public DrawingEntities(int sizeArr, Class<T> objectT, Class<U> objectU)
|
||||||
|
{
|
||||||
|
final T[] arrPlane = (T[]) Array.newInstance(objectT, sizeArr);
|
||||||
|
_arrPlane = arrPlane;
|
||||||
|
|
||||||
|
final U[] arrWindod = (U[]) Array.newInstance(objectU, sizeArr);
|
||||||
|
_arrWindow = arrWindod;
|
||||||
|
}
|
||||||
|
|
||||||
|
//добавить сущность-самолёт
|
||||||
|
public int Insert(T plane)
|
||||||
|
{
|
||||||
|
if(countArrPlane < _arrPlane.length)
|
||||||
|
{
|
||||||
|
_arrPlane[countArrPlane] = plane;
|
||||||
|
countArrPlane++;
|
||||||
|
|
||||||
|
return countArrPlane - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//добавить кол-во и тип иллюминаторов
|
||||||
|
public int Insert(U addElement)
|
||||||
|
{
|
||||||
|
if(countArrWindows < _arrWindow.length)
|
||||||
|
{
|
||||||
|
_arrWindow[countArrWindows] = addElement;
|
||||||
|
countArrWindows++;
|
||||||
|
|
||||||
|
return countArrWindows - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//фиксирование индексов
|
||||||
|
public void SetIndex(int indexFirst, int indexSecond)
|
||||||
|
{
|
||||||
|
_x_index = Integer.toString(indexFirst);
|
||||||
|
_y_index = Integer.toString(indexSecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingPlane CreatePlane()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
int indexPlane = 0;
|
||||||
|
int indexArrWindow = 0;
|
||||||
|
|
||||||
|
if(countArrPlane - 1 != 0 && countArrWindows - 1 != 0)
|
||||||
|
{
|
||||||
|
indexPlane = rnd.nextInt(0, countArrPlane - 1);
|
||||||
|
indexArrWindow = rnd.nextInt(0, countArrWindows - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
T plane = (T)_arrPlane[indexPlane];
|
||||||
|
U windows = (U)_arrWindow[indexArrWindow];
|
||||||
|
|
||||||
|
SetIndex(indexPlane, indexArrWindow);
|
||||||
|
|
||||||
|
if(plane instanceof EntityAirbus)
|
||||||
|
{
|
||||||
|
return new DrawingAirbus(plane, windows);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DrawingPlane(plane, windows);
|
||||||
|
}
|
||||||
|
}
|
@ -1,40 +1,72 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DrawingPlane
|
public class DrawingPlane extends JPanel
|
||||||
{
|
{
|
||||||
public EntityPlane Airbus; //класс-сущность
|
protected float _startPosX; //левая координата отрисовки
|
||||||
public DrawingAirplaneWindow _airplaneWindow; //для дополнительной отрисовки
|
protected float _startPosY; //верхняя координата отрисовки
|
||||||
|
|
||||||
private float _startPosX; //левая координата отрисовки
|
|
||||||
private float _startPosY; //верхняя координата отрисовки
|
|
||||||
private Integer _pictureWidth = null; //ширина окна отрисовки
|
private Integer _pictureWidth = null; //ширина окна отрисовки
|
||||||
private Integer _pictureHeight = null; //высота окна отрисовки
|
private Integer _pictureHeight = null; //высота окна отрисовки
|
||||||
protected final int _airbusWidth = 50; //ширина отрисовки самолёта
|
protected int _airbusWidth = 50; //ширина отрисовки самолёта
|
||||||
protected final int _airbusHeight = 16; //высота отрисовки самолёта
|
protected int _airbusHeight = 16; //высота отрисовки самолёта
|
||||||
|
|
||||||
//инициализаци свойств
|
protected EntityPlane Plane; //класс-сущность
|
||||||
public void Initial(int speed, float weight, Color corpusColor)
|
public IAdditionalDrawingObject _airplaneWindow; //для дополнительной отрисовки
|
||||||
|
|
||||||
|
public void SetColor(Color color)
|
||||||
{
|
{
|
||||||
Airbus = new EntityPlane();
|
Plane = new EntityPlane(Plane.GetSpeed(), Plane.GetWeight(), color);
|
||||||
Airbus.Initial(speed, weight, corpusColor);
|
|
||||||
_airplaneWindow = new DrawingAirplaneWindow();
|
|
||||||
|
|
||||||
SetAddEnum();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//установка кол-ва иллюминаторов
|
public void SetTypeWindow(int countWindow, IAdditionalDrawingObject window)
|
||||||
public void SetAddEnum()
|
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
_airplaneWindow = window;
|
||||||
int countWindow = rnd.nextInt(1, 4);
|
|
||||||
_airplaneWindow.SetAddEnum(countWindow);
|
_airplaneWindow.SetAddEnum(countWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityPlane GetPlane()
|
public EntityPlane GetPlane()
|
||||||
{
|
{
|
||||||
return Airbus;
|
return Plane;
|
||||||
|
}
|
||||||
|
|
||||||
|
//конструктор
|
||||||
|
public DrawingPlane(int speed, float weight, Color corpusColor, int countWindow)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//второй конструктор
|
||||||
|
public DrawingPlane(EntityPlane plane, IAdditionalDrawingObject countWindow)
|
||||||
|
{
|
||||||
|
Plane = plane;
|
||||||
|
_airplaneWindow = countWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
//установка координат позиции самолёта
|
//установка координат позиции самолёта
|
||||||
@ -65,30 +97,30 @@ public class DrawingPlane
|
|||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
case Right: //вправо
|
case Right: //вправо
|
||||||
if (_startPosX + _airbusWidth + Airbus.GetStep() < _pictureWidth)
|
if (_startPosX + _airbusWidth + Plane.GetStep() < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += Airbus.GetStep();
|
_startPosX += Plane.GetStep();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Left: //влево
|
case Left: //влево
|
||||||
if (_startPosX - _airbusWidth - Airbus.GetStep() > 0)
|
if (_startPosX - _airbusWidth - Plane.GetStep() > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= Airbus.GetStep();
|
_startPosX -= Plane.GetStep();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Up: //вверх
|
case Up: //вверх
|
||||||
if (_startPosY - _airbusHeight - Airbus.GetStep() > 0)
|
if (_startPosY - _airbusHeight - Plane.GetStep() > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= Airbus.GetStep();
|
_startPosY -= Plane.GetStep();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Down: //вниз
|
case Down: //вниз
|
||||||
if (_startPosY + _airbusHeight + Airbus.GetStep() < _pictureHeight)
|
if (_startPosY + _airbusHeight + Plane.GetStep() < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += Airbus.GetStep();
|
_startPosY += Plane.GetStep();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -107,19 +139,15 @@ public class DrawingPlane
|
|||||||
|
|
||||||
Graphics2D g2d = (Graphics2D)g;
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
|
||||||
g2d.setColor(Color.WHITE);
|
//заливка корпуса
|
||||||
g2d.fillRect(0, 0, _pictureWidth, _pictureHeight);
|
g2d.setColor(Plane.GetColor());
|
||||||
|
g2d.fillRect((int)_startPosX, (int)_startPosY + 10, 40, 10);
|
||||||
//заливает фигуру
|
|
||||||
g2d.setPaint(Color.BLACK);
|
|
||||||
|
|
||||||
//крыло
|
//крыло
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
g2d.fillRect((int)_startPosX + 10, (int)_startPosY + 15, 20, 2);
|
g2d.fillRect((int)_startPosX + 10, (int)_startPosY + 15, 20, 2);
|
||||||
g2d.fillRect((int)_startPosX + 12, (int)_startPosY + 17, 16, 2);
|
g2d.fillRect((int)_startPosX + 12, (int)_startPosY + 17, 16, 2);
|
||||||
|
|
||||||
//заднее поперечное крыло
|
|
||||||
g2d.fillOval((int)_startPosX - 3, (int)_startPosY + 7, 10, 5);
|
|
||||||
|
|
||||||
//задние шасси
|
//задние шасси
|
||||||
g2d.fillRect((int)_startPosX + 10, (int)_startPosY + 21, 2, 2);
|
g2d.fillRect((int)_startPosX + 10, (int)_startPosY + 21, 2, 2);
|
||||||
g2d.fillRect((int)_startPosX + 12, (int)_startPosY + 23, 4, 4);
|
g2d.fillRect((int)_startPosX + 12, (int)_startPosY + 23, 4, 4);
|
||||||
@ -129,21 +157,39 @@ public class DrawingPlane
|
|||||||
g2d.fillRect((int)_startPosX + 35, (int)_startPosY + 21, 2, 2);
|
g2d.fillRect((int)_startPosX + 35, (int)_startPosY + 21, 2, 2);
|
||||||
g2d.fillRect((int)_startPosX + 35, (int)_startPosY + 23, 4, 4);
|
g2d.fillRect((int)_startPosX + 35, (int)_startPosY + 23, 4, 4);
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK); //рисует контур
|
//заливка хвостового крыла
|
||||||
//корпус
|
g2d.setColor(Plane.GetColor());
|
||||||
g2d.drawRect((int)_startPosX, (int)_startPosY + 10, 40, 10);
|
int[] xCoordFirst = {(int)_startPosX, (int)_startPosX, (int)_startPosX + 10};
|
||||||
|
int[] yCoordFirst = {(int)_startPosY + 10, (int)_startPosY, (int)_startPosY + 10};
|
||||||
|
g2d.fillPolygon(xCoordFirst, yCoordFirst, xCoordFirst.length);
|
||||||
|
|
||||||
//хвостовое крыло
|
//заливка носа самолёта
|
||||||
|
int[] xCoordSecond = {(int)_startPosX + 40, (int)_startPosX + 47, (int)_startPosX + 40};
|
||||||
|
int[] yCoordSecond = {(int)_startPosY + 15, (int)_startPosY + 15, (int)_startPosY + 10};
|
||||||
|
g2d.fillPolygon(xCoordSecond, yCoordSecond, xCoordSecond.length);
|
||||||
|
|
||||||
|
int[] xCoordThird = {(int)_startPosX + 40, (int)_startPosX + 50, (int)_startPosX + 40};
|
||||||
|
int[] yCoordThird = {(int)_startPosY + 15, (int)_startPosY + 15, (int)_startPosY + 20};
|
||||||
|
g2d.fillPolygon(xCoordThird, yCoordThird, xCoordThird.length);
|
||||||
|
|
||||||
|
//контур хвостового крыла
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
g2d.drawLine((int)_startPosX, (int)_startPosY + 10, (int)_startPosX, (int)_startPosY);
|
g2d.drawLine((int)_startPosX, (int)_startPosY + 10, (int)_startPosX, (int)_startPosY);
|
||||||
g2d.drawLine((int)_startPosX, (int)_startPosY, (int)_startPosX + 10, (int)_startPosY + 10);
|
g2d.drawLine((int)_startPosX, (int)_startPosY, (int)_startPosX + 10, (int)_startPosY + 10);
|
||||||
|
|
||||||
//нос самолёта
|
//отрисовка контура самолёта
|
||||||
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 15, (int)_startPosX + 50, (int)_startPosY + 16);
|
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 15, (int)_startPosX + 50, (int)_startPosY + 15);
|
||||||
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 10, (int)_startPosX + 47, (int)_startPosY + 15);
|
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 10, (int)_startPosX + 47, (int)_startPosY + 15);
|
||||||
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 20, (int)_startPosX + 50, (int)_startPosY + 15);
|
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 20, (int)_startPosX + 50, (int)_startPosY + 15);
|
||||||
|
|
||||||
|
//контур корпуса
|
||||||
|
g2d.drawRect((int)_startPosX, (int)_startPosY + 10, 40, 10);
|
||||||
|
|
||||||
|
//заднее поперечное крыло
|
||||||
|
g2d.fillOval((int)_startPosX - 3, (int)_startPosY + 7, 10, 5);
|
||||||
|
|
||||||
//отрисовка иллюминаторов
|
//отрисовка иллюминаторов
|
||||||
_airplaneWindow.DrawAirplaneWindow(Airbus.GetColor(), g, _startPosX, _startPosY);
|
_airplaneWindow.DrawAirplaneWindow(Plane.GetColor(), g, _startPosX, _startPosY);
|
||||||
}
|
}
|
||||||
|
|
||||||
//смена границ формы отрисовки
|
//смена границ формы отрисовки
|
||||||
@ -169,4 +215,9 @@ public class DrawingPlane
|
|||||||
_startPosY = _pictureHeight - _airbusHeight;
|
_startPosY = _pictureHeight - _airbusHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float[] GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return new float[]{_startPosX, _startPosY, _startPosX + _airbusWidth, _startPosY + _airbusHeight};
|
||||||
|
}
|
||||||
}
|
}
|
54
Project/src/DrawingRectAirplaneWindow.java
Normal file
54
Project/src/DrawingRectAirplaneWindow.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingRectAirplaneWindow extends JComponent implements IAdditionalDrawingObject
|
||||||
|
{
|
||||||
|
private Additional_Enum _airplaneWindowEnum;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetAddEnum(int airplaneWindow)
|
||||||
|
{
|
||||||
|
for(Additional_Enum item : _airplaneWindowEnum.values())
|
||||||
|
{
|
||||||
|
if(item.GetAddEnum() == airplaneWindow)
|
||||||
|
{
|
||||||
|
_airplaneWindowEnum = item;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawAirplaneWindow(Color colorWindow, Graphics g, float _startPosX, float _startPosY)
|
||||||
|
{
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 1)
|
||||||
|
{
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillRect((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawRect((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 2)
|
||||||
|
{
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillRect((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawRect((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 3)
|
||||||
|
{
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillRect((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawRect((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
Project/src/DrawingTriangleAirplaneWindow.java
Normal file
63
Project/src/DrawingTriangleAirplaneWindow.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingTriangleAirplaneWindow extends JComponent implements IAdditionalDrawingObject
|
||||||
|
{
|
||||||
|
private Additional_Enum _airplaneWindowEnum;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetAddEnum(int airplaneWindow)
|
||||||
|
{
|
||||||
|
for(Additional_Enum item : _airplaneWindowEnum.values())
|
||||||
|
{
|
||||||
|
if(item.GetAddEnum() == airplaneWindow)
|
||||||
|
{
|
||||||
|
_airplaneWindowEnum = item;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawAirplaneWindow(Color colorWindow, Graphics g, float _startPosX, float _startPosY)
|
||||||
|
{
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 1)
|
||||||
|
{
|
||||||
|
int[] x_point = {(int)_startPosX + 12, (int)_startPosX + 16, (int)_startPosX + 9};
|
||||||
|
int[] y_point = {(int)_startPosY + 11, (int)_startPosY + 15, (int)_startPosY + 15};
|
||||||
|
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillPolygon(x_point, y_point, 3);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawPolygon(x_point, y_point, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 2)
|
||||||
|
{
|
||||||
|
int[] x_point = {(int)_startPosX + 21, (int)_startPosX + 25, (int)_startPosX + 18};
|
||||||
|
int[] y_point = {(int)_startPosY + 11, (int)_startPosY + 15, (int)_startPosY + 15};
|
||||||
|
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillPolygon(x_point, y_point, 3);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawPolygon(x_point, y_point, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 3)
|
||||||
|
{
|
||||||
|
int[] x_point = {(int)_startPosX + 30, (int)_startPosX + 34, (int)_startPosX + 27};
|
||||||
|
int[] y_point = {(int)_startPosY + 11, (int)_startPosY + 15, (int)_startPosY + 15};
|
||||||
|
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillPolygon(x_point, y_point, 3);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawPolygon(x_point, y_point, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
Project/src/DrawningObjectPlane.java
Normal file
53
Project/src/DrawningObjectPlane.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningObjectPlane implements IDrawningObject
|
||||||
|
{
|
||||||
|
private DrawingPlane _plane = null;
|
||||||
|
|
||||||
|
public DrawingPlane GetDrawingObjectPlane()
|
||||||
|
{
|
||||||
|
return _plane;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawningObjectPlane(DrawingPlane plane){ _plane = plane; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float Step()
|
||||||
|
{
|
||||||
|
if(_plane != null && _plane.Plane != null)
|
||||||
|
{
|
||||||
|
return _plane.Plane.GetStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetObject(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_plane.SetPosition(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_plane.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawningObject(Graphics g)
|
||||||
|
{
|
||||||
|
_plane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float[] GetCurrentPosition()
|
||||||
|
{
|
||||||
|
if(_plane != null)
|
||||||
|
{
|
||||||
|
return _plane.GetCurrentPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
34
Project/src/EntityAirbus.java
Normal file
34
Project/src/EntityAirbus.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityAirbus extends EntityPlane
|
||||||
|
{
|
||||||
|
//Дополнительный цвет
|
||||||
|
public Color addColor;
|
||||||
|
public Color AddColor()
|
||||||
|
{
|
||||||
|
return addColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Признак наличия дополнительно пассажирского отсека
|
||||||
|
public boolean addСompartment;
|
||||||
|
public boolean AddCompartment()
|
||||||
|
{
|
||||||
|
return addСompartment;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Признак наличия дополнительных двигателей
|
||||||
|
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);
|
||||||
|
this.addColor = addColor;
|
||||||
|
this.addСompartment = addCompartment;
|
||||||
|
this.addEngine = addEngine;
|
||||||
|
}
|
||||||
|
}
|
@ -2,27 +2,34 @@ import java.awt.*;
|
|||||||
|
|
||||||
public class EntityPlane
|
public class EntityPlane
|
||||||
{
|
{
|
||||||
public int Speed; //скорость
|
//скорость
|
||||||
public int GetSpeed(){
|
public int Speed;
|
||||||
|
public int GetSpeed()
|
||||||
|
{
|
||||||
return Speed;
|
return Speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Weight; //вес
|
//вес
|
||||||
public float GetWeight(){
|
public float Weight;
|
||||||
|
public float GetWeight()
|
||||||
|
{
|
||||||
return Weight;
|
return Weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color CorpusColor; //цвет корпуса
|
//цвет корпуса
|
||||||
public Color GetColor(){
|
public Color CorpusColor;
|
||||||
|
public Color GetColor()
|
||||||
|
{
|
||||||
return CorpusColor;
|
return CorpusColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
//шаг перемещения самолёта
|
//шаг перемещения самолёта
|
||||||
public float GetStep(){
|
public float GetStep()
|
||||||
|
{
|
||||||
return Speed * 100 / Weight;
|
return Speed * 100 / Weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initial(int speed, float weight, Color corpusColor)
|
public EntityPlane(int speed, float weight, Color corpusColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
|
252
Project/src/FormMapWithSetPlanesGeneric.form
Normal file
252
Project/src/FormMapWithSetPlanesGeneric.form
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetPlanesGeneric">
|
||||||
|
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" 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="994" height="654"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="92d87" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="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="730" height="650"/>
|
||||||
|
<preferred-size width="730" height="650"/>
|
||||||
|
<maximum-size width="730" height="650"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="4871f" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="17" 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="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="250" height="650"/>
|
||||||
|
<preferred-size width="250" height="650"/>
|
||||||
|
<maximum-size width="250" height="650"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none" title="Инструменты"/>
|
||||||
|
<children>
|
||||||
|
<component id="d0967" class="javax.swing.JButton" binding="ButtonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="16" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="45" height="45"/>
|
||||||
|
<preferred-size width="45" height="45"/>
|
||||||
|
<maximum-size width="45" height="45"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="d9af3" class="javax.swing.JButton" binding="ButtonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="16" column="1" 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="45" height="45"/>
|
||||||
|
<preferred-size width="45" height="45"/>
|
||||||
|
<maximum-size width="45" height="45"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="9e43" class="javax.swing.JButton" binding="ButtonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="16" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="45" height="45"/>
|
||||||
|
<preferred-size width="45" height="45"/>
|
||||||
|
<maximum-size width="45" height="45"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="4d1dd" class="javax.swing.JButton" binding="ButtonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="15" column="1" 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="45" height="45"/>
|
||||||
|
<preferred-size width="45" height="45"/>
|
||||||
|
<maximum-size width="45" height="45"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="67190" class="javax.swing.JButton" binding="ButtonShowOnMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="13" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="30"/>
|
||||||
|
<preferred-size width="220" height="30"/>
|
||||||
|
<maximum-size width="220" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Посмотреть карту"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="28576" class="javax.swing.JButton" binding="ButtonShowStorage">
|
||||||
|
<constraints>
|
||||||
|
<grid row="11" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="30"/>
|
||||||
|
<preferred-size width="220" height="30"/>
|
||||||
|
<maximum-size width="220" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Посмотреть хранилище"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="7119" class="javax.swing.JButton" binding="ButtonAddPlane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="30"/>
|
||||||
|
<preferred-size width="220" height="30"/>
|
||||||
|
<maximum-size width="220" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Добавить самолёт"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="6f119" class="javax.swing.JTextField" binding="MaskedTextBoxPosition">
|
||||||
|
<constraints>
|
||||||
|
<grid row="7" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="30"/>
|
||||||
|
<preferred-size width="220" height="30"/>
|
||||||
|
<maximum-size width="220" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<columns value="2"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="d75e9" class="javax.swing.JButton" binding="ButtonRemovePlane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="30"/>
|
||||||
|
<preferred-size width="220" height="30"/>
|
||||||
|
<maximum-size width="220" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Удалить самолёт"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<vspacer id="f972a">
|
||||||
|
<constraints>
|
||||||
|
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<vspacer id="65c78">
|
||||||
|
<constraints>
|
||||||
|
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<vspacer id="7d70b">
|
||||||
|
<constraints>
|
||||||
|
<grid row="14" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<vspacer id="d4b8a">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<grid id="fe895" binding="GroupBoxMap" layout-manager="GridLayoutManager" row-count="5" 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="5" col-span="3" 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="7efbe" class="javax.swing.JTextField" binding="TextBoxNewMapName">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="30"/>
|
||||||
|
<preferred-size width="220" height="30"/>
|
||||||
|
<maximum-size width="220" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="1388e" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="30"/>
|
||||||
|
<preferred-size width="220" height="30"/>
|
||||||
|
<maximum-size width="220" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<model>
|
||||||
|
<item value="Простая карта"/>
|
||||||
|
<item value="Буря в пустыне"/>
|
||||||
|
<item value="Звёздные войны"/>
|
||||||
|
</model>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="3b6b1" class="javax.swing.JButton" binding="ButtonAddMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="30"/>
|
||||||
|
<preferred-size width="220" height="30"/>
|
||||||
|
<maximum-size width="220" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Добавить карту"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="9a389" class="javax.swing.JList" binding="ListBoxMaps" custom-create="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="100"/>
|
||||||
|
<preferred-size width="220" height="100"/>
|
||||||
|
<maximum-size width="220" height="100"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<selectionMode value="2"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="81eff" class="javax.swing.JButton" binding="ButtonDeleteMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="30"/>
|
||||||
|
<preferred-size width="220" height="30"/>
|
||||||
|
<maximum-size width="220" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Удалить карту"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<component id="860bc" class="javax.swing.JButton" binding="ButtonShowDelete">
|
||||||
|
<constraints>
|
||||||
|
<grid row="9" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="220" height="30"/>
|
||||||
|
<preferred-size width="220" height="30"/>
|
||||||
|
<maximum-size width="220" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Посмотреть удалённый самолёт"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
382
Project/src/FormMapWithSetPlanesGeneric.java
Normal file
382
Project/src/FormMapWithSetPlanesGeneric.java
Normal file
@ -0,0 +1,382 @@
|
|||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class FormMapWithSetPlanesGeneric extends JFrame{
|
||||||
|
public JPanel MainPanel;
|
||||||
|
private JPanel PictureBoxPlane;
|
||||||
|
private JPanel GroupBoxTools;
|
||||||
|
private JComboBox ComboBoxSelectorMap;
|
||||||
|
private JButton ButtonLeft;
|
||||||
|
private JButton ButtonDown;
|
||||||
|
private JButton ButtonRight;
|
||||||
|
private JButton ButtonUp;
|
||||||
|
private JButton ButtonShowOnMap;
|
||||||
|
private JButton ButtonShowStorage;
|
||||||
|
private JButton ButtonAddPlane;
|
||||||
|
private JTextField MaskedTextBoxPosition;
|
||||||
|
private JButton ButtonRemovePlane;
|
||||||
|
private JTextField TextBoxNewMapName;
|
||||||
|
private JButton ButtonAddMap;
|
||||||
|
private JList ListBoxMaps;
|
||||||
|
private JButton ButtonDeleteMap;
|
||||||
|
private JPanel GroupBoxMap;
|
||||||
|
private JButton ButtonShowDelete;
|
||||||
|
|
||||||
|
//объект от коллекции карт
|
||||||
|
private final MapsCollection _mapsCollection;
|
||||||
|
|
||||||
|
//Для выпадающего списка
|
||||||
|
HashMap<String, AbstractMap> _mapsHashMap = new HashMap<>()
|
||||||
|
{{
|
||||||
|
put("Простая карта", new SimpleMap());
|
||||||
|
put("Буря в пустыне", new DesertStormMap());
|
||||||
|
put("Звёздные войны", new StarWarsMap());
|
||||||
|
}};
|
||||||
|
|
||||||
|
public FormMapWithSetPlanesGeneric()
|
||||||
|
{
|
||||||
|
super("Хранилище");
|
||||||
|
CreateWindow();
|
||||||
|
_mapsCollection = new MapsCollection(730, 650);
|
||||||
|
ComboBoxSelectorMap.removeAllItems();
|
||||||
|
|
||||||
|
for (String elem : _mapsHashMap.keySet())
|
||||||
|
{
|
||||||
|
ComboBoxSelectorMap.addItem(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//заполнение ListBoxMaps
|
||||||
|
private void ReloadMaps()
|
||||||
|
{
|
||||||
|
int index = ListBoxMaps.getSelectedIndex();
|
||||||
|
|
||||||
|
DefaultListModel<String> model = (DefaultListModel<String>)ListBoxMaps.getModel();
|
||||||
|
model.removeAllElements();
|
||||||
|
|
||||||
|
for (int i = 0; i < _mapsCollection.Keys().size(); i++)
|
||||||
|
{
|
||||||
|
model.addElement(_mapsCollection.Keys().get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ListBoxMaps.getModel().getSize() > 0 && (index == -1 || index >= ListBoxMaps.getModel().getSize()))
|
||||||
|
{
|
||||||
|
ListBoxMaps.setSelectedIndex(0);
|
||||||
|
}
|
||||||
|
else if (ListBoxMaps.getModel().getSize() > 0 && index > -1 && index < ListBoxMaps.getModel().getSize())
|
||||||
|
{
|
||||||
|
ListBoxMaps.setSelectedIndex(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//обновление отрисовки
|
||||||
|
public void UpdateWindow(BufferedImage bmp)
|
||||||
|
{
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(bmp));
|
||||||
|
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBoxPlane.revalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateWindow()
|
||||||
|
{
|
||||||
|
//загрузка изображений для кнопок
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Image img = ImageIO.read(getClass().getResource("resourses/Up.png"));
|
||||||
|
ButtonUp.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(getClass().getResource("resourses/Left.png"));
|
||||||
|
ButtonLeft.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(getClass().getResource("resourses/Down.png"));
|
||||||
|
ButtonDown.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(getClass().getResource("resourses/Right.png"));
|
||||||
|
ButtonRight.setIcon(new ImageIcon(img));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
//добавить карту
|
||||||
|
ButtonAddMap.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(ComboBoxSelectorMap.getSelectedIndex() == -1 || TextBoxNewMapName.getText().isEmpty())
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "Не все данные заполнены", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!_mapsHashMap.containsKey(ComboBoxSelectorMap.getSelectedItem()))
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "Данная карта отсутсвует", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_mapsCollection.AddMap(TextBoxNewMapName.getText(), _mapsHashMap.get(ComboBoxSelectorMap.getSelectedItem().toString()));
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//удалить карту
|
||||||
|
ButtonDeleteMap.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(ListBoxMaps.getSelectedIndex() == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(JOptionPane.showConfirmDialog(null, "Удалить карту" + ListBoxMaps.getSelectedValue().toString() + "?",
|
||||||
|
"Удаление", JOptionPane.YES_NO_OPTION) == 0)
|
||||||
|
{
|
||||||
|
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//список карт
|
||||||
|
ListBoxMaps.addListSelectionListener(new ListSelectionListener() {
|
||||||
|
@Override
|
||||||
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
|
if(ListBoxMaps.getSelectedIndex() == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Просмотр удалённых самолётов
|
||||||
|
ButtonShowDelete.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(ListBoxMaps.getSelectedIndex() == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawningObjectPlane plane = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).GetPlaneInDelete();
|
||||||
|
|
||||||
|
if(plane == null)
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "Список пуст", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FormPlane form = new FormPlane(plane);
|
||||||
|
form.setSize(700, 500);
|
||||||
|
form.setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//добавление самолёта с использованием делегата
|
||||||
|
ButtonAddPlane.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
FormPlaneConfig form = new FormPlaneConfig();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//удаление самолёта
|
||||||
|
ButtonRemovePlane.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (MaskedTextBoxPosition.getText().isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = JOptionPane.showConfirmDialog(null,"Удалить объект?","Удаление",
|
||||||
|
JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
|
||||||
|
|
||||||
|
if(result == JOptionPane.NO_OPTION)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = Integer.parseInt(MaskedTextBoxPosition.getText());
|
||||||
|
|
||||||
|
if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Delete(pos) != null)
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null,"Объект удалён");
|
||||||
|
UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null,"Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//показ хранилища
|
||||||
|
ButtonShowStorage.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(_mapsCollection == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//показ карты
|
||||||
|
ButtonShowOnMap.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_mapsCollection == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowOnMap());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonUp.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(_mapsCollection== null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject((Direction.Up))));
|
||||||
|
|
||||||
|
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBoxPlane.revalidate();
|
||||||
|
PictureBoxPlane.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonLeft.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(_mapsCollection == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject((Direction.Left))));
|
||||||
|
|
||||||
|
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBoxPlane.revalidate();
|
||||||
|
PictureBoxPlane.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonDown.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(_mapsCollection == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject((Direction.Down))));
|
||||||
|
|
||||||
|
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBoxPlane.revalidate();
|
||||||
|
PictureBoxPlane.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonRight.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(_mapsCollection == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject((Direction.Right))));
|
||||||
|
|
||||||
|
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBoxPlane.revalidate();
|
||||||
|
PictureBoxPlane.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MaskedTextBoxPosition.addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e) {
|
||||||
|
char c = e.getKeyChar();
|
||||||
|
|
||||||
|
if ((c < '0') || (c > '9'))
|
||||||
|
{
|
||||||
|
e.consume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUIComponents()
|
||||||
|
{
|
||||||
|
DefaultListModel<String> defListMod = new DefaultListModel<String>();
|
||||||
|
ListBoxMaps = new JList(defListMod);
|
||||||
|
}
|
||||||
|
}
|
77
Project/src/FormParam.form
Normal file
77
Project/src/FormParam.form
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormParam">
|
||||||
|
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="6" column-count="6" 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="701" height="430"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<toolbar id="d67f5" binding="StatusStrip">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="-1" height="20"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</toolbar>
|
||||||
|
<hspacer id="92788">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" 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>
|
||||||
|
<component id="72d61" class="javax.swing.JButton" binding="ButtonAddPlane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Создать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="f7ecd">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="0" 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="94a6a">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="5" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<component id="d66bb" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Модификация"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="a433d">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" 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>
|
||||||
|
<grid id="ecc65" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="4" col-span="5" 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="56eb2" class="javax.swing.JLabel" binding="LabelInfo">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="5" row-span="4" 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>
|
||||||
|
</form>
|
130
Project/src/FormParam.java
Normal file
130
Project/src/FormParam.java
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormParam extends JFrame
|
||||||
|
{
|
||||||
|
public JPanel MainPanel;
|
||||||
|
private JButton ButtonAddPlane;
|
||||||
|
private JPanel PictureBoxPlane;
|
||||||
|
private JButton ButtonCreateModif;
|
||||||
|
private JLabel LabelInfo;
|
||||||
|
private JLabel LabelSpeed = new JLabel();
|
||||||
|
private JLabel LabelWeight = new JLabel();
|
||||||
|
private JLabel LabelColor = new JLabel();
|
||||||
|
private JToolBar StatusStrip;
|
||||||
|
|
||||||
|
private DrawingEntities<EntityPlane, IAdditionalDrawingObject> _drawingEntities;
|
||||||
|
|
||||||
|
private IAdditionalDrawingObject SetData()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
int r = rnd.nextInt(3);
|
||||||
|
|
||||||
|
if(r == 0)
|
||||||
|
{
|
||||||
|
return new DrawingAirplaneWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(r == 1)
|
||||||
|
{
|
||||||
|
return new DrawingTriangleAirplaneWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DrawingRectAirplaneWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Draw(DrawingPlane _plane)
|
||||||
|
{
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
Random rnd = new Random();
|
||||||
|
BufferedImage bmp = new BufferedImage(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||||
|
Graphics gr = bmp.getGraphics();
|
||||||
|
gr.setColor(new Color(238, 238, 238));
|
||||||
|
gr.fillRect(0, 0, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
|
|
||||||
|
if(_plane != null)
|
||||||
|
{
|
||||||
|
_plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
||||||
|
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
|
_plane.DrawTransport(gr);
|
||||||
|
LabelSpeed.setText("Скорость: " + _plane.GetPlane().GetSpeed() + " ");
|
||||||
|
LabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " ");
|
||||||
|
LabelColor.setText("Цвет: r = " + _plane.GetPlane().GetColor().getRed() + " g = " + _plane.GetPlane().GetColor().getGreen() +
|
||||||
|
" b = " + _plane.GetPlane().GetColor().getBlue());
|
||||||
|
JLabel imageOfLogo = new JLabel();
|
||||||
|
imageOfLogo.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageOfLogo.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageOfLogo.setIcon(new ImageIcon(bmp));
|
||||||
|
PictureBoxPlane.add(imageOfLogo, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormParam()
|
||||||
|
{
|
||||||
|
//создание строки отображения скорости, веса и цвета объекта
|
||||||
|
Box LableBox = Box.createHorizontalBox();
|
||||||
|
LableBox.setMinimumSize(new Dimension(1, 20));
|
||||||
|
LableBox.add(LabelSpeed);
|
||||||
|
LableBox.add(LabelWeight);
|
||||||
|
LableBox.add(LabelColor);
|
||||||
|
StatusStrip.add(LableBox);
|
||||||
|
|
||||||
|
_drawingEntities = new DrawingEntities<>(10, EntityPlane.class, IAdditionalDrawingObject.class);
|
||||||
|
|
||||||
|
ButtonAddPlane.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
Color colorCorpus = JColorChooser.showDialog(null, "Выбор цвета", null);
|
||||||
|
EntityPlane plane = new EntityPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), colorCorpus);
|
||||||
|
IAdditionalDrawingObject addWindows = SetData();
|
||||||
|
|
||||||
|
int countWindows = rnd.nextInt(1, 4);
|
||||||
|
addWindows.SetAddEnum(countWindows);
|
||||||
|
|
||||||
|
if((_drawingEntities.Insert(plane) != -1) && (_drawingEntities.Insert(addWindows) != -1))
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||||
|
Draw(_drawingEntities.CreatePlane());
|
||||||
|
LabelInfo.setText(_drawingEntities._x_index + " " + _drawingEntities._y_index);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonCreateModif.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
Color colorFirst = JColorChooser.showDialog(null, "Выбор цвета", null);
|
||||||
|
Color colorSecond = JColorChooser.showDialog(null, "Выбор цвета", null);
|
||||||
|
EntityAirbus airbus = new EntityAirbus(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||||
|
colorFirst, colorSecond, rnd.nextBoolean(), rnd.nextBoolean());
|
||||||
|
IAdditionalDrawingObject addWindows = SetData();
|
||||||
|
int countWindows = rnd.nextInt(1, 4);
|
||||||
|
addWindows.SetAddEnum(countWindows);
|
||||||
|
|
||||||
|
if((_drawingEntities.Insert(airbus) != -1) && (_drawingEntities.Insert(addWindows) != -1))
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||||
|
Draw(_drawingEntities.CreatePlane());
|
||||||
|
LabelInfo.setText(_drawingEntities._x_index + " " + _drawingEntities._y_index);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormPlane">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormPlane">
|
||||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="10" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="20" y="42" width="864" height="483"/>
|
<xy x="20" y="42" width="1040" height="483"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<children>
|
||||||
<component id="67a15" class="javax.swing.JButton" binding="ButtonLeft">
|
<component id="67a15" class="javax.swing.JButton" binding="ButtonLeft">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="2" column="7" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="45" height="45"/>
|
<minimum-size width="45" height="45"/>
|
||||||
<preferred-size width="45" height="45"/>
|
<preferred-size width="45" height="45"/>
|
||||||
<maximum-size width="45" height="45"/>
|
<maximum-size width="45" height="45"/>
|
||||||
@ -23,7 +23,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="b10a1" class="javax.swing.JButton" binding="ButtonRight">
|
<component id="b10a1" class="javax.swing.JButton" binding="ButtonRight">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="2" column="9" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="45" height="45"/>
|
<minimum-size width="45" height="45"/>
|
||||||
<preferred-size width="45" height="45"/>
|
<preferred-size width="45" height="45"/>
|
||||||
<maximum-size width="45" height="45"/>
|
<maximum-size width="45" height="45"/>
|
||||||
@ -34,38 +34,21 @@
|
|||||||
<text value=""/>
|
<text value=""/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<hspacer id="5b756">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" 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>
|
|
||||||
<component id="a48b0" class="javax.swing.JButton" binding="ButtonCreate">
|
<component id="a48b0" class="javax.swing.JButton" binding="ButtonCreate">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="100" height="25"/>
|
<minimum-size width="100" height="30"/>
|
||||||
<preferred-size width="100" height="25"/>
|
<preferred-size width="100" height="30"/>
|
||||||
<maximum-size width="100" height="25"/>
|
<maximum-size width="100" height="30"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Создать"/>
|
<text value="Создать"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<toolbar id="ede45" binding="StatusStrip">
|
<grid id="b0c9a" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="0" column="0" row-span="1" col-span="10" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
<minimum-size width="345" height="25"/>
|
|
||||||
<preferred-size width="345" height="25"/>
|
|
||||||
<maximum-size width="345" height="25"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</toolbar>
|
|
||||||
<grid id="b0c9a" binding="PictureBox" layout-manager="BorderLayout" hgap="0" vgap="0">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@ -73,7 +56,7 @@
|
|||||||
</grid>
|
</grid>
|
||||||
<component id="51778" class="javax.swing.JButton" binding="ButtonDown">
|
<component id="51778" class="javax.swing.JButton" binding="ButtonDown">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="2" column="8" 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="45" height="45"/>
|
<minimum-size width="45" height="45"/>
|
||||||
<preferred-size width="45" height="45"/>
|
<preferred-size width="45" height="45"/>
|
||||||
<maximum-size width="45" height="45"/>
|
<maximum-size width="45" height="45"/>
|
||||||
@ -86,7 +69,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="44002" class="javax.swing.JButton" binding="ButtonUp">
|
<component id="44002" class="javax.swing.JButton" binding="ButtonUp">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="1" column="8" 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="45" height="45"/>
|
<minimum-size width="45" height="45"/>
|
||||||
<preferred-size width="45" height="45"/>
|
<preferred-size width="45" height="45"/>
|
||||||
<maximum-size width="45" height="45"/>
|
<maximum-size width="45" height="45"/>
|
||||||
@ -97,14 +80,46 @@
|
|||||||
<text value=""/>
|
<text value=""/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<hspacer id="993b6">
|
<component id="96587" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="220" height="25"/>
|
<minimum-size width="120" height="30"/>
|
||||||
<preferred-size width="220" height="25"/>
|
<preferred-size width="120" height="30"/>
|
||||||
<maximum-size width="220" height="25"/>
|
<maximum-size width="120" height="30"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Модификация"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="c1262" class="javax.swing.JButton" binding="ButtonSelectPlane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="5" 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="100" height="30"/>
|
||||||
|
<preferred-size width="100" height="30"/>
|
||||||
|
<maximum-size width="100" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Выбрать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<toolbar id="ede45" binding="StatusStrip">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="345" height="25"/>
|
||||||
|
<preferred-size width="345" height="25"/>
|
||||||
|
<maximum-size width="345" height="25"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</toolbar>
|
||||||
|
<hspacer id="5bc63">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="3" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
</hspacer>
|
</hspacer>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.event.ComponentAdapter;
|
|
||||||
import java.awt.event.ComponentEvent;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class FormPlane
|
public class FormPlane extends JDialog
|
||||||
{
|
{
|
||||||
protected DrawingPlane plane = new DrawingPlane();
|
|
||||||
|
|
||||||
public JPanel MainPanel;
|
public JPanel MainPanel;
|
||||||
private JButton ButtonCreate;
|
private JButton ButtonCreate;
|
||||||
private JButton ButtonLeft;
|
private JButton ButtonLeft;
|
||||||
@ -18,12 +14,82 @@ public class FormPlane
|
|||||||
private JButton ButtonRight;
|
private JButton ButtonRight;
|
||||||
private JButton ButtonUp;
|
private JButton ButtonUp;
|
||||||
private JToolBar StatusStrip;
|
private JToolBar StatusStrip;
|
||||||
private JPanel PictureBox;
|
private JPanel PictureBoxPlane;
|
||||||
|
private JButton ButtonCreateModif;
|
||||||
|
private JButton ButtonSelectPlane;
|
||||||
private JLabel LabelSpeed = new JLabel();
|
private JLabel LabelSpeed = new JLabel();
|
||||||
private JLabel LabelWeight = new JLabel();
|
private JLabel LabelWeight = new JLabel();
|
||||||
private JLabel LabelColor = new JLabel();
|
private JLabel LabelColor = new JLabel();
|
||||||
|
|
||||||
|
protected DrawingPlane _plane;
|
||||||
|
protected DrawingPlane _selectedPlane;
|
||||||
|
private int PictureBoxPlaneWidth;
|
||||||
|
private int PictureBoxPlaneHeight;
|
||||||
|
|
||||||
|
public DrawingPlane GetSelectedShip()
|
||||||
|
{
|
||||||
|
return _selectedPlane;
|
||||||
|
}
|
||||||
|
|
||||||
|
//метод отрисовки
|
||||||
|
public void Draw(DrawingPlane _plane) {
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
BufferedImage bmp = new BufferedImage(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||||
|
Graphics gr = bmp.getGraphics();
|
||||||
|
|
||||||
|
gr.setColor(new Color(238, 238, 238));
|
||||||
|
gr.fillRect(0, 0, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
|
|
||||||
|
if (_plane.GetPlane() != null) {
|
||||||
|
_plane.DrawTransport(gr);
|
||||||
|
JLabel imageOfLogo = new JLabel();
|
||||||
|
imageOfLogo.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageOfLogo.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageOfLogo.setIcon(new ImageIcon(bmp));
|
||||||
|
PictureBoxPlane.add(imageOfLogo, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
//создание всплывающего окна (первый конструктор)
|
||||||
public FormPlane()
|
public FormPlane()
|
||||||
|
{
|
||||||
|
super(new Frame("Аэробус"));
|
||||||
|
CreateWindow();
|
||||||
|
setModal(true);
|
||||||
|
getContentPane().add(MainPanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
//второй конструктор
|
||||||
|
protected FormPlane(DrawningObjectPlane plane)
|
||||||
|
{
|
||||||
|
super(new Frame("Аэробус"));
|
||||||
|
CreateWindow();
|
||||||
|
setModal(true);
|
||||||
|
_plane = plane.GetDrawingObjectPlane();
|
||||||
|
SetData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingPlane GetSelectedPlane()
|
||||||
|
{
|
||||||
|
return _selectedPlane;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetData()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
_plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
||||||
|
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
|
|
||||||
|
LabelSpeed.setText("Скорость: " + _plane.GetPlane().GetSpeed() + " ");
|
||||||
|
LabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " ");
|
||||||
|
LabelColor.setText("Цвет: r = " + _plane.GetPlane().GetColor().getRed() + " g = " + _plane.GetPlane().GetColor().getGreen() +
|
||||||
|
" b = " + _plane.GetPlane().GetColor().getBlue());
|
||||||
|
PictureBoxPlane.add(_plane, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateWindow()
|
||||||
{
|
{
|
||||||
//создание строки отображения скорости, веса и цвета объекта
|
//создание строки отображения скорости, веса и цвета объекта
|
||||||
Box LableBox = Box.createHorizontalBox();
|
Box LableBox = Box.createHorizontalBox();
|
||||||
@ -33,6 +99,10 @@ public class FormPlane
|
|||||||
LableBox.add(LabelColor);
|
LableBox.add(LabelColor);
|
||||||
StatusStrip.add(LableBox);
|
StatusStrip.add(LableBox);
|
||||||
|
|
||||||
|
PictureBoxPlane.setBackground(Color.WHITE);
|
||||||
|
setPreferredSize(new Dimension(1000, 700));
|
||||||
|
getContentPane().add(MainPanel);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Image img = ImageIO.read(getClass().getResource("resourses/Up.png"));
|
Image img = ImageIO.read(getClass().getResource("resourses/Up.png"));
|
||||||
@ -43,78 +113,130 @@ public class FormPlane
|
|||||||
ButtonDown.setIcon(new ImageIcon(img));
|
ButtonDown.setIcon(new ImageIcon(img));
|
||||||
img = ImageIO.read(getClass().getResource("resourses/Right.png"));
|
img = ImageIO.read(getClass().getResource("resourses/Right.png"));
|
||||||
ButtonRight.setIcon(new ImageIcon(img));
|
ButtonRight.setIcon(new ImageIcon(img));
|
||||||
} catch (Exception ex){
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
System.out.println(ex.getMessage());
|
System.out.println(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_selectedPlane = _plane;
|
||||||
|
|
||||||
ButtonCreate.addActionListener(new ActionListener() {
|
ButtonCreate.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
plane = new DrawingPlane();
|
try
|
||||||
|
{
|
||||||
|
PictureBoxPlane.remove(_plane);
|
||||||
|
}
|
||||||
|
catch (Exception c){ }
|
||||||
|
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
plane.Initial(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null);
|
||||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
|
||||||
plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
_plane = new DrawingPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||||
PictureBox.getWidth(), PictureBox.getHeight());
|
colorSimple, rnd.nextInt(3));
|
||||||
LabelSpeed.setText("Скорость: " + plane.GetPlane().GetSpeed() + " ");
|
|
||||||
LabelWeight.setText("Вес: " + plane.GetPlane().GetWeight() + " ");
|
SetData();
|
||||||
LabelColor.setText("Цвет: r = " + plane.GetPlane().GetColor().getRed() + " g = " + plane.GetPlane().GetColor().getGreen() +
|
|
||||||
" b = " + plane.GetPlane().GetColor().getBlue());
|
Draw(_plane);
|
||||||
Draw();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//обновление размеров формы
|
ButtonCreateModif.addActionListener(new ActionListener() {
|
||||||
MainPanel.addComponentListener(new ComponentAdapter() {
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PictureBoxPlane.remove(_plane);
|
||||||
|
}
|
||||||
|
catch (Exception c){ }
|
||||||
|
|
||||||
|
Random rnd = new Random();
|
||||||
|
Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null);
|
||||||
|
Color colorModif = JColorChooser.showDialog(null, "Выберите цвет", null);
|
||||||
|
|
||||||
|
_plane = new DrawingAirbus(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||||
|
colorSimple, rnd.nextInt(3), colorModif, rnd.nextBoolean(), rnd.nextBoolean());
|
||||||
|
|
||||||
|
SetData();
|
||||||
|
|
||||||
|
Draw(_plane);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonSelectPlane.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
_selectedPlane = _plane;
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
PictureBoxPlane.addComponentListener(new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
super.componentResized(e);
|
super.componentResized(e);
|
||||||
plane.ChangeBorders(PictureBox.getWidth(), PictureBox.getHeight());
|
|
||||||
Draw();
|
if(_plane == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_plane.ChangeBorders(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PictureBoxPlane.remove(_plane);
|
||||||
|
}
|
||||||
|
catch (Exception c){ }
|
||||||
|
|
||||||
|
PictureBoxPlane.add(_plane, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonUp.addActionListener(new ActionListener() {
|
ButtonUp.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
plane.MoveTransport(Direction.Up);
|
_plane.MoveTransport(Direction.Up);
|
||||||
Draw();
|
PictureBoxPlane.revalidate();
|
||||||
|
Draw(_plane);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonLeft.addActionListener(new ActionListener() {
|
ButtonLeft.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
plane.MoveTransport(Direction.Left);
|
_plane.MoveTransport(Direction.Left);
|
||||||
Draw();
|
PictureBoxPlane.revalidate();
|
||||||
|
Draw(_plane);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonDown.addActionListener(new ActionListener() {
|
ButtonDown.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
plane.MoveTransport(Direction.Down);
|
_plane.MoveTransport(Direction.Down);
|
||||||
Draw();
|
PictureBoxPlane.revalidate();
|
||||||
|
Draw(_plane);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonRight.addActionListener(new ActionListener() {
|
ButtonRight.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
plane.MoveTransport(Direction.Right);
|
_plane.MoveTransport(Direction.Right);
|
||||||
Draw();
|
PictureBoxPlane.revalidate();
|
||||||
|
Draw(_plane);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//кнопка подтверждение выбора
|
||||||
|
ButtonSelectPlane.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
_selectedPlane = _plane;
|
||||||
|
dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw()
|
|
||||||
{
|
|
||||||
if(plane.GetPlane() == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
plane.DrawTransport(PictureBox.getGraphics());
|
|
||||||
}
|
|
||||||
}
|
}
|
417
Project/src/FormPlaneConfig.form
Normal file
417
Project/src/FormPlaneConfig.form
Normal file
@ -0,0 +1,417 @@
|
|||||||
|
<?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="5" 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="f0d81" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="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>
|
||||||
|
</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="f542d">
|
||||||
|
<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>
|
||||||
|
<hspacer id="2e630">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="4" 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>
|
311
Project/src/FormPlaneConfig.java
Normal file
311
Project/src/FormPlaneConfig.java
Normal file
@ -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<DrawingPlane> EventAddPlane;
|
||||||
|
|
||||||
|
//объект для контролирования работы DnD
|
||||||
|
Object dragObject;
|
||||||
|
|
||||||
|
//хранит в себе объект иллюминатор
|
||||||
|
Object enterObject;
|
||||||
|
|
||||||
|
public void AddEvent(Consumer<DrawingPlane> ev)
|
||||||
|
{
|
||||||
|
EventAddPlane = ev;
|
||||||
|
}
|
||||||
|
|
||||||
|
//конструктор
|
||||||
|
public FormPlaneConfig()
|
||||||
|
{
|
||||||
|
super("Самолёт");
|
||||||
|
CreateWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(DrawingPlane _plane)
|
||||||
|
{
|
||||||
|
PictureBoxPlane.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(PictureBoxPlane.getSize());
|
||||||
|
imageOfLogo.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageOfLogo.setIcon(new ImageIcon(bmp));
|
||||||
|
PictureBoxPlane.add(imageOfLogo, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateWindow()
|
||||||
|
{
|
||||||
|
setPreferredSize(new Dimension(1000, 700));
|
||||||
|
getContentPane().add(MainPanel);
|
||||||
|
|
||||||
|
//рамки у Label
|
||||||
|
LabelAddColor.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));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//настройки курсоров
|
||||||
|
PictureBoxPlane.addMouseListener(defCursor);
|
||||||
|
LabelBaseColor.addMouseListener(defCursor);
|
||||||
|
LabelAddColor.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);
|
||||||
|
|
||||||
|
//настройка DnD для перетаскивания формы иллюминаторов
|
||||||
|
AdditWindowDropObject(LabelSimpleWindow);
|
||||||
|
AdditWindowDropObject(LabelRectWindow);
|
||||||
|
AdditWindowDropObject(LabelTriangleWindow);
|
||||||
|
|
||||||
|
AdditWindowDropTarget(PictureBoxPlane);
|
||||||
|
|
||||||
|
//передача объекта через событие
|
||||||
|
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);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(LabelAddColor.getMousePosition() != null && _plane instanceof DrawingAirbus airbus)
|
||||||
|
{
|
||||||
|
airbus.SetAddColor(panel.getBackground());
|
||||||
|
Draw(_plane);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dropItem instanceof JLabel label && PictureBoxPlane.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
|
||||||
|
{
|
||||||
|
_plane = new DrawingPlane(speed, weight, Color.WHITE, countWindow);
|
||||||
|
Draw(_plane);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
catch(Exception ex) { }
|
||||||
|
}
|
||||||
|
else if(label == LabelModifiedObject)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_plane = new DrawingAirbus(speed, weight, Color.WHITE, countWindow, Color.WHITE, addCompartment, addEngine);
|
||||||
|
Draw(_plane);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
catch (Exception ex) { };
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_plane != null)
|
||||||
|
{
|
||||||
|
_plane.SetPosition(PictureBoxPlane.getWidth() - 200, PictureBoxPlane.getHeight() - 150, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
|
PictureBoxPlane.add(_plane, BorderLayout.CENTER);
|
||||||
|
Draw(_plane);
|
||||||
|
repaint();
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdditWindowDropTarget(JComponent obj)
|
||||||
|
{
|
||||||
|
obj.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {super.mouseEntered(e);
|
||||||
|
Window_DragEnter(obj);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {super.mouseExited(e);
|
||||||
|
DragExit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdditWindowDropObject(JComponent obj)
|
||||||
|
{
|
||||||
|
obj.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {super.mousePressed(e);
|
||||||
|
Window_MouseDown(obj);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {super.mouseReleased(e);
|
||||||
|
Window_DragDrop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window_MouseDown(Object sender)
|
||||||
|
{
|
||||||
|
IAdditionalDrawingObject windows;
|
||||||
|
switch (((JLabel)sender).getText()){
|
||||||
|
case "Простая":
|
||||||
|
windows = new DrawingAirplaneWindow();
|
||||||
|
break;
|
||||||
|
case "Треугольная":
|
||||||
|
windows = new DrawingTriangleAirplaneWindow();
|
||||||
|
break;
|
||||||
|
case "Квадратная":
|
||||||
|
windows = new DrawingRectAirplaneWindow();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
enterObject = windows;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window_DragEnter(Object sender)
|
||||||
|
{
|
||||||
|
if(enterObject != null && IAdditionalDrawingObject.class.isAssignableFrom(enterObject.getClass()) && _plane != null)
|
||||||
|
{
|
||||||
|
setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||||
|
dragObject = sender;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window_DragDrop()
|
||||||
|
{
|
||||||
|
if(dragObject == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), (IAdditionalDrawingObject)enterObject);
|
||||||
|
DragExit();
|
||||||
|
enterObject = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DragExit()
|
||||||
|
{
|
||||||
|
if(enterObject != null && dragObject != null)
|
||||||
|
{
|
||||||
|
setCursor(Cursor.getDefaultCursor());
|
||||||
|
Draw(_plane);
|
||||||
|
dragObject = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
Project/src/IAdditionalDrawingObject.java
Normal file
7
Project/src/IAdditionalDrawingObject.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IAdditionalDrawingObject
|
||||||
|
{
|
||||||
|
void SetAddEnum(int airplaneWindow);
|
||||||
|
void DrawAirplaneWindow(Color colorAirplaneWindow, Graphics g, float _startPosX, float _startPosY);
|
||||||
|
}
|
19
Project/src/IDrawningObject.java
Normal file
19
Project/src/IDrawningObject.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawningObject
|
||||||
|
{
|
||||||
|
//шаг перемещения объекта
|
||||||
|
public float Step();
|
||||||
|
|
||||||
|
//установка позиции объекта
|
||||||
|
void SetObject(int x, int y, int width, int height);
|
||||||
|
|
||||||
|
//изменение направления перемещения объекта
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
|
||||||
|
//отрисовка объекта
|
||||||
|
void DrawningObject(Graphics g);
|
||||||
|
|
||||||
|
//получение текущей позиции объекта
|
||||||
|
float[] GetCurrentPosition();
|
||||||
|
}
|
@ -1,13 +1,15 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class Main {
|
public class Main
|
||||||
public static void main(String[] args) {
|
{
|
||||||
JFrame frame = new JFrame("Airbus");
|
public static void main(String[] args)
|
||||||
frame.setContentPane(new FormPlane().MainPanel);
|
{
|
||||||
|
JFrame frame = new JFrame("Аэробус");
|
||||||
|
frame.setContentPane(new FormMapWithSetPlanesGeneric().MainPanel);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setLocation(500, 200);
|
frame.setLocation(200, 100);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setSize(1000, 500);
|
frame.setSize(1000, 700);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
229
Project/src/MapWithSetPlanesGeneric.java
Normal file
229
Project/src/MapWithSetPlanesGeneric.java
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends AbstractMap>
|
||||||
|
{
|
||||||
|
//ширина окна отрисовки
|
||||||
|
private final int _pictureWidth;
|
||||||
|
|
||||||
|
//высота окна отрисовки
|
||||||
|
private final int _pictureHeight;
|
||||||
|
|
||||||
|
//размер занимаемого объектом места (ширина)
|
||||||
|
private final int _placeSizeWidth = 210;
|
||||||
|
|
||||||
|
//размер занимаемого объектом места (высота)
|
||||||
|
private final int _placeSizeHeight = 90;
|
||||||
|
|
||||||
|
//набор объектов
|
||||||
|
private final SetPlanesGeneric<T> _setPlanes;
|
||||||
|
|
||||||
|
//набор удалённых объектов (двусвязный список)
|
||||||
|
public final LinkedList<T> _deletePlane;
|
||||||
|
|
||||||
|
//карта
|
||||||
|
private final U _map;
|
||||||
|
|
||||||
|
//конструктор
|
||||||
|
public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setPlanes = new SetPlanesGeneric<T>(width * height);
|
||||||
|
_deletePlane = new LinkedList<>();
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Add(T plane)
|
||||||
|
{
|
||||||
|
return _setPlanes.Insert(plane);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Delete(int position)
|
||||||
|
{
|
||||||
|
T temp = _setPlanes.Remove(position);
|
||||||
|
_deletePlane.add(temp);
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
//вывод всего набора объектов
|
||||||
|
public BufferedImage ShowSet()
|
||||||
|
{
|
||||||
|
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
|
||||||
|
Graphics gr = bmp.getGraphics();
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawPlanes(gr);
|
||||||
|
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
//просмотр объекта на карте
|
||||||
|
public BufferedImage ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
|
||||||
|
for(int i = 0; i < _setPlanes.Count(); i++)
|
||||||
|
{
|
||||||
|
var plane = _setPlanes.Get(i);
|
||||||
|
|
||||||
|
if(plane != null)
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
|
||||||
|
}
|
||||||
|
|
||||||
|
//пеермещение объекта по карте
|
||||||
|
public BufferedImage MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if(_map != null)
|
||||||
|
{
|
||||||
|
return _map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
|
||||||
|
}
|
||||||
|
|
||||||
|
//"взламываем" набор, чтобы все элементы оказались в начале
|
||||||
|
private void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setPlanes.Count() - 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < _setPlanes.Count(); i++)
|
||||||
|
{
|
||||||
|
if (_setPlanes.Get(i) == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var plane = _setPlanes.Get(j);
|
||||||
|
|
||||||
|
if (plane != null)
|
||||||
|
{
|
||||||
|
_setPlanes.Insert(plane, i);
|
||||||
|
_setPlanes.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//метод отрисовки фона
|
||||||
|
public void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
//заливаем область в цвет бетона
|
||||||
|
g2d.setPaint(Color.LIGHT_GRAY);
|
||||||
|
g2d.fillRect(0, 0, _pictureWidth, _pictureHeight);
|
||||||
|
|
||||||
|
g2d.setStroke(new BasicStroke(3));
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
|
||||||
|
for(int i = 0; i < _pictureWidth / _placeSizeWidth - 1; i++)
|
||||||
|
{
|
||||||
|
//линия разметки места
|
||||||
|
for(int j = 2; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{
|
||||||
|
g2d.drawLine(i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 5, j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
g2d.drawLine(i * _placeSizeWidth + 5, _placeSizeHeight * 2, i * _placeSizeWidth + 5, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
//отрисовка разметки взлётной полосы
|
||||||
|
g2d.setColor(Color.DARK_GRAY);
|
||||||
|
g2d.fillRect(_placeSizeWidth * 2 + 35, 0, 175, _pictureHeight);
|
||||||
|
|
||||||
|
g2d.setStroke(new BasicStroke(5));
|
||||||
|
g2d.setColor(Color.WHITE);
|
||||||
|
g2d.drawLine(_placeSizeWidth * 2 + 210, 0, _placeSizeWidth * 2 + 210, _pictureHeight);
|
||||||
|
g2d.drawLine(_placeSizeWidth * 2 + 35, 0, _placeSizeWidth * 2 + 35, _pictureHeight);
|
||||||
|
g2d.drawLine(_placeSizeWidth * 2 + 215, 0, _placeSizeWidth * 2 + 215, _pictureHeight);
|
||||||
|
g2d.drawLine(_placeSizeWidth * 2 + 30, 0, _placeSizeWidth * 2 + 30, _pictureHeight);
|
||||||
|
|
||||||
|
g2d.setStroke(new BasicStroke(5));
|
||||||
|
g2d.setColor(Color.WHITE);
|
||||||
|
for (int i = 0; i < _pictureHeight / _placeSizeHeight; ++i)
|
||||||
|
{
|
||||||
|
g2d.drawLine(_placeSizeWidth * 2 + 125, 20 + i * _placeSizeHeight, _placeSizeWidth * 2 + 125, (i + 1) * _placeSizeHeight - 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
g2d.setColor(new Color(0xFF, 0x45, 0x00));
|
||||||
|
for(int i = 0; i < _pictureHeight / 20; i++)
|
||||||
|
{
|
||||||
|
g2d.drawLine(_placeSizeWidth * 2 + 15, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 2 + 15, (i + 1) * _placeSizeHeight / 2 - 20);
|
||||||
|
g2d.drawLine(_placeSizeWidth * 3 + 20, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 3 + 20, (i + 1) * _placeSizeHeight / 2 - 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
//отрисовка сочков
|
||||||
|
for(int i = 1; i < 6; i++)
|
||||||
|
{
|
||||||
|
g2d.setColor(new Color(0xFF, 0xB6, 0xC1));
|
||||||
|
int[] xPoint = {(i * 70 - 10) + 45, i * 70 - 10, i * 70 - 10};
|
||||||
|
int[] yPoint = {30, 50, 10};
|
||||||
|
g2d.fillPolygon(xPoint, yPoint, xPoint.length);
|
||||||
|
|
||||||
|
g2d.setStroke(new BasicStroke(3));
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.drawLine(i * 70 - 10, 10, i * 70 - 10, 80);
|
||||||
|
g2d.drawLine(i * 70 - 10, 10, (i * 70 - 10) + 45, 30);
|
||||||
|
g2d.drawLine(i * 70 - 10, 50, (i * 70 - 10) + 45, 30);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//метод прорисовки объеков
|
||||||
|
public void DrawPlanes(Graphics g)
|
||||||
|
{
|
||||||
|
int position = 0;
|
||||||
|
int currentWidth = 1;
|
||||||
|
int currentHeight = 6;
|
||||||
|
|
||||||
|
for (int i = 0; i < _setPlanes.Count(); i++)
|
||||||
|
{
|
||||||
|
if(_setPlanes.Get(i) != null)
|
||||||
|
{
|
||||||
|
_setPlanes.Get(i).SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight);
|
||||||
|
_setPlanes.Get(i).DrawningObject(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(position % 2 == 0)
|
||||||
|
{
|
||||||
|
position++;
|
||||||
|
currentWidth--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
position = 0;
|
||||||
|
currentWidth = 1;
|
||||||
|
currentHeight--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetPlaneInList(int index)
|
||||||
|
{
|
||||||
|
return _setPlanes.Get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetPlaneInDelete()
|
||||||
|
{
|
||||||
|
if(_deletePlane.isEmpty())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _deletePlane.pop();
|
||||||
|
}
|
||||||
|
}
|
66
Project/src/MapsCollection.java
Normal file
66
Project/src/MapsCollection.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
//класс для хранения коллекции карт
|
||||||
|
public class MapsCollection
|
||||||
|
{
|
||||||
|
//словарь (хранилище) с картами
|
||||||
|
public HashMap<String, MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>> _mapStorage;
|
||||||
|
|
||||||
|
//возвращение списка названий карт
|
||||||
|
public ArrayList<String> Keys()
|
||||||
|
{
|
||||||
|
return new ArrayList<>(_mapStorage.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
//ширина окна отрисовки
|
||||||
|
private final int _pictureWidth;
|
||||||
|
|
||||||
|
//высота окна отрисовки
|
||||||
|
private final int _pictureHeight;
|
||||||
|
|
||||||
|
//конструктор
|
||||||
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_mapStorage = new HashMap<>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
//добавление карты
|
||||||
|
public void AddMap(String name, AbstractMap map)
|
||||||
|
{
|
||||||
|
if(_mapStorage.containsKey(name))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_mapStorage.put(name, new MapWithSetPlanesGeneric<>(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
|
|
||||||
|
//удаление карты
|
||||||
|
public void DelMap(String name)
|
||||||
|
{
|
||||||
|
_mapStorage.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Доступ к аэродрому
|
||||||
|
public MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> get(String index)
|
||||||
|
{
|
||||||
|
if(_mapStorage.containsKey(index))
|
||||||
|
{
|
||||||
|
return _mapStorage.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawningObjectPlane Get(String name, int index)
|
||||||
|
{
|
||||||
|
if(_mapStorage.containsKey(name))
|
||||||
|
{
|
||||||
|
return _mapStorage.get(name).GetPlaneInList(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
11
Project/src/Project.iml
Normal file
11
Project/src/Project.iml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
87
Project/src/SetPlanesGeneric.java
Normal file
87
Project/src/SetPlanesGeneric.java
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public class SetPlanesGeneric<T extends Object> implements Iterable<T>
|
||||||
|
{
|
||||||
|
//массив объектов, которые храним
|
||||||
|
private ArrayList<T> _places;
|
||||||
|
|
||||||
|
//максимальное кол-во элементов в списке
|
||||||
|
private final int _maxCount;
|
||||||
|
|
||||||
|
//количество объектов в массиве
|
||||||
|
public int Count()
|
||||||
|
{
|
||||||
|
return _places.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
//конструктор
|
||||||
|
public SetPlanesGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//добавление объекта в набор
|
||||||
|
public int Insert(T plane)
|
||||||
|
{
|
||||||
|
return Insert(plane, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//добавление объекта в набор на конкретную позицию
|
||||||
|
public int Insert(T plane, int position)
|
||||||
|
{
|
||||||
|
//проверка на корректность значения индекса
|
||||||
|
if (position >= _maxCount|| position < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
_places.add(plane);
|
||||||
|
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
//удаление объекта из набора с конкретной позиции
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
// проверка позиции
|
||||||
|
if (position >= _maxCount || position < 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// удаление объекта из массива, присовив элементу массива значение null
|
||||||
|
T temp = _places.get(position);
|
||||||
|
_places.remove(position);
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
//получение объекта из набора по позиции
|
||||||
|
public T Get(int position)
|
||||||
|
{
|
||||||
|
if (position >= _maxCount || position < 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _places.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set(int position, T value)
|
||||||
|
{
|
||||||
|
if(position >= _maxCount || position < 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Insert(value, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator()
|
||||||
|
{
|
||||||
|
return _places.iterator();
|
||||||
|
}
|
||||||
|
}
|
55
Project/src/SimpleMap.java
Normal file
55
Project/src/SimpleMap.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class SimpleMap extends AbstractMap
|
||||||
|
{
|
||||||
|
//цвет закрытого участка
|
||||||
|
private final Color barriedColor = Color.black;
|
||||||
|
|
||||||
|
//цвет открытого участка
|
||||||
|
private final Color roadColor = Color.gray;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(roadColor);
|
||||||
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(barriedColor);
|
||||||
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
|
||||||
|
}
|
||||||
|
}
|
59
Project/src/StarWarsMap.java
Normal file
59
Project/src/StarWarsMap.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class StarWarsMap extends AbstractMap
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
|
||||||
|
//цвет закрытого участка
|
||||||
|
Color barriedColor;
|
||||||
|
|
||||||
|
//цвет открытого участка
|
||||||
|
private final Color roadColor = new Color(0, 0, 139);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(roadColor);
|
||||||
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
barriedColor = new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
|
||||||
|
g2d.setPaint(barriedColor);
|
||||||
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user