Лабораторная работа №1
This commit is contained in:
parent
d2bdb6802a
commit
7825ad417b
124
ProjectAirbus/.idea/uiDesigner.xml
generated
Normal file
124
ProjectAirbus/.idea/uiDesigner.xml
generated
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>
|
6
ProjectAirbus/src/DirectionType.java
Normal file
6
ProjectAirbus/src/DirectionType.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public enum DirectionType {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
}
|
162
ProjectAirbus/src/DrawningAirbus.java
Normal file
162
ProjectAirbus/src/DrawningAirbus.java
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawningAirbus {
|
||||||
|
private EntityAirbus entityAirbus;
|
||||||
|
|
||||||
|
public EntityAirbus getEntityAirbus() {
|
||||||
|
return entityAirbus;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer _pictureWidth;
|
||||||
|
private Integer _pictureHeight;
|
||||||
|
private Integer _startPosX;
|
||||||
|
private Integer _startPosY;
|
||||||
|
|
||||||
|
private final int _drawningAirbusWidth = 145;
|
||||||
|
private final int _drawningAirbusHeight = 50;
|
||||||
|
private DrawningAirbusPortholes _drawningAirbusPortholes;
|
||||||
|
|
||||||
|
public DrawningAirbus(int Speed, double Weight, Color BodyColor, Color AdditionalColor,
|
||||||
|
boolean AdditionalEngine, boolean PassengerCompartment) {
|
||||||
|
entityAirbus = new EntityAirbus(Speed, Weight, BodyColor, AdditionalColor, AdditionalEngine, PassengerCompartment);
|
||||||
|
_pictureWidth = null;
|
||||||
|
_pictureHeight = null;
|
||||||
|
_startPosX = null;
|
||||||
|
_startPosY = null;
|
||||||
|
_drawningAirbusPortholes = new DrawningAirbusPortholes(entityAirbus);
|
||||||
|
Random random = new Random();
|
||||||
|
int portholesCount = random.nextInt(1, 4);
|
||||||
|
_drawningAirbusPortholes.setPortholesCount(portholesCount * 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean SetPictureSize(int width, int height) {
|
||||||
|
if (width > _drawningAirbusWidth && height > _drawningAirbusHeight) {
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
|
||||||
|
if (_startPosX != null && _startPosY != null) {
|
||||||
|
if (_startPosX + _drawningAirbusWidth > _pictureWidth) {
|
||||||
|
_startPosX = _pictureWidth - _drawningAirbusWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_startPosY + _drawningAirbusHeight > _pictureHeight) {
|
||||||
|
_startPosY = _pictureHeight - _drawningAirbusHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(int x, int y) {
|
||||||
|
if (_pictureHeight == null || _pictureWidth == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
|
||||||
|
if (_startPosX + _drawningAirbusWidth > _pictureWidth) {
|
||||||
|
_startPosX = _pictureWidth - _drawningAirbusWidth;
|
||||||
|
}
|
||||||
|
if (_startPosY + _drawningAirbusHeight > _pictureHeight) {
|
||||||
|
_startPosY = _pictureHeight - _drawningAirbusHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean MoveTransport(DirectionType direction) {
|
||||||
|
if (entityAirbus == null || _startPosX == null || _startPosY == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (_startPosX - entityAirbus.getStep() > 0) {
|
||||||
|
_startPosX -= (int) entityAirbus.getStep();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_startPosY - entityAirbus.getStep() > 0) {
|
||||||
|
_startPosY -= (int) entityAirbus.getStep();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Right:
|
||||||
|
if (_startPosX + entityAirbus.getStep() < _pictureWidth - _drawningAirbusWidth) {
|
||||||
|
_startPosX += (int) entityAirbus.getStep();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (_startPosY + entityAirbus.getStep() < _pictureHeight - _drawningAirbusHeight) {
|
||||||
|
_startPosY += (int) entityAirbus.getStep();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTransport(Graphics g) {
|
||||||
|
if (entityAirbus == null || _startPosX == null || _startPosY == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
// дополнительный отсек для пассажиров
|
||||||
|
if (entityAirbus.withPassengerCompartment()) {
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.drawRect(_startPosX + 60, _startPosY + 10, 40, 10);
|
||||||
|
g2d.drawOval(_startPosX + 50, _startPosY + 10, 20, 20);
|
||||||
|
g2d.drawOval(_startPosX + 90, _startPosY + 10, 20, 20);
|
||||||
|
|
||||||
|
g2d.setColor(entityAirbus.getAdditionalColor());
|
||||||
|
g2d.fillRect(_startPosX + 60, _startPosY + 11, 40, 10);
|
||||||
|
g2d.fillOval(_startPosX + 50, _startPosY + 10, 20, 20);
|
||||||
|
g2d.fillOval(_startPosX + 90, _startPosY + 10, 20, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
//фюзеляж самолёта
|
||||||
|
int[] xPointsBorders = {_startPosX, _startPosX, _startPosX + 10, _startPosX + 120, _startPosX + 145, _startPosX + 120, _startPosX + 20};
|
||||||
|
int[] yPointsBorders = {_startPosY, _startPosY + 30, _startPosY + 40, _startPosY + 40, _startPosY + 30, _startPosY + 20, _startPosY + 20};
|
||||||
|
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.drawOval(_startPosX, _startPosY + 20, 20, 20);
|
||||||
|
g2d.drawPolygon(xPointsBorders, yPointsBorders, 7);
|
||||||
|
|
||||||
|
g2d.setColor(entityAirbus.getBodyColor());
|
||||||
|
g2d.fillOval(_startPosX, _startPosY + 20, 20, 20);
|
||||||
|
g2d.fillPolygon(xPointsBorders, yPointsBorders, 7);
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.drawLine(_startPosX + 120, _startPosY + 30, _startPosX + 145, _startPosY + 30);
|
||||||
|
g2d.drawLine(_startPosX + 120, _startPosY + 20, _startPosX + 120, _startPosY + 40);
|
||||||
|
|
||||||
|
//шасси
|
||||||
|
g2d.drawLine(_startPosX + 40, _startPosY + 40, _startPosX + 40, _startPosY + 44);
|
||||||
|
g2d.drawOval(_startPosX + 34, _startPosY + 44, 6, 6);
|
||||||
|
g2d.drawOval(_startPosX + 40, _startPosY + 44, 6, 6);
|
||||||
|
g2d.drawLine(_startPosX + 110, _startPosY + 40, _startPosX + 110, _startPosY + 44);
|
||||||
|
g2d.drawOval(_startPosX + 107, _startPosY + 44, 6, 6);
|
||||||
|
|
||||||
|
//двигатель в хвосте
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.fillOval(_startPosX, _startPosY + 15, 8, 8);
|
||||||
|
g2d.fillOval(_startPosX + 12, _startPosY + 15, 8, 8);
|
||||||
|
g2d.fillRect(_startPosX + 4, _startPosY + 15, 12, 8);
|
||||||
|
|
||||||
|
//иллюминаторы
|
||||||
|
_drawningAirbusPortholes.drawAirbusPortholes(g, Color.BLUE, _startPosX + 2, _startPosY + 25);
|
||||||
|
|
||||||
|
//дополнительный двигатель на крыле
|
||||||
|
if (entityAirbus.withAdditionalEngine()) {
|
||||||
|
g2d.fillOval(_startPosX + 48, _startPosY + 30, 8, 8);
|
||||||
|
g2d.fillOval(_startPosX + 60, _startPosY + 30, 8, 8);
|
||||||
|
g2d.fillRect(_startPosX + 52, _startPosY + 30, 12, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
//крыло
|
||||||
|
g2d.fillRect(_startPosX + 40, _startPosY + 28, 40, 4);
|
||||||
|
g2d.fillOval(_startPosX + 38, _startPosY + 28, 4, 4);
|
||||||
|
g2d.fillOval(_startPosX + 78, _startPosY + 28, 4, 4);
|
||||||
|
}
|
||||||
|
}
|
37
ProjectAirbus/src/DrawningAirbusPortholes.java
Normal file
37
ProjectAirbus/src/DrawningAirbusPortholes.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningAirbusPortholes {
|
||||||
|
private PortholesEnum _portholesEnum;
|
||||||
|
private EntityAirbus _entityAirbus;
|
||||||
|
|
||||||
|
public void setPortholesCount(int portholesCount) {
|
||||||
|
for (PortholesEnum value : PortholesEnum.values()) {
|
||||||
|
if (value.portholesEnumNumber == portholesCount) {
|
||||||
|
_portholesEnum = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawningAirbusPortholes(EntityAirbus entityAirbus) {
|
||||||
|
_entityAirbus = entityAirbus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawAirbusPortholes(Graphics g, Color color, float portholesStartPosX, float portholesStartPosY) {
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
int intervalBetweenPortholes = 120 / _portholesEnum.portholesEnumNumber;
|
||||||
|
|
||||||
|
for (int i = 0; i < _portholesEnum.portholesEnumNumber; i++) {
|
||||||
|
g2d.setColor(color);
|
||||||
|
int posX = (int)(portholesStartPosX + i * intervalBetweenPortholes);
|
||||||
|
drawPortholeKit(g2d, posX, (int)portholesStartPosY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawPortholeKit(Graphics2D g2d, int posX, int posY) {
|
||||||
|
g2d.setColor(Color.CYAN);
|
||||||
|
g2d.fillOval(posX, posY, 5, 5);
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.drawOval(posX, posY, 5, 5);
|
||||||
|
}
|
||||||
|
}
|
48
ProjectAirbus/src/EntityAirbus.java
Normal file
48
ProjectAirbus/src/EntityAirbus.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityAirbus {
|
||||||
|
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 AdditionalEngine;
|
||||||
|
public boolean withAdditionalEngine() {
|
||||||
|
return AdditionalEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean PassengerCompartment;
|
||||||
|
public boolean withPassengerCompartment() {
|
||||||
|
return PassengerCompartment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double Step;
|
||||||
|
public double getStep() {
|
||||||
|
return (double)Speed * 100 / Weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityAirbus(int Speed, double Weight, Color BodyColor, Color AdditionalColor,
|
||||||
|
boolean AdditionalEngine, boolean PassengerCompartment) {
|
||||||
|
this.Speed = Speed;
|
||||||
|
this.Weight = Weight;
|
||||||
|
this.BodyColor = BodyColor;
|
||||||
|
this.AdditionalColor = AdditionalColor;
|
||||||
|
this.AdditionalEngine = AdditionalEngine;
|
||||||
|
this.PassengerCompartment = PassengerCompartment;
|
||||||
|
}
|
||||||
|
}
|
89
ProjectAirbus/src/FormAirbus.form
Normal file
89
ProjectAirbus/src/FormAirbus.form
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormAirbus">
|
||||||
|
<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="758" height="523"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none" title=""/>
|
||||||
|
<children>
|
||||||
|
<grid id="39159" 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>
|
||||||
|
<vspacer id="2d93c">
|
||||||
|
<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="a271e" 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="1" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Создать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="62a86" 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>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="68896">
|
||||||
|
<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>
|
||||||
|
<component id="936f1" 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>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="1c141" 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>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="5175e" 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>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
113
ProjectAirbus/src/FormAirbus.java
Normal file
113
ProjectAirbus/src/FormAirbus.java
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormAirbus {
|
||||||
|
DrawningAirbus _drawningAirbus;
|
||||||
|
private JPanel PanelWrapper;
|
||||||
|
public JPanel getPanelWrapper() {
|
||||||
|
return PanelWrapper;
|
||||||
|
}
|
||||||
|
private JButton buttonCreate;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JPanel PictureBox;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private List<JComponent> controls;
|
||||||
|
|
||||||
|
public FormAirbus() {
|
||||||
|
buttonUp.setName("buttonUp");
|
||||||
|
buttonDown.setName("buttonDown");
|
||||||
|
buttonLeft.setName("buttonLeft");
|
||||||
|
buttonRight.setName("buttonRight");
|
||||||
|
|
||||||
|
InitializeControlsRepaintList();
|
||||||
|
|
||||||
|
buttonCreate.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Random random = new Random();
|
||||||
|
_drawningAirbus = new DrawningAirbus(random.nextInt(100, 300), random.nextInt(1000, 3000),
|
||||||
|
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||||
|
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||||
|
random.nextBoolean(), random.nextBoolean());
|
||||||
|
_drawningAirbus.SetPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
_drawningAirbus.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||||
|
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ActionListener buttonMoveClickListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String buttonName = ((JButton) e.getSource()).getName();
|
||||||
|
boolean result = false;
|
||||||
|
|
||||||
|
switch (buttonName) {
|
||||||
|
case "buttonUp": {
|
||||||
|
result = _drawningAirbus.MoveTransport(DirectionType.Up);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "buttonDown": {
|
||||||
|
result = _drawningAirbus.MoveTransport(DirectionType.Down);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "buttonLeft": {
|
||||||
|
result = _drawningAirbus.MoveTransport(DirectionType.Left);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "buttonRight": {
|
||||||
|
result = _drawningAirbus.MoveTransport(DirectionType.Right);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
buttonRight.addActionListener(buttonMoveClickListener);
|
||||||
|
buttonDown.addActionListener(buttonMoveClickListener);
|
||||||
|
buttonLeft.addActionListener(buttonMoveClickListener);
|
||||||
|
buttonUp.addActionListener(buttonMoveClickListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw() {
|
||||||
|
if (_drawningAirbus.getEntityAirbus() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics g = PictureBox.getGraphics();
|
||||||
|
g.setColor(PictureBox.getBackground());
|
||||||
|
g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
_drawningAirbus.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(buttonDown);
|
||||||
|
controls.add(buttonLeft);
|
||||||
|
controls.add(buttonRight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,14 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||||
|
JFrame frame = new JFrame("Аэробус");
|
||||||
|
frame.setContentPane(new FormAirbus().getPanelWrapper());
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setLocation(200, 200);
|
||||||
|
frame.pack();
|
||||||
|
frame.setSize(1000, 600);
|
||||||
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
10
ProjectAirbus/src/PortholesEnum.java
Normal file
10
ProjectAirbus/src/PortholesEnum.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
public enum PortholesEnum {
|
||||||
|
Ten(10),
|
||||||
|
Twenty(20),
|
||||||
|
Thirty(30);
|
||||||
|
|
||||||
|
public final int portholesEnumNumber;
|
||||||
|
PortholesEnum (int i) {
|
||||||
|
this.portholesEnumNumber = i;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user