Merge pull request 'Eliseev E.E. LabWork01' (#1) from LabWork01 into main

Reviewed-on: http://student.git.athene.tech/ElEgEv/PIbd-21_Eliseev_E.E._Airbus_Hard/pulls/1
This commit is contained in:
Евгений Эгов 2022-11-07 10:12:33 +04:00
commit 584a649a4b
14 changed files with 590 additions and 6 deletions

View File

@ -14,18 +14,18 @@
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<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.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="5ae821da-b40c-40e0-b119-6eb7c1c5f4cc" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/../../.idea/Hard.iml" beforeDir="false" afterPath="$PROJECT_DIR$/../../.idea/Hard.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../.idea/misc.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2H35pnpNG1e0131fjsCOoqYsTJr" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/.." />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="5ae821da-b40c-40e0-b119-6eb7c1c5f4cc" name="Changes" comment="" />
<created>1667501112705</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1667501112705</updated>
</task>
<servers />
</component>
</project>

View File

@ -0,0 +1,16 @@
public enum Additional_Enum {
One(1),
Two(2),
Three(3);
private final int addEnum;
Additional_Enum(int i)
{
this.addEnum = i;
}
public int GetAddEnum(){
return addEnum;
}
}

View File

@ -0,0 +1,17 @@
public enum Direction {
Up(1),
Down(2),
Left(3),
Right(4);
private final int DirectionCode;
private Direction(int directionCode)
{
this.DirectionCode = directionCode;
}
public int GetDirect(){
return DirectionCode;
}
}

View File

@ -0,0 +1,55 @@
import javax.swing.*;
import java.awt.*;
public class DrawingAirplaneWindow extends JComponent
{
private Additional_Enum _airplaneWindowEnum;
public void SetAddEnum(int decksAmount) {
for(Additional_Enum item : _airplaneWindowEnum.values())
{
if(item.GetAddEnum() == decksAmount)
{
_airplaneWindowEnum = item;
return;
}
}
}
public void DrawAirplaneWindow(Color colorWindow, Graphics g, float _startPosX, float _startPosY)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
switch(_airplaneWindowEnum.GetAddEnum())
{
case 1:
g2d.setPaint(colorWindow);
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
g2d.setPaint(Color.BLACK);
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
break;
case 2:
g2d.setPaint(colorWindow);
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
g2d.fillOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
g2d.setPaint(Color.BLACK);
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
g2d.drawOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
break;
case 3:
g2d.setPaint(colorWindow);
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
g2d.fillOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
g2d.fillOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
g2d.setPaint(Color.BLACK);
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
g2d.drawOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
g2d.drawOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
break;
}
}
}

View File

@ -0,0 +1,172 @@
import java.awt.*;
import java.awt.Color;
import java.util.Random;
public class DrawingPlane
{
public EntityPlane Airbus; //класс-сущность
public DrawingAirplaneWindow _airplaneWindow; //для дополнительной отрисовки
private float _startPosX; //левая координата отрисовки
private float _startPosY; //верхняя координата отрисовки
private Integer _pictureWidth = null; //ширина окна отрисовки
private Integer _pictureHeight = null; //высота окна отрисовки
protected final int _airbusWidth = 50; //ширина отрисовки самолёта
protected final int _airbusHeight = 16; //высота отрисовки самолёта
//инициализаци свойств
public void Initial(int speed, float weight, Color corpusColor)
{
Airbus = new EntityPlane();
Airbus.Initial(speed, weight, corpusColor);
_airplaneWindow = new DrawingAirplaneWindow();
SetAddEnum();
}
//установка кол-ва иллюминаторов
public void SetAddEnum()
{
Random rnd = new Random();
int countWindow = rnd.nextInt(1, 4);
_airplaneWindow.SetAddEnum(countWindow);
}
public EntityPlane GetPlane()
{
return Airbus;
}
//установка координат позиции самолёта
public void SetPosition(int x, int y, int width, int height)
{
if (x < 0 || y < 0 || width <= x + _airbusWidth || height <= y + _airbusHeight)
{
_pictureHeight = null;
_pictureWidth = null;
return;
}
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
//изменение направления движения
public void MoveTransport(Direction direction)
{
if (GetPlane() == null)
{
return;
}
switch (direction)
{
case Right: //вправо
if (_startPosX + _airbusWidth + Airbus.GetStep() < _pictureWidth)
{
_startPosX += Airbus.GetStep();
}
break;
case Left: //влево
if (_startPosX - _airbusWidth - Airbus.GetStep() > 0)
{
_startPosX -= Airbus.GetStep();
}
break;
case Up: //вверх
if (_startPosY - _airbusHeight - Airbus.GetStep() > 0)
{
_startPosY -= Airbus.GetStep();
}
break;
case Down: //вниз
if (_startPosY + _airbusHeight + Airbus.GetStep() < _pictureHeight)
{
_startPosY += Airbus.GetStep();
}
break;
}
}
public void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
{
return;
}
if(GetPlane() == null){
return;
}
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, _pictureWidth, _pictureHeight);
//заливает фигуру
g2d.setPaint(Color.BLACK);
//крыло
g2d.fillRect((int)_startPosX + 10, (int)_startPosY + 15, 20, 2);
g2d.fillRect((int)_startPosX + 12, (int)_startPosY + 17, 16, 2);
//заднее поперечное крыло
g2d.fillOval((int)_startPosX - 3, (int)_startPosY + 7, 10, 5);
//задние шасси
g2d.fillRect((int)_startPosX + 10, (int)_startPosY + 21, 2, 2);
g2d.fillRect((int)_startPosX + 12, (int)_startPosY + 23, 4, 4);
g2d.fillRect((int)_startPosX + 8, (int)_startPosY + 23, 2, 4);
//переднее шасси
g2d.fillRect((int)_startPosX + 35, (int)_startPosY + 21, 2, 2);
g2d.fillRect((int)_startPosX + 35, (int)_startPosY + 23, 4, 4);
g2d.setColor(Color.BLACK); //рисует контур
//корпус
g2d.drawRect((int)_startPosX, (int)_startPosY + 10, 40, 10);
//хвостовое крыло
g2d.drawLine((int)_startPosX, (int)_startPosY + 10, (int)_startPosX, (int)_startPosY);
g2d.drawLine((int)_startPosX, (int)_startPosY, (int)_startPosX + 10, (int)_startPosY + 10);
//нос самолёта
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 15, (int)_startPosX + 50, (int)_startPosY + 16);
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 10, (int)_startPosX + 47, (int)_startPosY + 15);
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 20, (int)_startPosX + 50, (int)_startPosY + 15);
//отрисовка иллюминаторов
_airplaneWindow.DrawAirplaneWindow(Airbus.GetColor(), g, _startPosX, _startPosY);
}
//смена границ формы отрисовки
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _airbusWidth || _pictureHeight <= _airbusHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _airbusWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _airbusWidth;
}
if (_startPosY + _airbusHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _airbusHeight;
}
}
}

View File

@ -0,0 +1,31 @@
import java.awt.*;
public class EntityPlane
{
public int Speed; //скорость
public int GetSpeed(){
return Speed;
}
public float Weight; //вес
public float GetWeight(){
return Weight;
}
public Color CorpusColor; //цвет корпуса
public Color GetColor(){
return CorpusColor;
}
//шаг перемещения самолёта
public float GetStep(){
return Speed * 100 / Weight;
}
public void Initial(int speed, float weight, Color corpusColor)
{
Speed = speed;
Weight = weight;
CorpusColor = corpusColor;
}
}

111
Project/src/FormPlane.form Normal file
View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormPlane">
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="42" width="864" height="483"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="67a15" class="javax.swing.JButton" binding="ButtonLeft">
<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="45" height="45"/>
<preferred-size width="45" height="45"/>
<maximum-size width="45" height="45"/>
</grid>
</constraints>
<properties>
<horizontalTextPosition value="0"/>
<text value=""/>
</properties>
</component>
<component id="b10a1" class="javax.swing.JButton" binding="ButtonRight">
<constraints>
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="45" height="45"/>
<preferred-size width="45" height="45"/>
<maximum-size width="45" height="45"/>
</grid>
</constraints>
<properties>
<horizontalTextPosition value="0"/>
<text value=""/>
</properties>
</component>
<hspacer id="5b756">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="a48b0" class="javax.swing.JButton" binding="ButtonCreate">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="100" height="25"/>
<preferred-size width="100" height="25"/>
<maximum-size width="100" height="25"/>
</grid>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<toolbar id="ede45" binding="StatusStrip">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="345" height="25"/>
<preferred-size width="345" height="25"/>
<maximum-size width="345" height="25"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</toolbar>
<grid id="b0c9a" binding="PictureBox" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<component id="51778" class="javax.swing.JButton" binding="ButtonDown">
<constraints>
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="45" height="45"/>
<preferred-size width="45" height="45"/>
<maximum-size width="45" height="45"/>
</grid>
</constraints>
<properties>
<horizontalTextPosition value="0"/>
<text value=""/>
</properties>
</component>
<component id="44002" class="javax.swing.JButton" binding="ButtonUp">
<constraints>
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="45" height="45"/>
<preferred-size width="45" height="45"/>
<maximum-size width="45" height="45"/>
</grid>
</constraints>
<properties>
<horizontalTextPosition value="11"/>
<text value=""/>
</properties>
</component>
<hspacer id="993b6">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="220" height="25"/>
<preferred-size width="220" height="25"/>
<maximum-size width="220" height="25"/>
</grid>
</constraints>
</hspacer>
</children>
</grid>
</form>

120
Project/src/FormPlane.java Normal file
View File

@ -0,0 +1,120 @@
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Random;
public class FormPlane
{
protected DrawingPlane plane = new DrawingPlane();
public JPanel MainPanel;
private JButton ButtonCreate;
private JButton ButtonLeft;
private JButton ButtonDown;
private JButton ButtonRight;
private JButton ButtonUp;
private JToolBar StatusStrip;
private JPanel PictureBox;
private JLabel LabelSpeed = new JLabel();
private JLabel LabelWeight = new JLabel();
private JLabel LabelColor = new JLabel();
public FormPlane()
{
//создание строки отображения скорости, веса и цвета объекта
Box LableBox = Box.createHorizontalBox();
LableBox.setMinimumSize(new Dimension(1, 20));
LableBox.add(LabelSpeed);
LableBox.add(LabelWeight);
LableBox.add(LabelColor);
StatusStrip.add(LableBox);
try
{
Image img = ImageIO.read(getClass().getResource("resourses/Up.png"));
ButtonUp.setIcon(new ImageIcon(img));
img = ImageIO.read(getClass().getResource("resourses/Left.png"));
ButtonLeft.setIcon(new ImageIcon(img));
img = ImageIO.read(getClass().getResource("resourses/Down.png"));
ButtonDown.setIcon(new ImageIcon(img));
img = ImageIO.read(getClass().getResource("resourses/Right.png"));
ButtonRight.setIcon(new ImageIcon(img));
} catch (Exception ex){
System.out.println(ex.getMessage());
}
ButtonCreate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
plane = new DrawingPlane();
Random rnd = new Random();
plane.Initial(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
PictureBox.getWidth(), PictureBox.getHeight());
LabelSpeed.setText("Скорость: " + plane.GetPlane().GetSpeed() + " ");
LabelWeight.setText("Вес: " + plane.GetPlane().GetWeight() + " ");
LabelColor.setText("Цвет: r = " + plane.GetPlane().GetColor().getRed() + " g = " + plane.GetPlane().GetColor().getGreen() +
" b = " + plane.GetPlane().GetColor().getBlue());
Draw();
}
});
//обновление размеров формы
MainPanel.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
plane.ChangeBorders(PictureBox.getWidth(), PictureBox.getHeight());
Draw();
}
});
ButtonUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
plane.MoveTransport(Direction.Up);
Draw();
}
});
ButtonLeft.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
plane.MoveTransport(Direction.Left);
Draw();
}
});
ButtonDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
plane.MoveTransport(Direction.Down);
Draw();
}
});
ButtonRight.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
plane.MoveTransport(Direction.Right);
Draw();
}
});
}
public void Draw()
{
if(plane.GetPlane() == null)
{
return;
}
plane.DrawTransport(PictureBox.getGraphics());
}
}

13
Project/src/Main.java Normal file
View File

@ -0,0 +1,13 @@
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("Airbus");
frame.setContentPane(new FormPlane().MainPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(500, 200);
frame.pack();
frame.setSize(1000, 500);
frame.setVisible(true);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB