PIbd-11_Zakharov_I.E._LabWork01_Hard #1
124
ProjectAirFighter/.idea/uiDesigner.xml
Normal file
124
ProjectAirFighter/.idea/uiDesigner.xml
Normal 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>
|
@ -3,6 +3,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/Resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
BIN
ProjectAirFighter/Resources/arrowDown.jpg
Normal file
BIN
ProjectAirFighter/Resources/arrowDown.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 943 B |
BIN
ProjectAirFighter/Resources/arrowLeft.jpg
Normal file
BIN
ProjectAirFighter/Resources/arrowLeft.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 932 B |
BIN
ProjectAirFighter/Resources/arrowRight.jpg
Normal file
BIN
ProjectAirFighter/Resources/arrowRight.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 935 B |
BIN
ProjectAirFighter/Resources/arrowUp.jpg
Normal file
BIN
ProjectAirFighter/Resources/arrowUp.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 923 B |
13
ProjectAirFighter/src/CountEngines.java
Normal file
13
ProjectAirFighter/src/CountEngines.java
Normal file
@ -0,0 +1,13 @@
|
||||
public enum CountEngines {
|
||||
Zero(0),
|
||||
Two(2),
|
||||
Four(4),
|
||||
Six(6);
|
||||
private int Count;
|
||||
public int getCount() {
|
||||
return Count;
|
||||
}
|
||||
CountEngines(int num){
|
||||
this.Count = num;
|
||||
}
|
||||
}
|
6
ProjectAirFighter/src/DirectionType.java
Normal file
6
ProjectAirFighter/src/DirectionType.java
Normal file
@ -0,0 +1,6 @@
|
||||
public enum DirectionType {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
}
|
137
ProjectAirFighter/src/DrawningAirFighter.java
Normal file
137
ProjectAirFighter/src/DrawningAirFighter.java
Normal file
@ -0,0 +1,137 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningAirFighter {
|
||||
private EntityAirFighter EntityAirFighter;
|
||||
public EntityAirFighter getEntityAirFighter() {
|
||||
return EntityAirFighter;
|
||||
}
|
||||
private Integer _pictureWidth;
|
||||
private Integer _pictureHeight;
|
||||
private Integer _startPosX;
|
||||
private Integer _startPosY;
|
||||
private int _drawningPlaneWidth = 150;
|
||||
private int _drawningPlaneHeight = 150;
|
||||
private DrawningEngines DrawningEngines;
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean extraWings, boolean rockets) {
|
||||
EntityAirFighter = new EntityAirFighter();
|
||||
EntityAirFighter.Init(speed, weight, bodyColor, additionalColor, extraWings, rockets);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
DrawningEngines = new DrawningEngines(EntityAirFighter);
|
||||
Random random = new Random();
|
||||
int Count = 2 * random.nextInt(4);
|
||||
DrawningEngines.SetCountEngines(Count);
|
||||
}
|
||||
public boolean SetPictureSize(int width, int height) {
|
||||
if (_drawningPlaneWidth > width || _drawningPlaneHeight > height) return false;
|
||||
if (_startPosX != null && _startPosY != null) {
|
||||
if (_startPosX < 0) { _startPosX = 0; }
|
||||
if (_startPosX + _drawningPlaneWidth > width) { _startPosX = width - _drawningPlaneWidth; }
|
||||
if (_startPosY < 0) { _startPosY = 0; }
|
||||
if (_startPosY + _drawningPlaneHeight > height) { _startPosY = height - _drawningPlaneHeight; }
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
public void SetPosition(int x, int y) {
|
||||
if (_pictureHeight == null || _pictureWidth == null) {
|
||||
return;
|
||||
}
|
||||
if (x + _drawningPlaneWidth > _pictureWidth || x < 0) {
|
||||
Random random = new Random();
|
||||
_startPosX = random.nextInt(_pictureWidth - _drawningPlaneWidth);
|
||||
}
|
||||
else {
|
||||
_startPosX = x;
|
||||
}
|
||||
|
||||
if (y + _drawningPlaneHeight > _pictureHeight || y < 0) {
|
||||
Random random = new Random();
|
||||
_startPosY = random.nextInt(_pictureHeight - _drawningPlaneHeight);
|
||||
}
|
||||
else {
|
||||
_startPosY = y;
|
||||
}
|
||||
}
|
||||
public boolean MoveTransport(DirectionType direction) {
|
||||
if (EntityAirFighter == null || _startPosX == null || _startPosY == null) {
|
||||
return false;
|
||||
}
|
||||
switch (direction) {
|
||||
case Left:
|
||||
if (_startPosX - EntityAirFighter.Step() > 0) {
|
||||
_startPosX -= (int)EntityAirFighter.Step();
|
||||
}
|
||||
return true;
|
||||
case Up:
|
||||
if (_startPosY - EntityAirFighter.Step() > 0) {
|
||||
_startPosY -= (int)EntityAirFighter.Step();
|
||||
}
|
||||
return true;
|
||||
case Right:
|
||||
if (_startPosX + EntityAirFighter.Step() + _drawningPlaneWidth < _pictureWidth) {
|
||||
_startPosX += (int)EntityAirFighter.Step();
|
||||
}
|
||||
return true;
|
||||
case Down:
|
||||
if (_startPosY + EntityAirFighter.Step() + _drawningPlaneHeight < _pictureHeight) {
|
||||
_startPosY += (int)EntityAirFighter.Step();
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics2D g) {
|
||||
if (EntityAirFighter == null || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
g.setColor(Color.BLACK);
|
||||
int[] pointX = {_startPosX, _startPosX + 20, _startPosX + 20, _startPosX};
|
||||
int[] pointY = {_startPosY + 75, _startPosY + 70, _startPosY + 80, _startPosY + 75};
|
||||
Polygon triangle = new Polygon(pointX, pointY, 4);
|
||||
g.fillPolygon(triangle);
|
||||
|
||||
g.setColor(EntityAirFighter.getBodyColor());
|
||||
g.fillRect(_startPosX + 20, _startPosY + 70, 130, 10);
|
||||
|
||||
g.drawLine(_startPosX + 40, _startPosY + 70, _startPosX + 40, _startPosY);
|
||||
g.drawLine(_startPosX + 40, _startPosY, _startPosX + 50, _startPosY);
|
||||
g.drawLine(_startPosX + 50, _startPosY, _startPosX + 55, _startPosY + 70);
|
||||
g.drawLine(_startPosX + 40, _startPosY + 80, _startPosX + 40, _startPosY + 150);
|
||||
g.drawLine(_startPosX + 40, _startPosY + 150, _startPosX + 50, _startPosY + 150);
|
||||
g.drawLine(_startPosX + 50, _startPosY + 150, _startPosX + 55, _startPosY + 80);
|
||||
|
||||
g.drawLine(_startPosX + 150, _startPosY + 70, _startPosX + 150, _startPosY + 55);
|
||||
g.drawLine(_startPosX + 150, _startPosY + 55, _startPosX + 135, _startPosY + 65);
|
||||
g.drawLine(_startPosX + 135, _startPosY + 65, _startPosX + 135, _startPosY + 70);
|
||||
g.drawLine(_startPosX + 150, _startPosY + 80, _startPosX + 150, _startPosY + 95);
|
||||
g.drawLine(_startPosX + 150, _startPosY + 95, _startPosX + 135, _startPosY + 85);
|
||||
g.drawLine(_startPosX + 135, _startPosY + 85, _startPosX + 135, _startPosY + 80);
|
||||
|
||||
DrawningEngines.DrawEngines(g, EntityAirFighter.getAdditionalColor(), _startPosX, _startPosY);
|
||||
g.setColor(EntityAirFighter.getAdditionalColor());
|
||||
|
||||
if (EntityAirFighter.getExtraWings()) {
|
||||
g.drawLine(_startPosX + 65, _startPosY + 70, _startPosX + 90, _startPosY + 20);
|
||||
g.drawLine(_startPosX + 90, _startPosY + 20, _startPosX + 110, _startPosY + 20);
|
||||
g.drawLine(_startPosX + 110, _startPosY + 20, _startPosX + 85, _startPosY + 70);
|
||||
g.drawLine(_startPosX + 65, _startPosY + 80, _startPosX + 90, _startPosY + 130);
|
||||
g.drawLine(_startPosX + 90, _startPosY + 130, _startPosX + 110, _startPosY + 130);
|
||||
g.drawLine(_startPosX + 110, _startPosY + 130, _startPosX + 85, _startPosY + 80);
|
||||
}
|
||||
|
||||
if (EntityAirFighter.getRockets()) {
|
||||
g.fillRect(_startPosX + 32, _startPosY + 4, 8, 6);
|
||||
g.drawLine(_startPosX + 32, _startPosY + 4, _startPosX + 26, _startPosY + 7);
|
||||
g.drawLine(_startPosX + 26, _startPosY + 7, _startPosX + 32, _startPosY + 10);
|
||||
g.fillRect(_startPosX + 32, _startPosY + 140, 8, 6);
|
||||
g.drawLine(_startPosX + 32, _startPosY + 146, _startPosX + 26, _startPosY + 143);
|
||||
g.drawLine(_startPosX + 26, _startPosY + 143, _startPosX + 32, _startPosY + 140);
|
||||
}
|
||||
}
|
||||
}
|
27
ProjectAirFighter/src/DrawningEngines.java
Normal file
27
ProjectAirFighter/src/DrawningEngines.java
Normal file
@ -0,0 +1,27 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningEngines {
|
||||
private CountEngines CountEngines;
|
||||
public CountEngines getCountEngines() {
|
||||
return CountEngines;
|
||||
}
|
||||
private EntityAirFighter EntityAirFighter;
|
||||
public void SetCountEngines(int countEngines) {
|
||||
for (CountEngines num : CountEngines.values()) {
|
||||
if (num.getCount() == countEngines) {
|
||||
CountEngines = num;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
public DrawningEngines(EntityAirFighter entityAirFighter) {
|
||||
EntityAirFighter = entityAirFighter;
|
||||
}
|
||||
public void DrawEngines(Graphics2D g, Color color, int x, int y) {
|
||||
g.setColor(color);
|
||||
for (int i = CountEngines.getCount(); i > 0; i -= 2) {
|
||||
g.fillOval(x + 35, y + 10 * i - 5, 10, 10);
|
||||
g.fillOval(x + 35, y + 145 - 10 * i, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
39
ProjectAirFighter/src/EntityAirFighter.java
Normal file
39
ProjectAirFighter/src/EntityAirFighter.java
Normal file
@ -0,0 +1,39 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAirFighter {
|
||||
private int Speed;
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
}
|
||||
private double Weight;
|
||||
public double getWeight() {
|
||||
return Weight;
|
||||
}
|
||||
private Color BodyColor;
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
private Color AdditionalColor;
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
private boolean ExtraWings;
|
||||
public boolean getExtraWings() {
|
||||
return ExtraWings;
|
||||
}
|
||||
private boolean Rockets;
|
||||
public boolean getRockets() {
|
||||
return Rockets;
|
||||
}
|
||||
public double Step() {
|
||||
return Speed * 100 / Weight;
|
||||
}
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean extraWings, boolean rockets) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
ExtraWings = extraWings;
|
||||
Rockets = rockets;
|
||||
}
|
||||
}
|
97
ProjectAirFighter/src/FormAirFighter.form
Normal file
97
ProjectAirFighter/src/FormAirFighter.form
Normal file
@ -0,0 +1,97 @@
|
||||
<?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="mainBox" 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="816" height="542"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="bfe57" binding="pictureBoxAirFighter" 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="1b3d8" class="javax.swing.JButton" binding="buttonCreateAirFighter">
|
||||
<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>
|
||||
<hspacer id="a279f">
|
||||
<constraints>
|
||||
<grid row="2" 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>
|
||||
<vspacer id="d2306">
|
||||
<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>
|
||||
<component id="ab717" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="false"/>
|
||||
<icon value="arrowLeft.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ed329" class="javax.swing.JButton" binding="buttonDown">
|
||||
<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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="false"/>
|
||||
<icon value="arrowDown.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2954a" class="javax.swing.JButton" binding="buttonRight">
|
||||
<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">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="false"/>
|
||||
<icon value="arrowRight.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7452e" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="false"/>
|
||||
<icon value="arrowUp.jpg"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
105
ProjectAirFighter/src/FormAirFighter.java
Normal file
105
ProjectAirFighter/src/FormAirFighter.java
Normal file
@ -0,0 +1,105 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
import java.util.List;
|
||||
|
||||
public class FormAirFighter {
|
||||
JPanel mainBox;
|
||||
private JPanel pictureBoxAirFighter;
|
||||
private JButton buttonCreateAirFighter;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonRight;
|
||||
private DrawningAirFighter _drawningAirFighter = new DrawningAirFighter();
|
||||
private List<JComponent> controls;
|
||||
public FormAirFighter() {
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
InitializeControlsRepaintList();
|
||||
|
||||
buttonCreateAirFighter.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_drawningAirFighter = new DrawningAirFighter();
|
||||
Random random = new Random();
|
||||
_drawningAirFighter.Init(random.nextInt(300) + 300,
|
||||
random.nextInt(1500) + 1500,
|
||||
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(pictureBoxAirFighter.getWidth(), pictureBoxAirFighter.getHeight());
|
||||
_drawningAirFighter.SetPosition(random.nextInt(100), random.nextInt(100));
|
||||
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
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 == null) {
|
||||
return;
|
||||
}
|
||||
Graphics g = pictureBoxAirFighter.getGraphics();
|
||||
g.setColor(pictureBoxAirFighter.getBackground());
|
||||
g.fillRect(0,0, pictureBoxAirFighter.getWidth(), pictureBoxAirFighter.getHeight());
|
||||
_drawningAirFighter.DrawTransport((Graphics2D) g);
|
||||
|
||||
RepaintControls();
|
||||
}
|
||||
private void RepaintControls() {
|
||||
for (JComponent control : controls) {
|
||||
control.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeControlsRepaintList() {
|
||||
controls = new LinkedList<>();
|
||||
controls.add(buttonCreateAirFighter);
|
||||
controls.add(buttonUp);
|
||||
controls.add(buttonDown);
|
||||
controls.add(buttonLeft);
|
||||
controls.add(buttonRight);
|
||||
}
|
||||
}
|
14
ProjectAirFighter/src/Main.java
Normal file
14
ProjectAirFighter/src/Main.java
Normal file
@ -0,0 +1,14 @@
|
||||
import javax.swing.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||
JFrame frame = new JFrame("FormSeaplane");
|
||||
frame.setContentPane(new FormAirFighter().mainBox);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(500, 200);
|
||||
frame.pack();
|
||||
frame.setSize(1000, 500);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user