Лабораторная работа №1 (усложненная)
@ -2,7 +2,9 @@
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/Seaplane/Resources" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
|
124
Seaplane/.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>
|
BIN
Seaplane/Resources/30px_arrow_down.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
Seaplane/Resources/30px_arrow_left.png
Normal file
After Width: | Height: | Size: 249 B |
BIN
Seaplane/Resources/30px_arrow_right.png
Normal file
After Width: | Height: | Size: 254 B |
BIN
Seaplane/Resources/30px_arrow_up.png
Normal file
After Width: | Height: | Size: 257 B |
BIN
Seaplane/Resources/arrowDown.jpg
Normal file
After Width: | Height: | Size: 61 KiB |
BIN
Seaplane/Resources/arrowLeft.jpg
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
Seaplane/Resources/arrowRight.jpg
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
Seaplane/Resources/arrowUp.jpg
Normal file
After Width: | Height: | Size: 61 KiB |
@ -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" />
|
||||
|
6
Seaplane/src/DirectionType.java
Normal file
@ -0,0 +1,6 @@
|
||||
public enum DirectionType {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
187
Seaplane/src/DrawingSeaplane.java
Normal file
@ -0,0 +1,187 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingSeaplane {
|
||||
private EntitySeaplane entitySeaplane;
|
||||
private Integer pictureWidth;
|
||||
private Integer pictureHeight;
|
||||
private Integer _startPosX;
|
||||
private Integer _startPosY;
|
||||
private final int drawingSeaplaneWidth = 190;
|
||||
private final int drawingSeaplaneHeight = 90;
|
||||
private final int drawingKeelHeight = 35;
|
||||
private DrawingSeaplanePortholes _drawingSeaplanePortholes;
|
||||
public EntitySeaplane EntitySeaplane() {
|
||||
return entitySeaplane;
|
||||
}
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean floats, boolean inflatableBoat) {
|
||||
entitySeaplane = new EntitySeaplane();
|
||||
entitySeaplane.Init(speed, weight, bodyColor, additionalColor, floats, inflatableBoat);
|
||||
pictureHeight = null;
|
||||
pictureWidth = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
_drawingSeaplanePortholes = new DrawingSeaplanePortholes(entitySeaplane);
|
||||
Random random = new Random();
|
||||
int paddlesCount = random.nextInt(1,4);
|
||||
_drawingSeaplanePortholes.setEnumNumber(paddlesCount * 10);
|
||||
}
|
||||
|
||||
public void setPictureSize(int width, int height) {
|
||||
pictureWidth = width;
|
||||
pictureHeight = height;
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
if (pictureHeight == null || pictureWidth == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
} else if (x - drawingSeaplaneWidth >= pictureWidth) {
|
||||
x = pictureWidth - drawingSeaplaneWidth - drawingSeaplaneWidth;
|
||||
}
|
||||
|
||||
if (y - drawingKeelHeight < 0) {
|
||||
y = drawingKeelHeight;
|
||||
} else if (y - drawingSeaplaneHeight >= pictureHeight) {
|
||||
y = pictureHeight - drawingSeaplaneHeight - drawingSeaplaneHeight;
|
||||
}
|
||||
|
||||
_startPosY = y;
|
||||
_startPosX = x;
|
||||
}
|
||||
|
||||
public boolean moveTransport(DirectionType direction) {
|
||||
if (entitySeaplane == null || _startPosX == null || _startPosY == null || pictureWidth == null || pictureHeight == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return switch (direction) {
|
||||
case Left -> {
|
||||
if (_startPosX - entitySeaplane.getStep() >= 0) {
|
||||
_startPosX -= (int) entitySeaplane.getStep();
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
case Up -> {
|
||||
if (_startPosY - drawingKeelHeight - entitySeaplane.getStep() >= 0) {
|
||||
_startPosY -= (int) entitySeaplane.getStep();
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
case Right -> {
|
||||
if (_startPosX + entitySeaplane.getStep() <= pictureWidth - drawingSeaplaneWidth) {
|
||||
_startPosX += (int) entitySeaplane.getStep();
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
case Down -> {
|
||||
if (_startPosY + entitySeaplane.getStep() <= pictureHeight - drawingSeaplaneHeight + drawingKeelHeight) {
|
||||
_startPosY += (int) entitySeaplane.getStep();
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
public void drawTransport(Graphics g) {
|
||||
if (entitySeaplane == null || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(Color.BLACK);
|
||||
// Отрисовка корпуса
|
||||
g2d.drawOval(_startPosX, _startPosY + 4, 20, 20);
|
||||
g2d.drawOval(_startPosX, _startPosY + 14, 20, 20);
|
||||
g2d.drawRect(_startPosX, _startPosY + 15, 10, 10);
|
||||
g2d.drawRect(_startPosX + 170, _startPosY + 15, 10, 10);
|
||||
g2d.drawRect(_startPosX + 10, _startPosY + 4, 160, 30);
|
||||
|
||||
// Отрисовка верхней части
|
||||
int[] xPointsTop = {_startPosX + 170, _startPosX + 170, _startPosX + 190};
|
||||
int[] yPointsTop = {_startPosY, _startPosY + 20, _startPosY + 20};
|
||||
g2d.drawPolygon(xPointsTop, yPointsTop, 3);
|
||||
|
||||
// Отрисовка нижней части
|
||||
int[] xPointsBottom = {_startPosX + 170, _startPosX + 170, _startPosX + 190};
|
||||
int[] yPointsBottom = {_startPosY + 40, _startPosY + 20, _startPosY + 20};
|
||||
g2d.drawPolygon(xPointsBottom, yPointsBottom, 3);
|
||||
|
||||
// Отрисовка киля
|
||||
int[] xPointsKeel = {_startPosX + 10, _startPosX + 10, _startPosX + 50};
|
||||
int[] yPointsKeel = {_startPosY - 30, _startPosY + 5, _startPosY + 5};
|
||||
g2d.drawPolygon(xPointsKeel, yPointsKeel, 3);
|
||||
|
||||
if (!entitySeaplane.getFloats())
|
||||
{
|
||||
// Рисуем переднее шасси с одним колесом
|
||||
g2d.drawOval( _startPosX + 140, _startPosY + 45, 10, 10);
|
||||
|
||||
// Рисуем задние шасси с двумя колесами
|
||||
g2d.drawOval( _startPosX + 20, _startPosY + 45, 10, 10);
|
||||
g2d.drawOval( _startPosX + 30, _startPosY + 45, 10, 10);
|
||||
|
||||
// Рисуем ногу переднего шасси
|
||||
g2d.drawLine( _startPosX + 145, _startPosY + 35, _startPosX + 145, _startPosY + 50);
|
||||
|
||||
// Рисуем ноги заднего шасси
|
||||
g2d.drawLine( _startPosX + 30, _startPosY + 35, _startPosX + 30, _startPosY + 50);
|
||||
}
|
||||
|
||||
g2d.setColor(entitySeaplane.getBodyColor());
|
||||
// Закрашиваем корпус
|
||||
g2d.fillOval(_startPosX, _startPosY + 4, 20, 20);
|
||||
g2d.fillOval(_startPosX, _startPosY + 14, 20, 20);
|
||||
g2d.fillOval(_startPosX, _startPosY + 15, 10, 10);
|
||||
g2d.fillRect(_startPosX + 10, _startPosY + 4, 160, 30);
|
||||
|
||||
g2d.setColor(entitySeaplane.getAdditionalColor());
|
||||
// Закрашиваем дополнительные элементы
|
||||
g2d.fillPolygon(xPointsTop, yPointsTop, 3);
|
||||
g2d.fillPolygon(xPointsBottom, yPointsBottom, 3);
|
||||
g2d.fillPolygon(xPointsKeel, yPointsKeel, 3);
|
||||
|
||||
_drawingSeaplanePortholes.drawSeaplanePortholes(g, Color.CYAN, _startPosX, _startPosY);
|
||||
|
||||
g2d.setColor(Color.BLACK);
|
||||
// Рисуем триммера
|
||||
g2d.drawOval( _startPosX, _startPosY, 10, 10);
|
||||
g2d.drawOval( _startPosX+30, _startPosY, 10, 10);
|
||||
g2d.drawRect( _startPosX+5, _startPosY, 30, 10);
|
||||
|
||||
// Рисуем крыло
|
||||
g2d.drawOval( _startPosX + 70, _startPosY + 15, 6, 6);
|
||||
g2d.drawOval( _startPosX + 130, _startPosY + 15, 6, 6);
|
||||
g2d.drawRect( _startPosX + 75, _startPosY + 15, 60, 6);
|
||||
|
||||
// Закрашиваем триммера
|
||||
g2d.fillOval( _startPosX, _startPosY, 10, 10);
|
||||
g2d.fillOval( _startPosX+30, _startPosY, 10, 10);
|
||||
g2d.fillRect( _startPosX+5, _startPosY, 30, 10);
|
||||
|
||||
// Закрашиваем крыло
|
||||
g2d.fillOval( _startPosX + 70, _startPosY + 15, 6, 6);
|
||||
g2d.fillOval( _startPosX + 130, _startPosY + 15, 6, 6);
|
||||
g2d.fillRect( _startPosX + 75, _startPosY + 15, 60, 6);
|
||||
|
||||
// Поплавки
|
||||
if (entitySeaplane.getFloats()) {
|
||||
g2d.drawLine(_startPosX + 125, _startPosY + 35, _startPosX + 125, _startPosY + 50);
|
||||
g2d.drawLine(_startPosX + 50, _startPosY + 35, _startPosX + 50, _startPosY + 50);
|
||||
g2d.fillOval(_startPosX + 40, _startPosY + 45, 10, 10);
|
||||
g2d.fillOval(_startPosX + 125, _startPosY + 45, 10, 10);
|
||||
g2d.fillRect(_startPosX + 45, _startPosY + 45, 85, 10);
|
||||
}
|
||||
g2d.setColor(Color.RED);
|
||||
// Надувная лодка
|
||||
if (entitySeaplane.getInflatableBoat()) {
|
||||
g2d.fillOval(_startPosX, _startPosY + 30, 8, 8);
|
||||
g2d.fillOval(_startPosX + 165, _startPosY + 30, 8, 8);
|
||||
g2d.fillRect(_startPosX + 4, _startPosY + 30, 165, 8);
|
||||
}
|
||||
}
|
||||
}
|
36
Seaplane/src/DrawingSeaplanePortholes.java
Normal file
@ -0,0 +1,36 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingSeaplanePortholes {
|
||||
private PortholesCount _portholesCount;
|
||||
private final EntitySeaplane _entitySeaplane;
|
||||
public DrawingSeaplanePortholes(EntitySeaplane entitySeaplane) {
|
||||
_entitySeaplane = entitySeaplane;
|
||||
}
|
||||
|
||||
public void setEnumNumber(int portholesCount) {
|
||||
for (PortholesCount value : PortholesCount.values()) {
|
||||
if (value.enumNumber == portholesCount) {
|
||||
_portholesCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawSeaplanePortholes(Graphics g, Color color, float startPosX, float startPosY) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setStroke(new BasicStroke(1));
|
||||
int distanceBetweenPortholes = (_portholesCount.enumNumber == 20) ? 7 : 20 - _portholesCount.enumNumber / 2;
|
||||
|
||||
for (int i = 0; i < _portholesCount.enumNumber; i++) {
|
||||
g2d.setColor(color);
|
||||
int posX = (int)(startPosX + i * distanceBetweenPortholes);
|
||||
drawPortholeBundle(g2d, posX, (int)startPosY + 5);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPortholeBundle(Graphics2D g2d, int posX, int posY) {
|
||||
g2d.fillOval(posX + 10, posY + 6, 5, 5); // Рисуем иллюминатор
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(posX + 10, posY + 6, 5, 5); // Рисуем границу иллюминатора
|
||||
}
|
||||
}
|
46
Seaplane/src/EntitySeaplane.java
Normal file
@ -0,0 +1,46 @@
|
||||
import java.awt.*;
|
||||
public class EntitySeaplane {
|
||||
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 double Step;
|
||||
public double getStep() {
|
||||
return (double)Speed * 100 / Weight;
|
||||
}
|
||||
|
||||
private boolean Floats;
|
||||
public boolean getFloats() {
|
||||
return Floats;
|
||||
}
|
||||
|
||||
private boolean InflatableBoat;
|
||||
public boolean getInflatableBoat() {
|
||||
return InflatableBoat;
|
||||
}
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean floats, boolean inflatableBoat) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Floats = floats;
|
||||
InflatableBoat = inflatableBoat;
|
||||
}
|
||||
}
|
93
Seaplane/src/FormSeaplane.form
Normal file
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormSeaplane">
|
||||
<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="818" height="610"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="805b0" 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="6925e" 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>
|
||||
<hspacer id="1c97f">
|
||||
<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="3a7db">
|
||||
<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="ed42c" 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>
|
||||
<icon value="30px_arrow_right.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b5d88" 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>
|
||||
<icon value="30px_arrow_left.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d16d8" 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>
|
||||
<icon value="30px_arrow_down.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a9a25" 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>
|
||||
<icon value="30px_arrow_up.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
107
Seaplane/src/FormSeaplane.java
Normal file
@ -0,0 +1,107 @@
|
||||
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 FormSeaplane {
|
||||
protected DrawingSeaplane _drawningSeaplane = new DrawingSeaplane();
|
||||
JPanel PanelWrapper;
|
||||
private JPanel PictureBox;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonUp;
|
||||
|
||||
private List<JComponent> controls;
|
||||
public FormSeaplane() {
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
InitializeControlsRepaintList();
|
||||
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_drawningSeaplane = new DrawingSeaplane();
|
||||
Random random = new Random();
|
||||
_drawningSeaplane.Init(random.nextInt(30, 100),
|
||||
random.nextInt(100, 500),
|
||||
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() );
|
||||
_drawningSeaplane.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
||||
_drawningSeaplane.setPosition(random.nextInt(35, 100),
|
||||
random.nextInt(35, 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 = _drawningSeaplane.moveTransport(DirectionType.Up);
|
||||
}
|
||||
break;
|
||||
case "buttonDown": {
|
||||
result = _drawningSeaplane.moveTransport(DirectionType.Down);
|
||||
}
|
||||
break;
|
||||
case "buttonLeft": {
|
||||
result = _drawningSeaplane.moveTransport(DirectionType.Left);
|
||||
}
|
||||
break;
|
||||
case "buttonRight": {
|
||||
result = _drawningSeaplane.moveTransport(DirectionType.Right);
|
||||
}
|
||||
break;
|
||||
|
||||
};
|
||||
|
||||
if (result) {
|
||||
Draw();
|
||||
};
|
||||
};
|
||||
};
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
|
||||
}
|
||||
private void Draw() {
|
||||
if (_drawningSeaplane.EntitySeaplane() == null) {
|
||||
return;
|
||||
}
|
||||
Graphics g = PictureBox.getGraphics();
|
||||
g.setColor(PictureBox.getBackground());
|
||||
g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
_drawningSeaplane.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 static void main(String[] args) {
|
||||
|
||||
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||
JFrame frame = new JFrame("FormSeaplane");
|
||||
frame.setContentPane(new FormSeaplane().PanelWrapper);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(500, 200);
|
||||
frame.pack();
|
||||
frame.setSize(1000, 500);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
8
Seaplane/src/PortholesCount.java
Normal file
@ -0,0 +1,8 @@
|
||||
public enum PortholesCount {
|
||||
Ten(10),
|
||||
Twenty(20),
|
||||
Thirty(30);
|
||||
|
||||
public final int enumNumber;
|
||||
PortholesCount(int i) {this.enumNumber = i;}
|
||||
}
|