Почти готово

This commit is contained in:
nezui1 2024-04-22 23:43:02 +04:00
parent 3edcac277f
commit 3cb248f857
12 changed files with 762 additions and 0 deletions

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" 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.svg" 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="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@ -0,0 +1,21 @@
/**
* Направление перемещение
*/
public enum DirectionType {
/**
* Вверх
*/
Up,
/**
* Вниз
*/
Down,
/**
* Влево
*/
Left,
/**
* Вправо
*/
Right,
}

View File

@ -0,0 +1,247 @@
import java.awt.*;
import java.util.Random;
/**
* Класс отрисовки и перемещения объекта-сущности
*/
public class DrawningAirFighter {
/**
* Класс-сущность
*/
public EntityAirFighter EntityAirFighter;
public EntityAirFighter getEntityAirFighter(){
return EntityAirFighter;
}
/**
* Обхект класса отрисовки иллюминаторов
*/
private DrawningAirFighterEngine _drawningAirFighterEngine;
/**
* Ширина окна
*/
private Integer _pictureWidth;
/**
* Высота окна
*/
private Integer _pictureHeight;
/**
* Начальная координата x
*/
private Integer _startPosX;
/**
* Начальная координата y
*/
private Integer _startPosY;
/**
* Ширина истребителя
*/
public final int _drawningAirFlighterWidth = 120;
/**
* Высота истребителя
*/
public final int _drawningAirFlighterHeight = 140;
/**
* Инициализация свойств
* @param speed Скорость
* @param weight Вес
* @param bodyColor Основной цвет
* @param additionalColor Дополнительный цвет
* @param rocket Признак (опция) наличия ракет
* @param additionalWing Признак (опция) наличия дополнительный крыльев
*/
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean rocket, boolean additionalWing){
EntityAirFighter = new EntityAirFighter();
EntityAirFighter.Init(speed,weight,bodyColor,additionalColor,rocket,additionalWing);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
_drawningAirFighterEngine = new DrawningAirFighterEngine();
Random random = new Random();
int engineCount = 2 * random.nextInt(1,3);
_drawningAirFighterEngine.setEngineCount(engineCount);
}
/**
* Установка границ поля
* @param width Ширина поля
* @param height Высота поля
* @return
*/
public boolean SetPictureSize(int width, int height){
if (width > _drawningAirFlighterWidth && height > _drawningAirFlighterHeight){
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX != null && _startPosY != null){
if(_startPosX + _drawningAirFlighterWidth > _pictureWidth){
_startPosX = _pictureWidth - _drawningAirFlighterWidth;
}
if(_startPosY + _drawningAirFlighterHeight > _pictureHeight){
_startPosY = _pictureHeight - _drawningAirFlighterHeight;
}
}
return true;
}
return false;
}
/**
* Установка позиции истребителя
* @param x Координата x
* @param y Координата y
*/
public void SetPosition(int x, int y){
if(_pictureHeight == null || _pictureWidth == null){
return;
}
else {
_startPosX = x;
_startPosY = y;
if(_startPosX < 0) _startPosX = 0;
if(_startPosY < 0) _startPosY = 0;
if(_startPosX + _drawningAirFlighterWidth > _pictureWidth){
_startPosX = _pictureWidth - _drawningAirFlighterWidth;
}
if(_startPosY + _drawningAirFlighterHeight > _pictureHeight){
_startPosY = _pictureHeight - _drawningAirFlighterHeight;
}
}
}
/**
* Выбор направления перемещения
*
* @param direction Направление
* @return true - перемещение возможно и выполнено, false - перемещение невозможно и не выполено
*/
public boolean MoveTransport(DirectionType direction){
if(EntityAirFighter == null || _startPosX == null || _startPosY == null){
return false;
}
switch (direction){
case DirectionType.Up:
if(_startPosY - EntityAirFighter.getStep() > 0){
_startPosY -= (int)EntityAirFighter.getStep();
}
return true;
case DirectionType.Left:
if(_startPosX - EntityAirFighter.getStep() > 0){
_startPosX -= (int)EntityAirFighter.getStep();
}
return true;
case DirectionType.Down:
if(_startPosY + EntityAirFighter.getStep() < _pictureWidth - _drawningAirFlighterHeight){
_startPosY -= (int)EntityAirFighter.getStep();
}
return true;
case DirectionType.Right:
if (_startPosX + EntityAirFighter.getStep() > _pictureHeight - _drawningAirFlighterWidth){
_startPosX -=(int)EntityAirFighter.getStep();
}
return true;
default:
return false;
}
}
public void DrawTransport(Graphics g){
if(EntityAirFighter == null || _startPosX == null || _startPosY == null){
return;
}
Graphics2D g2d = (Graphics2D) g;
//ракеты
if (EntityAirFighter.withRocket()){
int[] xFirstRocket = {_startPosX + 55, _startPosX + 95, _startPosX + 105, _startPosX + 95,_startPosX + 55};
int[] yFirstRocket = {_startPosY + 110,_startPosY + 110,_startPosY + 115, _startPosY + 120,_startPosY + 120};
g2d.setColor(Color.BLACK);
g2d.drawPolygon(xFirstRocket,yFirstRocket, 5);
g2d.setColor(EntityAirFighter.getAdditionalColor());
g2d.fillPolygon(xFirstRocket,yFirstRocket, 5);
int[] xSecondRocket = {_startPosX + 55, _startPosX + 95, _startPosX + 105, _startPosX + 95,_startPosX + 55};
int[] ySecondRocket = {_startPosY + 30,_startPosY + 30,_startPosY + 35, _startPosY + 40,_startPosY + 40};
g2d.setColor(Color.BLACK);
g2d.drawPolygon(xSecondRocket,ySecondRocket, 5);
}
//корпус
g2d.setColor(Color.BLACK);
g2d.drawRect(_startPosX, _startPosY + 60, 100,20);
int[] xBody = {_startPosX + 100, _startPosX + 120, _startPosX + 100};
int[] yBody = {_startPosY + 80, _startPosY + 70, _startPosY + 60};
g2d.drawPolygon(xBody,yBody, 3);
g2d.setColor(EntityAirFighter.getBodyColor());
g2d.fillPolygon(xBody,yBody, 3);
//верхнее крыло
g2d.setColor(Color.BLACK);
int[] xWingUpper = {_startPosX + 80, _startPosX + 80, _startPosX + 70, _startPosX + 60};
int[] yWingUpper = {_startPosY + 80, _startPosY + 140, _startPosY + 140, _startPosY + 80};
g2d.drawPolygon(xWingUpper, yWingUpper, 4);
g2d.setColor(EntityAirFighter.getBodyColor());
g2d.fillPolygon(xWingUpper, yWingUpper, 4);
//нижнее крыло
g2d.setColor(Color.BLACK);
int[] xWingLower = {_startPosX + 80, _startPosX + 80, _startPosX + 70, _startPosX + 60};
int[] yWingLower = {_startPosY + 60, _startPosY, _startPosY, _startPosY + 60};
g2d.drawPolygon(xWingLower, yWingLower, 4);
g2d.setColor(EntityAirFighter.getBodyColor());
g2d.fillPolygon(xWingLower, yWingLower, 4);
//задние крылья
//верхнее
g2d.setColor(Color.BLACK);
int[] xRearWingUpper = {_startPosX, _startPosX, _startPosX + 25, _startPosX + 25};
int[] yRearWingUpper = {_startPosY + 60, _startPosY + 30, _startPosY + 50, _startPosY + 60};
g2d.drawPolygon(xRearWingUpper, yRearWingUpper, 4);
g2d.setColor(EntityAirFighter.getBodyColor());
g2d.fillPolygon(xRearWingUpper, yRearWingUpper, 4);
//нижнее
g2d.setColor(Color.BLACK);
int[] xRearWingLower = {_startPosX, _startPosX, _startPosX + 25, _startPosX + 25};
int[] yRearWingLower = {_startPosY + 80, _startPosY + 110, _startPosY + 90, _startPosY + 80};
g2d.drawPolygon(xRearWingLower, yRearWingLower, 4);
g2d.setColor(EntityAirFighter.getBodyColor());
g2d.fillPolygon(xRearWingLower, yRearWingLower, 4);
if(EntityAirFighter.withAdditionalWing()){
// нижнее доп крыло
g2d.setColor(Color.BLACK);
int[] xAddWingLower = {_startPosX + 60, _startPosX + 60, _startPosX + 50, _startPosX + 40};
int[] yAddWingLower = {_startPosY + 80, _startPosY + 140, _startPosY + 140, _startPosY + 80};
g2d.drawPolygon(xAddWingLower, yAddWingLower, 4);
g2d.setColor(EntityAirFighter.getAdditionalColor());
g2d.fillPolygon(xAddWingLower, yAddWingLower, 4);
// верхнее доп крыло
g2d.setColor(Color.BLACK);
int[] xAddWingUpper = {_startPosX + 60, _startPosX + 60, _startPosX + 50, _startPosX + 40};
int[] yAddWingUpper = {_startPosY + 60, _startPosY, _startPosY, _startPosY + 60};
g2d.drawPolygon(xAddWingUpper , yAddWingUpper , 4);
g2d.setColor(EntityAirFighter.getAdditionalColor());
g2d.fillPolygon(xAddWingUpper , yAddWingUpper, 4);
}
}
}

View File

@ -0,0 +1,35 @@
import java.awt.*;
/**
* Класс отрисовки иллюминаторов
*/
public class DrawningAirFighterEngine {
/**
* количество двигателей
*/
private EngineEnum _engineCount;
public void setEngineCount(int engineCount){
for(EngineEnum value : EngineEnum.values()){
if(value.engineEnumNumber == engineCount){
_engineCount = value;
return;
}
}
}
private void DrawEngine(Graphics2D g2d, int posX, int posY){
g2d.setColor(Color.BLACK);
g2d.drawOval(posX,posY,10,10);
}
public void drawAirFighterEngine(Graphics g, float startPosX, float startPosY){
Graphics2D g2d = (Graphics2D) g;
int intervalBetweenEngine = 140 / _engineCount.getEngineEnumNumber();
for(int i = 0; i < _engineCount.getEngineEnumNumber(); i++){
int posX = (int) (startPosX + i * intervalBetweenEngine);
DrawEngine(g2d, posX, (int)startPosY);
}
}
}

View File

@ -0,0 +1,26 @@
/**
* Перечисление возможного колличества двигателей
*/
public enum EngineEnum {
/**
* Два
*/
Two(2),
/**
* Четыре
*/
Four(4),
/**
* Шесть
*/
Six(6);
public final int engineEnumNumber;
public int getEngineEnumNumber(){
return engineEnumNumber;
}
EngineEnum(int number){
this.engineEnumNumber = number;
}
}

View File

@ -0,0 +1,77 @@
import java.awt.*;
/**
* Класс сущности "Истребитель"
*/
public class EntityAirFighter {
/**
* Скорость
*/
public int Speed;
/**
* Вес
*/
public double Weight;
/**
* Основной цвет
*/
public Color BodyColor;
public Color getBodyColor() {
return BodyColor;
}
/**
* Дополнительный цвет
*/
public Color AdditionalColor;
public Color getAdditionalColor() {
return AdditionalColor;
}
/**
* Признак (опция) наличия ракет
*/
public boolean Rocket;
public boolean withRocket(){
return Rocket;
}
/**
* Признак (опция) наличия дополнительных крыльев
*/
public boolean AdditionalWing;
public boolean withAdditionalWing(){
return AdditionalWing;
}
/**
* Шаг
*/
public double Step;
public double getStep(){
return (double) Speed * 100 / Weight;
}
/**
* Инициализация полей объекта-класса истребителя
*
* @param speed скорость
* @param weight вес
* @param bodyColor основной цвет
* @param additionalColor дополнительный цвет
* @param rocket признак (опция) наличия ракет
* @param additionalWing Признак (опция) наличия дополнительный крыльев
*/
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean rocket, boolean additionalWing){
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Rocket = rocket;
AdditionalWing = additionalWing;
}
}

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormAirFighter">
<grid id="27dc6" binding="PanelWrapper" 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>
<xy x="20" y="20" width="728" height="549"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="e30f5" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" 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>
<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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="62c2e" class="javax.swing.JButton" binding="buttonCreate">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<component id="a3af8" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="2" column="4" 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="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/right.jpg"/>
<text value=""/>
</properties>
</component>
<component id="2b352" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="2" column="3" 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="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/down.jpg"/>
<text value=""/>
</properties>
</component>
<component id="84615" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="1" column="3" 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="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<horizontalTextPosition value="0"/>
<icon value="Resources/up.jpg"/>
<text value=""/>
</properties>
</component>
<component id="cfcfa" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="2" 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="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/left.jpg"/>
<text value=""/>
</properties>
</component>
<vspacer id="c1567">
<constraints>
<grid row="0" 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>
<hspacer id="b267f">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -0,0 +1,138 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
/**
* Форма, работающая с объектом "истребитель"
*/
public class FormAirFighter {
/**
* Поле-объект для отрисовки объекта
*/
private DrawningAirFighter _drawningAirFighter;
private JPanel PanelWrapper;
public JPanel getPanelWrapper() {
return PanelWrapper;
}
private JPanel PictureBox;
private JButton buttonCreate;
private JButton buttonUp;
private JButton buttonLeft;
private JButton buttonRight;
private JButton buttonDown;
private List<JComponent> controls;
/**
* Конструктор формы
*/
public FormAirFighter(){
buttonUp.setName("up");
buttonLeft.setName("left");
buttonRight.setName("right");
buttonDown.setName("down");
InitializeControlsRepaintList();
buttonCreate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_drawningAirFighter = new DrawningAirFighter();
Random random = new Random();
_drawningAirFighter.Init(random.nextInt(100,300), random.nextDouble(1000,3000), new Color(random.nextInt(256),
random.nextInt(256),random.nextInt(256)),
new Color(random.nextInt(256),random.nextInt(256),random.nextInt(256)),random.nextBoolean(), random.nextBoolean());
_drawningAirFighter.SetPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
_drawningAirFighter.SetPosition(random.nextInt(10,100),random.nextInt(10,100));
}
});
ActionListener buttonMoveClickedListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String buttonName = ((JButton) e.getSource()).getName();
boolean result = false;
switch (buttonName) {
case "buttonUp":
result = _drawningAirFighter.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawningAirFighter.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _drawningAirFighter.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _drawningAirFighter.MoveTransport(DirectionType.Right);
break;
}
if (result)
Draw();
}
};
buttonRight.addActionListener(buttonMoveClickedListener);
buttonDown.addActionListener(buttonMoveClickedListener);
buttonLeft.addActionListener(buttonMoveClickedListener);
buttonUp.addActionListener(buttonMoveClickedListener);
}
/**
* Метод прорисовки аэробуса
*/
private void Draw() {
if (_drawningAirFighter.getEntityAirFighter() == null) {
return;
}
Graphics g = PictureBox.getGraphics();
g.setColor(PictureBox.getBackground());
g.fillRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
_drawningAirFighter.DrawTransport(g);
RepaintControls();
}
/**
* Перерисовка кнопок
*/
private void RepaintControls() {
for (JComponent control : controls) {
control.repaint();
}
}
/**
* Обновление списка кнопок
*/
private void InitializeControlsRepaintList() {
controls = new LinkedList<>();
controls.add(buttonCreate);
controls.add(buttonUp);
controls.add(buttonLeft);
controls.add(buttonRight);
controls.add(buttonDown);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB