Compare commits

...

18 Commits
main ... Lab3

Author SHA1 Message Date
artur-kalimullin
b78de3d146 Готово! 2024-06-17 11:13:01 +04:00
artur-kalimullin
ab48eac425 правка 2024-06-16 21:56:53 +04:00
artur-kalimullin
a5fe686016 Merge remote-tracking branch 'origin/Lab3' into Lab3 2024-06-16 13:49:26 +04:00
artur-kalimullin
916ebee85d Последняя правка 2024-06-16 13:48:57 +04:00
artur-kalimullin
7924f3a68e Конец 2024-06-16 13:47:27 +04:00
artur-kalimullin
c432bf98b7 Конец 2024-06-16 13:43:13 +04:00
artur-kalimullin
23058f6672 Готово 2024-06-16 00:33:20 +04:00
artur-kalimullin
e714e00fdb Почти готово 2024-06-15 20:40:11 +04:00
artur-kalimullin
c51d279cf8 воркинг 2024-05-22 01:06:16 +04:00
artur-kalimullin
021b810748 Лабараторная работа №3(начало) 2024-05-22 01:05:19 +04:00
artur-kalimullin
53693d9d08 Последняя правка 2024-05-21 20:30:45 +04:00
artur-kalimullin
fba2fe80be Лабораторная работа №2 2024-05-21 19:42:45 +04:00
artur-kalimullin
8945d1c2cc Лабораторная работа №2 2024-05-21 19:38:36 +04:00
artur-kalimullin
471fd18960 Убрал одинаковый код 2024-04-23 23:38:33 +04:00
artur-kalimullin
ae2b1c951d Правка 2024-04-23 22:58:43 +04:00
artur-kalimullin
ded836d6bb Правка 2024-04-10 21:19:01 +04:00
artur-kalimullin
d8ef359431 Чистота 2024-04-10 20:43:46 +04:00
artur-kalimullin
6028922e21 Lab1 2024-04-10 20:27:17 +04:00
75 changed files with 1783 additions and 0 deletions

View File

@ -3,6 +3,7 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/ProjectAirFighter/Resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/ProjectAirFighter/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />

124
.idea/uiDesigner.xml Normal file
View File

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

View File

@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 965 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1005 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 978 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1012 B

View File

@ -0,0 +1,58 @@
package CollectionGenericObjects;
import Drawnings.DrawningAirCraft;
import java.awt.*;
import java.util.Random;
public abstract class AbstractCompany {
protected final int _placeSizeWidth = 100;
protected final int _placeSizeHeight = 86;
protected final int _pictureWidth;
protected final int _pictureHeight;
protected ICollectionGenericObjects<DrawningAirCraft> _collection = null;
public int getMaxCount() {
return _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
}
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAirCraft> collection) {
this._pictureWidth = picWidth;
this._pictureHeight = picHeight;
this._collection = collection;
int maxCount = getMaxCount();
_collection.setMaxCount(maxCount);
}
public static int add(AbstractCompany company ,DrawningAirCraft airCraft) {
if (company._collection == null) {
return -1;
}
return company._collection.insert(airCraft);
}
public static DrawningAirCraft remove(AbstractCompany company, int position) {
if (company._collection == null) {
return null;
}
return company._collection.remove(position);
}
public DrawningAirCraft getRandomObject() {
if (_collection == null) {
return null;
}
Random rnd = new Random();
return _collection.get(rnd.nextInt(0, _collection.getCount() + 1));
}
public void show(Graphics g) {
drawBackground(g);
setObjectsPosition();
if (_collection == null) {
return;
}
for(int i = 0; i < _collection.getCount(); i++) {
if(_collection.get(i) != null) {
_collection.get(i).drawAirCraft(g);
}
}
}
protected abstract void drawBackground(Graphics g);
protected abstract void setObjectsPosition();
}

View File

@ -0,0 +1,53 @@
package CollectionGenericObjects;
import Drawnings.DrawningAirCraft;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class AirCraftAngar extends AbstractCompany {
private final List<Point> locCoord = new ArrayList<>();
int pamat_i = 0;
int pamat_j = 0;
public AirCraftAngar(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAirCraft> collection) {
super(picWidth, picHeight, collection);
_collection.setMaxCount(30);
}
@Override
protected void drawBackground(Graphics g) {
Color backgroundColor = new Color(255, 255, 255);
g.setColor(backgroundColor);
g.fillRect(0, 0, _pictureWidth, _pictureHeight);
g.setColor(Color.black);
((Graphics2D) g).setStroke(new BasicStroke(4));
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) {
pamat_i = i;
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) {
pamat_j = j;
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, (int) (_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j);
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth, _placeSizeHeight * (j + 1));
}
g.drawLine(i * _placeSizeWidth, _placeSizeHeight * (_pictureHeight / _placeSizeHeight), (int) (_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight));
}
}
@Override
protected void setObjectsPosition() {
if (locCoord == null || _collection == null) {
return;
}
int currentIndex = -1;
for (int j = pamat_j; j >= 0; j--) {
for (int i = pamat_i; i >= 0; i--) {
currentIndex++;
if (_collection.get(currentIndex) == null) continue;
_collection.get(currentIndex).setPictureSize(_pictureWidth, _pictureHeight);
_collection.get(currentIndex).setPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5);
}
}
}
}

View File

@ -0,0 +1,53 @@
package CollectionGenericObjects;
import Drawnings.DrawningAirCraft;
import Drawnings.DrawningAirFighter;
import Drawnings.IDrawEngine;
import Entities.EntityAirCraft;
import Entities.EntityAirFighter;
import java.util.ArrayList;
import java.util.Random;
public class Constructor<T extends EntityAirCraft, U extends IDrawEngine> {
private ArrayList<T> entitiesList = new ArrayList<>();
private ArrayList<U> engineList = new ArrayList<>();
public void addAirCraft(T obj) {
entitiesList.add(obj);
}
public void addAirCraft(U obj) {
engineList.add(obj);
}
public DrawningAirCraft getRandomAirCraft() {
Random rnd = new Random();
int entityIndex = rnd.nextInt(0, 3);
int engineIndex = rnd.nextInt(0, 3);
T entity = entitiesList.get(entityIndex);
U engine = engineList.get(engineIndex);
return (entity instanceof EntityAirFighter) ?
new DrawningAirFighter((EntityAirFighter) entity, engine) :
new DrawningAirCraft(entity, engine);
}
public String getEntityDescription(int index) {
if (index < 0 || index >= entitiesList.size()) {
return null;
}
T entity = entitiesList.get(index);
String entityClassName = (entity instanceof EntityAirFighter) ? "EntityAirFighter" : "EntityAirCraft";
return String.format("<html><i><u>%s</u></i> = %s</html>", entityClassName, entity);
}
public String getEngineDescription(int index) {
if (index < 0 || index >= engineList.size()) {
return null;
}
return engineList.get(index).toString();
}
}

View File

@ -0,0 +1,17 @@
package CollectionGenericObjects;
import Drawnings.DrawningAirCraft;
public interface ICollectionGenericObjects<T extends DrawningAirCraft> {
int getCount();
void setMaxCount(int count);
int insert(T obj);
int insert(T obj, int index);
T remove(int index);
T get(int index);
}

View File

@ -0,0 +1,90 @@
package CollectionGenericObjects;
import Drawnings.DrawningAirCraft;
import java.util.ArrayList;
public class MassiveGenericObjects<T extends DrawningAirCraft> implements ICollectionGenericObjects<T> {
private ArrayList<T> _collection;
public MassiveGenericObjects() {
_collection = new ArrayList<>();
}
int maxCount = 0;
int realSize = 0;
@Override
public int getCount() {
return _collection.size();
}
@Override
public int insert(T obj) {
return insert(obj, 0);
}
@Override
public int insert(T obj, int position) {
if (position > maxCount|| position < 0) {
return -1;
}
for (int i = position; i < maxCount; i++) {
if (_collection.get(i) == null) {
_collection.set(i, obj);
realSize++;
return i;
}
}
for (int i = position; i > 0; i--) {
if (_collection.get(i) == null) {
_collection.set(i, obj);
realSize++;
return i;
}
}
return -1;
}
@Override
public T remove(int position) {
if (position < 0 || position >= maxCount) {
return null;
}
if (_collection.get(position) != null) {
T bf = _collection.get(position);
_collection.set(position, null);
--realSize;
return bf;
}
return null;
}
@Override
public T get(int position) {
if (position >= 0 && position < _collection.size()) {
return _collection.get(position);
}
else {
return null;
}
}
@Override
public void setMaxCount(int count) {
if (count > 0) {
if (!_collection.isEmpty()) {
ArrayList<T> bfLoc = new ArrayList<>(count);
bfLoc.addAll(0, _collection);
_collection = bfLoc;
for (int i = 0; i < count - maxCount; i++) {
_collection.add(null);
}
} else {
_collection = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
_collection.add(null);
}
}
maxCount = count;
}
}
}

View File

@ -0,0 +1,125 @@
package Drawnings;
import CollectionGenericObjects.AbstractCompany;
import CollectionGenericObjects.AirCraftAngar;
import CollectionGenericObjects.MassiveGenericObjects;
import Forms.FormAirFighter;
import Forms.FormConstructor;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.util.Random;
public class DrawningAbstractCompany extends JComponent {
private AbstractCompany _company = null;
public void collectionComboBox_SelectedIndexChanged(JComboBox<String> obj, int width, int height) {
switch (obj.getSelectedIndex()) {
case 1:
_company = new AirCraftAngar(width, height, new MassiveGenericObjects<DrawningAirCraft>());
break;
default:
break;
}
}
public void createObject(int type, JFrame obj) {
if (_company == null) {
return;
}
DrawningAirCraft _drawningAirCraft;
Random random = new Random();
switch (type) {
case 0:
_drawningAirCraft = new DrawningAirCraft(random.nextInt(30, 100), random.nextInt(100,500),
getColorR(obj, random), random.nextInt(3));
break;
case 1:
_drawningAirCraft = new DrawningAirFighter(random.nextInt(30, 100), random.nextInt(100,500),
getColorR(obj, random), random.nextInt(3),
getColorR(obj, random),
random.nextBoolean(), random.nextBoolean());
break;
default:
return;
}
if (AbstractCompany.add(_company, _drawningAirCraft) != -1) {
JOptionPane.showMessageDialog(obj, "Объект добавлен");
}
else {
JOptionPane.showMessageDialog(obj, "Не удалось добавить объект");
}
}
Color getColorR(JFrame obj, Random rnd) {
Color color = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256));
if (obj == null) {
return color;
}
JColorChooser colorChooser = new JColorChooser();
colorChooser.setColor(color);
return JColorChooser.showDialog(obj, "Выберите цвет", color);
}
public void deleteButtonAction(int val, Frame obj) {
if (_company == null) {
return;
}
int result = JOptionPane.showConfirmDialog(
obj,
"Удалить объект?",
"Подтверждение",
JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
if (AbstractCompany.remove(_company, val) != null) {
JOptionPane.showMessageDialog(obj, "Выполнено");
} else {
JOptionPane.showMessageDialog(obj, "Удаление не удалось");
}
}
}
public void goToCheckButtonAction() {
if (_company == null) {
return;
}
DrawningAirCraft airCraft = null;
int counter = 100;
while (airCraft == null && counter > 0) {
airCraft = _company.getRandomObject();
--counter;
}
if (airCraft == null) {
return;
}
FormAirFighter formAirFighter = new FormAirFighter();
formAirFighter.setDrawningAirCraft(airCraft);
formAirFighter.OpenFrame();
}
private DrawningAirCraft createObject;
public void getObjFromConstructor(JFrame obj) {
if (_company == null) {
return;
}
FormConstructor formConstructor = new FormConstructor();
formConstructor.OpenFrame();
formConstructor.getAddButton().addActionListener(e -> {
createObject = formConstructor.getConstructor().getObj();
if (AbstractCompany.add(_company, createObject) != -1) {
JOptionPane.showMessageDialog(obj, "Выполнено");
} else {
JOptionPane.showMessageDialog(obj, "Добавление не удалось");
}
obj.repaint();
formConstructor.getjFrameConstructor().dispatchEvent(new WindowEvent(formConstructor.getjFrameConstructor(), WindowEvent.WINDOW_CLOSING));
});
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (_company == null) {
return;
}
_company.show(g);
}
}

View File

@ -0,0 +1,207 @@
package Drawnings;
import Entities.*;
import MovementStrategy.*;
import java.awt.*;
import java.util.Random;
public class DrawningAirCraft {
public Entities.EntityAirCraft entityAirCraft;
public EntityAirCraft getEntityAirCraft() {
return entityAirCraft;
}
private Integer _pictureWidth;
private Integer _pictureHeight;
protected Integer _startPosX;
protected Integer _startPosY;
private int _drawingAirCraftWidth = 66;
private int _drawingAirCraftHeight = 74;
public Integer GetPosX() {
return _startPosX;
}
public Integer GetPosY() {
return _startPosY;
}
public int GetWidth() {
return _drawingAirCraftWidth;
}
public int GetHeight() {
return _drawingAirCraftHeight;
}
public IDrawEngine drawEngine;
public DrawningAirCraft(int speed, float weight, Color bodyColor, int engineType) {
entityAirCraft = new EntityAirCraft(speed, weight, bodyColor);
_startPosY = null;
_startPosX = null;
_pictureWidth = null;
_pictureHeight = null;
switch (engineType) {
case 0:
drawEngine = new DrawningEngine();
break;
case 1:
drawEngine = new DrawningOvalEngine();
break;
case 2:
drawEngine = new DrawningLongEngine();
break;
}
Random random = new Random();
int[] countengine = {2, 4, 6};
int engineCount = countengine[random.nextInt(countengine.length)];
drawEngine.setNumber(engineCount);
}
protected DrawningAirCraft(int speed, float weight, Color bodyColor, int EngineType, int aircraftWidth, int aircraftHeight) {
this(speed, weight, bodyColor, EngineType);
_drawingAirCraftHeight = aircraftHeight;
_drawingAirCraftWidth = aircraftWidth;
}
public DrawningAirCraft(EntityAirCraft _entityAirCraft, IDrawEngine _drawEngine) {
entityAirCraft = _entityAirCraft;
drawEngine = _drawEngine;
}
public void setPosition(int x, int y) {
if (_pictureHeight == null || _pictureWidth == null)
return;
_startPosX = x;
_startPosY = y;
if (_drawingAirCraftWidth + x > _pictureWidth || x < 0) {
_startPosX = 0;
}
if (_drawingAirCraftHeight + y > _pictureHeight || y < 0) {
_startPosY = 0;
}
}
public boolean setPictureSize(int width, int height) {
if (_drawingAirCraftHeight > height || _drawingAirCraftWidth > width)
return false;
_pictureHeight = height;
_pictureWidth = width;
if (_startPosX != null && _startPosY != null) {
if (_startPosX + _drawingAirCraftWidth > width)
_startPosX = width - _drawingAirCraftWidth;
if (_startPosY + _drawingAirCraftHeight > height)
_startPosY = height - _drawingAirCraftHeight;
}
return true;
}
public boolean moveTransport(MovementDirection direction) {
if (entityAirCraft == null || _pictureWidth == null || _pictureHeight == null)
return false;
switch (direction) {
case MovementDirection.Left:
if (_startPosX - entityAirCraft.getStep() > 0)
_startPosX -= (int) entityAirCraft.getStep();
return true;
case MovementDirection.Up:
if (_startPosY - entityAirCraft.getStep() > 0)
_startPosY -= (int) entityAirCraft.getStep();
return true;
case MovementDirection.Right:
if (_startPosX + entityAirCraft.getStep() < _pictureWidth - _drawingAirCraftWidth)
_startPosX += (int) entityAirCraft.getStep();
return true;
case MovementDirection.Down:
if (_startPosY + entityAirCraft.getStep() < _pictureHeight - _drawingAirCraftHeight)
_startPosY += (int) entityAirCraft.getStep();
return true;
default:
return false;
}
}
public void drawAirCraft(Graphics g) {
if (entityAirCraft == null || _startPosX == null || _startPosY == null) {
return;
}
Graphics2D g2d = (Graphics2D) g;
Point[] rtail = new Point[]{
new Point(_startPosX+2, _startPosY + 25),
new Point(_startPosX+2, _startPosY + 8),
new Point(_startPosX + 10, _startPosY + 17),
new Point(_startPosX + 10, _startPosY + 25),
};
Polygon rtailPolygon = new Polygon();
for (Point point : rtail)
rtailPolygon.addPoint(point.x, point.y);
g2d.setColor(entityAirCraft.getBodyColor());
g2d.fillPolygon(rtailPolygon);
Point[] ltail = new Point[]{
new Point(_startPosX+2, _startPosY + 49),
new Point(_startPosX+2, _startPosY + 66),
new Point(_startPosX + 10, _startPosY + 57),
new Point(_startPosX + 10, _startPosY + 49),
};
Polygon ltailPolygon = new Polygon();
for (Point point : ltail)
ltailPolygon.addPoint(point.x, point.y);
g2d.setColor(entityAirCraft.getBodyColor());
g2d.fillPolygon(ltailPolygon);
Point[] rwing = new Point[]{
new Point(_startPosX + 35, _startPosY + 49),
new Point(_startPosX + 35, _startPosY + 74),
new Point(_startPosX + 27, _startPosY + 74),
new Point(_startPosX + 20, _startPosY + 49),
};
Polygon rwingPolygon = new Polygon();
for (Point point : rwing)
rwingPolygon.addPoint(point.x, point.y);
g2d.setColor(entityAirCraft.getBodyColor());
g2d.fillPolygon(rwingPolygon);
Point[] lwing = new Point[]{
new Point(_startPosX + 35, _startPosY + 25),
new Point(_startPosX + 35, _startPosY),
new Point(_startPosX + 27, _startPosY),
new Point(_startPosX + 20, _startPosY + 25),
};
Polygon lwingPolygon = new Polygon();
for (Point point : lwing)
lwingPolygon.addPoint(point.x, point.y);
g2d.setColor(entityAirCraft.getBodyColor());
g2d.fillPolygon(lwingPolygon);
g2d.drawRect(_startPosX , _startPosY + 24, 50, 25);
g2d.fillRect(_startPosX , _startPosY + 24, 50, 25);
Point[] nose = new Point[]{
new Point(_startPosX + 50, _startPosY + 26),
new Point(_startPosX + 66, _startPosY + 37),
new Point(_startPosX + 50, _startPosY + 48),
};
Polygon nosePolygon = new Polygon();
for (Point point : nose)
nosePolygon.addPoint(point.x, point.y);
g2d.setColor(Color.GRAY);
g2d.fillPolygon(nosePolygon);
drawEngine.drawEngine(g2d, entityAirCraft.getBodyColor(), _startPosX, _startPosY);
}
}

View File

@ -0,0 +1,83 @@
package Drawnings;
import Entities.EntityAirFighter;
import java.awt.*;
public class DrawningAirFighter extends DrawningAirCraft {
public DrawningAirFighter(int speed, float weight, Color bodyColor, int engineType, Color additionalColor, boolean pgo, boolean rockets) {
super(speed, weight, bodyColor, engineType, 76, 80);
entityAirCraft = new EntityAirFighter(speed, weight, bodyColor, additionalColor, pgo, rockets);
}
public DrawningAirFighter(EntityAirFighter entity, IDrawEngine engine) {
super(entity, engine);
}
public void drawAirCraft(Graphics g) {
if (entityAirCraft == null|| !(entityAirCraft instanceof EntityAirFighter entityAirFighter) || _startPosX == null || _startPosY == null) {
return;
}
super.drawAirCraft(g);
Graphics2D g2d = (Graphics2D) g;
if (entityAirFighter.getPgo()) {
Point[] pgo1 = new Point[]{
new Point(_startPosX + 40, _startPosY + 25),
new Point(_startPosX + 40, _startPosY + 15),
new Point(_startPosX + 45, _startPosY + 25),
};
Polygon pgo1Polygon = new Polygon();
for (Point point : pgo1)
pgo1Polygon.addPoint(point.x, point.y);
g2d.setColor(entityAirFighter.getAdditionalColor());
g2d.fillPolygon(pgo1Polygon);
Point[] pgo2 = new Point[]{
new Point(_startPosX + 40, _startPosY + 49),
new Point(_startPosX + 40, _startPosY + 59),
new Point(_startPosX + 45, _startPosY + 49),
};
Polygon pgo2Polygon = new Polygon();
for (Point point : pgo2)
pgo2Polygon.addPoint(point.x, point.y);
g2d.setColor(entityAirFighter.getAdditionalColor());
g2d.fillPolygon(pgo2Polygon);
}
if (entityAirFighter.getRockets()) {
Point[] rocket1 = new Point[]{
new Point(_startPosX + 40, _startPosY + 71),
new Point(_startPosX + 40, _startPosY + 74),
new Point(_startPosX + 45, _startPosY + 69),
new Point(_startPosX + 40, _startPosY + 64),
};
Polygon rocket1Polygon = new Polygon();
for (Point point : rocket1)
rocket1Polygon.addPoint(point.x, point.y);
g2d.setColor(entityAirFighter.getAdditionalColor());
g2d.fillPolygon(rocket1Polygon);
g.drawRect(_startPosX + 35, _startPosY + 67, 5, 4);
g.fillRect(_startPosX + 35, _startPosY + 67, 5, 4);
Point[] rocket2 = new Point[]{
new Point(_startPosX + 40, _startPosY + 7),
new Point(_startPosX + 40, _startPosY + 10),
new Point(_startPosX + 45, _startPosY + 5),
new Point(_startPosX + 40, _startPosY),
};
Polygon rocket2Polygon = new Polygon();
for (Point point : rocket2)
rocket2Polygon.addPoint(point.x, point.y);
g2d.setColor(entityAirFighter.getAdditionalColor());
g2d.fillPolygon(rocket2Polygon);
g.drawRect(_startPosX + 35, _startPosY + 3, 5, 4);
g.fillRect(_startPosX + 35, _startPosY + 3, 5, 4);
}
}
}

View File

@ -0,0 +1,78 @@
package Drawnings;
import CollectionGenericObjects.Constructor;
import Entities.EntityAirCraft;
import Entities.EntityAirFighter;
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class DrawningConstructor extends JComponent {
Constructor<EntityAirCraft, IDrawEngine> constructor = new Constructor<>();
private DrawningAirCraft obj;
public DrawningAirCraft getObj() {
return obj;
}
public DrawningConstructor() {
for (int i = 0; i < 3; i++) {
EntityAirCraft _entityAirCraft = null;
IDrawEngine _drawEngine = null;
Random rnd = new Random();
int Type = rnd.nextInt(3);
switch (Type) {
case 0:
_drawEngine = new DrawningEngine();
break;
case 1:
_drawEngine = new DrawningOvalEngine();
break;
case 2:
_drawEngine = new DrawningLongEngine();
break;
}
int[] countengine = {2, 4, 6};
int engineCount = countengine[rnd.nextInt(countengine.length)];
_drawEngine.setNumber(engineCount);
int typeAir = rnd.nextInt(0,2);
switch (typeAir) {
case 0:
_entityAirCraft = new EntityAirCraft(rnd.nextInt(70 - 30) + 30, rnd.nextInt(500 - 100) + 100,
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
break;
case 1:
_entityAirCraft = new EntityAirFighter(rnd.nextInt(70 - 30) + 30, rnd.nextInt(500 - 100) + 100,
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
rnd.nextBoolean(), rnd.nextBoolean());
break;
}
constructor.addAirCraft(_entityAirCraft);
constructor.addAirCraft(_drawEngine);
}
obj = constructor.getRandomAirCraft();
}
public void reCreateObj() {
obj = constructor.getRandomAirCraft();
}
public String getEntityString(int index) {
return constructor.getEntityDescription(index);
}
public String getEngineString(int index) {
return constructor.getEngineDescription(index);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (obj != null) {
obj.setPosition(10, 30);
obj.setPictureSize(350, 300);
obj.drawAirCraft(g);
}
super.repaint();
}
}

View File

@ -0,0 +1,44 @@
package Drawnings;
import java.awt.*;
public class DrawningEngine implements IDrawEngine {
private EngineCount _engineCount;
@Override
public void setNumber(int engineCount) {
for (EngineCount value : EngineCount.values()) {
if (value.getEnumNumber() == engineCount) {
_engineCount = value;
return;
}
}
}
@Override
public void drawEngine(Graphics2D g2d, Color color, int _startX, int _startY) {
g2d.setColor(color);
g2d.setStroke(new BasicStroke(4));
if (_engineCount.getEnumNumber() >= 2){
g2d.drawRect(_startX + 30, _startY + 69, 10, 2 );
g2d.drawRect(_startX + 30, _startY + 3, 10, 2 );
}
if (_engineCount.getEnumNumber() >= 4){
g2d.drawRect(_startX + 30, _startY + 62, 10, 2 );
g2d.drawRect(_startX + 30, _startY + 10, 10, 2 );
}
if (_engineCount.getEnumNumber() >= 6){
g2d.drawRect(_startX + 30, _startY + 55, 10, 2 );
g2d.drawRect(_startX + 30, _startY + 17, 10, 2 );
}
}
@Override
public String toString() {
String buffer = "";
buffer += "Тип: обычные, Количество двигателей: " + _engineCount.getEnumNumber();
return buffer;
}
}

View File

@ -0,0 +1,69 @@
package Drawnings;
import MovementStrategy.*;
import javax.swing.*;
import java.awt.*;
public class DrawningFormAirFighter extends JComponent {
DrawningAirCraft drawningAirCraft;
private int _pictureHeight = -1;
private int _pictureWidth = -1;
private AbstractStrategy _strategy;
public void setDrawningAirCraft(DrawningAirCraft drawningAirCraft) {
this.drawningAirCraft = drawningAirCraft;
}
public boolean setPictureSize(int width, int height) {
if (drawningAirCraft.GetHeight() > height || drawningAirCraft.GetWidth() > width)
return false;
_pictureHeight = height;
_pictureWidth = width;
return true;
}
public void buttonStrategyStep(JComboBox<String> comboBox) {
if (drawningAirCraft == null)
return;
if (comboBox.isEnabled()) {
switch (comboBox.getSelectedIndex()) {
case 0:
_strategy = new MoveToCenter();
break;
case 1:
_strategy = new MoveToBorder();
break;
default:
_strategy = null;
break;
}
if (_strategy == null) {
return;
}
_strategy.SetData(new MoveableAirCraft(drawningAirCraft), _pictureWidth, _pictureHeight);
}
if (_strategy == null) {
return;
}
comboBox.setEnabled(false);
_strategy.MakeStep();
if (_strategy.GetStatus() == StrategyStatus.Finish) {
comboBox.setEnabled(true);
_strategy = null;
}
}
public void MoveButtonsAction(MovementDirection direction) {
if (drawningAirCraft == null)
return;
drawningAirCraft.moveTransport(direction);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (drawningAirCraft == null) {
return;
}
drawningAirCraft.drawAirCraft(g);
}
}

View File

@ -0,0 +1,44 @@
package Drawnings;
import java.awt.*;
public class DrawningLongEngine implements IDrawEngine {
private EngineCount _engineCount;
@Override
public void setNumber(int engineCount) {
for (EngineCount value : EngineCount.values()) {
if (value.getEnumNumber() == engineCount) {
_engineCount = value;
return;
}
}
}
@Override
public void drawEngine(Graphics2D g2d, Color color, int _startX, int _startY) {
g2d.setColor(color);
g2d.setStroke(new BasicStroke(4));
if (_engineCount.getEnumNumber() >= 2) {
g2d.drawRoundRect(_startX + 25, _startY + 69, 15, 2, 5, 5);
g2d.drawRoundRect(_startX + 25, _startY + 3, 15, 2, 5, 5);
}
if (_engineCount.getEnumNumber() >= 4) {
g2d.drawRoundRect(_startX + 25, _startY + 62, 15, 2, 5, 5);
g2d.drawRoundRect(_startX + 25, _startY + 10, 15, 2, 5, 5);
}
if (_engineCount.getEnumNumber() >= 6) {
g2d.drawRoundRect(_startX + 25, _startY + 55, 15, 2, 5, 5);
g2d.drawRoundRect(_startX + 25, _startY + 17, 15, 2, 5, 5);
}
}
@Override
public String toString() {
String buffer = "";
buffer += "Тип: длиные, Количество двигателей: " + _engineCount.getEnumNumber();
return buffer;
}
}

View File

@ -0,0 +1,44 @@
package Drawnings;
import java.awt.*;
public class DrawningOvalEngine implements IDrawEngine {
private EngineCount _engineCount;
@Override
public void setNumber(int engineCount) {
for (EngineCount value : EngineCount.values()) {
if (value.getEnumNumber() == engineCount) {
_engineCount = value;
return;
}
}
}
@Override
public void drawEngine(Graphics2D g2d, Color color, int _startX, int _startY) {
g2d.setColor(color);
g2d.setStroke(new BasicStroke(4));
if (_engineCount.getEnumNumber() >= 2) {
g2d.drawOval(_startX + 30, _startY + 69, 10, 2);
g2d.drawOval(_startX + 30, _startY + 3, 10, 2);
}
if (_engineCount.getEnumNumber() >= 4) {
g2d.drawOval(_startX + 30, _startY + 62, 10, 2);
g2d.drawOval(_startX + 30, _startY + 10, 10, 2);
}
if (_engineCount.getEnumNumber() >= 6) {
g2d.drawOval(_startX + 30, _startY + 55, 10, 2);
g2d.drawOval(_startX + 30, _startY + 17, 10, 2);
}
}
@Override
public String toString() {
String buffer = "";
buffer += "Тип: овальные, Количество двигателей: " + _engineCount.getEnumNumber();
return buffer;
}
}

View File

@ -0,0 +1,14 @@
package Drawnings;
public enum EngineCount {
Two(2),
Three(4),
Four(6);
final private int EnumNumber;
EngineCount(int enumNumber) {
EnumNumber = enumNumber;
}
public int getEnumNumber() {
return EnumNumber;
}
}

View File

@ -0,0 +1,8 @@
package Drawnings;
import java.awt.*;
public interface IDrawEngine {
void setNumber(int x);
void drawEngine(Graphics2D graphics2D, Color color, int _startX, int _startY);
}

View File

@ -0,0 +1,38 @@
package Entities;
import java.awt.*;
public class EntityAirCraft {
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 double Step;
public double getStep() {
return Speed*100/Weight;
}
public EntityAirCraft(int speed, double weight, Color bodyColor) {
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
@Override
public String toString() {
String buffer = "";
buffer += "Скорость: " + this.Speed;
buffer += ", Вес: " + this.Weight;
buffer += String.format(", Основной цвет : RGB{%d, %d, %d}",
this.BodyColor.getRed(), this.BodyColor.getGreen(), this.BodyColor.getBlue());
return buffer;
}
}

View File

@ -0,0 +1,34 @@
package Entities;
import java.awt.*;
public class EntityAirFighter extends EntityAirCraft {
private Color AdditionalColor;
public Color getAdditionalColor() {
return AdditionalColor;
}
private boolean Pgo;
public boolean getPgo() {
return Pgo;
}
private boolean Rockets;
public boolean getRockets() {
return Rockets;
}
public EntityAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, boolean pgo, boolean rockets) {
super(speed, weight, bodyColor);
AdditionalColor = additionalColor;
Pgo = pgo;
Rockets = rockets;
}
@Override
public String toString() {
String buffer = super.toString();
buffer += String.format(", Дополнительный цвет : RGB{%d, %d, %d}",
this.AdditionalColor.getRed(), this.AdditionalColor.getGreen(), this.AdditionalColor.getBlue());
buffer += ", ПГО: " + this.Pgo;
buffer += ", Ракеты: " + this.Rockets;
return buffer;
}
}

View File

@ -0,0 +1,161 @@
package Forms;
import Drawnings.DrawningAbstractCompany;
import javax.swing.*;
import javax.swing.text.NumberFormatter;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.text.NumberFormat;
public class FormAirCraftCollection extends JFrame {
final private JFrame jFrameCollectionAirCraft = new JFrame();
final private DrawningAbstractCompany _company = new DrawningAbstractCompany();
final private JButton refreshButton = new JButton("Обновить");
final private JPanel refreshPanel = new JPanel();
final private String[] listOfComboBox = {
"",
"Хранилище"
};
final private JComboBox<String> comboBoxSelectorCompany = new JComboBox<>(listOfComboBox);
final private JPanel comboBoxPanel = new JPanel();
final private JPanel toolsPanel = new JPanel();
final private JLabel toolsNameLabel = new JLabel("Инструменты");
final private JPanel labelPanel = new JPanel();
final private JButton buttonAddAirCraft = new JButton("Добавить самолёт");
final private JButton buttonAddAirFighter = new JButton("Добавить истребитель");
final private JPanel addAirCraftPanel = new JPanel();
final private JPanel addAirFighterPanel = new JPanel();
final private JButton buttonRemove = new JButton("Удалить самолёт");
final private JPanel removePanel = new JPanel();
final private JButton goToCheckButton = new JButton("Отправить на тесты");
final private JPanel goToCheckPanel = new JPanel();
final private JPanel addFromConstructorPanel = new JPanel();
final private JButton addFromConstructorButton = new JButton("Добавить из конструктора");
public void OpenFrame() {
jFrameCollectionAirCraft.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Toolkit tolls = Toolkit.getDefaultToolkit();
Dimension dimension = tolls.getScreenSize();
jFrameCollectionAirCraft.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
1200, 665);
jFrameCollectionAirCraft.setTitle("Коллекция самолётов");
toolsPanel.setBackground(Color.BLACK);
labelPanel.setSize(new Dimension(100, 20));
labelPanel.add(toolsNameLabel);
comboBoxPanel.setLayout(new BorderLayout());
comboBoxPanel.setSize(new Dimension(130, 30));
comboBoxPanel.add(comboBoxSelectorCompany, BorderLayout.CENTER);
addAirCraftPanel.setLayout(new BorderLayout());
addAirCraftPanel.setSize(170, 40);
addAirCraftPanel.add(buttonAddAirCraft, BorderLayout.CENTER);
addAirFighterPanel.setLayout(new BorderLayout());
addAirFighterPanel.setSize(170, 40);
addAirFighterPanel.add(buttonAddAirFighter, BorderLayout.CENTER);
removePanel.setLayout(new BorderLayout());
removePanel.setSize(170, 40);
removePanel.add(buttonRemove, BorderLayout.CENTER);
goToCheckPanel.setLayout(new BorderLayout());
goToCheckPanel.setSize(170, 40);
goToCheckPanel.add(goToCheckButton, BorderLayout.CENTER);
refreshPanel.setLayout(new BorderLayout());
refreshPanel.setSize(170, 40);
refreshPanel.add(refreshButton, BorderLayout.CENTER);
addFromConstructorPanel.setLayout(new BorderLayout());
addFromConstructorPanel.setSize(170, 40);
addFromConstructorPanel.add(addFromConstructorButton, BorderLayout.CENTER);
NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(0);
formatter.setMaximum(100);
formatter.setAllowsInvalid(true);
formatter.setCommitsOnValidEdit(true);
JTextField textBoxPosition = new JFormattedTextField(formatter);
JPanel textBoxPanel = new JPanel();
textBoxPanel.setLayout(new BorderLayout());
textBoxPanel.setSize(170, 40);
textBoxPanel.add(textBoxPosition, BorderLayout.CENTER);
jFrameCollectionAirCraft.add(toolsPanel);
jFrameCollectionAirCraft.add(labelPanel);
jFrameCollectionAirCraft.add(comboBoxPanel);
jFrameCollectionAirCraft.add(addAirCraftPanel);
jFrameCollectionAirCraft.add(addAirFighterPanel);
jFrameCollectionAirCraft.add(textBoxPanel);
jFrameCollectionAirCraft.add(removePanel);
jFrameCollectionAirCraft.add(goToCheckPanel);
jFrameCollectionAirCraft.add(refreshPanel);
jFrameCollectionAirCraft.add(addFromConstructorPanel);
jFrameCollectionAirCraft.add(_company);
jFrameCollectionAirCraft.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent componentEvent) {
labelPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 210, 0);
toolsPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 233, 0);
comboBoxPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 30);
addAirCraftPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 70);
addAirFighterPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 120);
textBoxPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 220);
removePanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 260);
goToCheckPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 300);
refreshPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 340);
addFromConstructorPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 170);
toolsPanel.setSize(new Dimension(10, jFrameCollectionAirCraft.getHeight()));
jFrameCollectionAirCraft.repaint();
}
});
comboBoxSelectorCompany.addActionListener(e -> {
_company.collectionComboBox_SelectedIndexChanged(comboBoxSelectorCompany,
jFrameCollectionAirCraft.getWidth() - 233, jFrameCollectionAirCraft.getHeight());
jFrameCollectionAirCraft.repaint();
});
buttonAddAirCraft.addActionListener(e -> {
_company.createObject(0, jFrameCollectionAirCraft);
jFrameCollectionAirCraft.repaint();
});
buttonAddAirFighter.addActionListener(e -> {
_company.createObject(1, jFrameCollectionAirCraft);
jFrameCollectionAirCraft.repaint();
});
buttonRemove.addActionListener(e -> {
if (!textBoxPosition.getText().isEmpty()) {
if (Integer.parseInt(textBoxPosition.getText()) <= 99
&& Integer.parseInt(textBoxPosition.getText()) >= 0) {
int pos = Integer.parseInt(textBoxPosition.getText());
_company.deleteButtonAction(pos, jFrameCollectionAirCraft);
}
}
jFrameCollectionAirCraft.repaint();
});
refreshButton.addActionListener(e -> {
jFrameCollectionAirCraft.repaint();
});
goToCheckButton.addActionListener(e -> {
_company.goToCheckButtonAction();
jFrameCollectionAirCraft.repaint();
});
addFromConstructorButton.addActionListener(e -> {
_company.getObjFromConstructor(jFrameCollectionAirCraft);
});
jFrameCollectionAirCraft.setVisible(true);
}
}

View File

@ -0,0 +1,112 @@
package Forms;
import Drawnings.*;
import MovementStrategy.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
public class FormAirFighter extends JFrame {
final private JFrame JFrameAirFighter = new JFrame();
final private JButton buttonRight = new JButton(new ImageIcon("ProjectAirFighter\\Resources\\arrowRight.png"));
final private JPanel RightPanel = new JPanel();
final private JButton buttonDown = new JButton(new ImageIcon("ProjectAirFighter\\Resources\\arrowDown.png"));
final private JPanel DownPanel = new JPanel();
final private JButton buttonLeft = new JButton(new ImageIcon("ProjectAirFighter\\Resources\\arrowLeft.png"));
final private JPanel LeftPanel = new JPanel();
final private JButton buttonUp = new JButton(new ImageIcon("ProjectAirFighter\\Resources\\arrowUp.png"));
final private JPanel UpPanel = new JPanel();
final private String [] itemsComboBox = {
"К центру",
"К краю"
};
final private JComboBox<String> comboBoxStrategy =new JComboBox<>(itemsComboBox);
final private JButton buttonStrategyStep = new JButton("Шаг");
final private JPanel StrategyPanel = new JPanel(new BorderLayout());
final private DrawningFormAirFighter form = new DrawningFormAirFighter();
public void setDrawningAirCraft(DrawningAirCraft airCraft) {form.setDrawningAirCraft(airCraft);}
public void OpenFrame() {
JFrameAirFighter.setVisible(true);
Toolkit tolls = Toolkit.getDefaultToolkit();
Dimension dimension = tolls.getScreenSize();
JFrameAirFighter.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
970, 700);
JFrameAirFighter.setTitle("Истребитель");
comboBoxStrategy.setPreferredSize(new Dimension(100, 35));
buttonStrategyStep.setPreferredSize(new Dimension(100, 35));
StrategyPanel.setSize(100, 70);
StrategyPanel.add(comboBoxStrategy, BorderLayout.NORTH);
StrategyPanel.add(buttonStrategyStep, BorderLayout.SOUTH);
UpPanel.setSize(30, 30);
buttonUp.setPreferredSize(new Dimension(30, 30));
UpPanel.add(buttonUp, BorderLayout.CENTER);
DownPanel.setSize(30, 30);
buttonDown.setPreferredSize(new Dimension(30, 30));
DownPanel.add(buttonDown, BorderLayout.CENTER);
RightPanel.setSize(30, 30);
buttonRight.setPreferredSize(new Dimension(30, 30));
RightPanel.add(buttonRight, BorderLayout.CENTER);
LeftPanel.setSize(30, 30);
buttonLeft.setPreferredSize(new Dimension(30, 30));
LeftPanel.add(buttonLeft, BorderLayout.CENTER);
JFrameAirFighter.add(StrategyPanel);
JFrameAirFighter.add(UpPanel);
JFrameAirFighter.add(DownPanel);
JFrameAirFighter.add(RightPanel);
JFrameAirFighter.add(LeftPanel);
JFrameAirFighter.add(form);
JFrameAirFighter.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
StrategyPanel.setLocation(JFrameAirFighter.getWidth() - 100, 0);
UpPanel.setLocation(JFrameAirFighter.getWidth() - 80, JFrameAirFighter.getHeight()-100);
DownPanel.setLocation(JFrameAirFighter.getWidth() - 80, JFrameAirFighter.getHeight()-70);
RightPanel.setLocation(JFrameAirFighter.getWidth() - 45, JFrameAirFighter.getHeight()-70);
LeftPanel.setLocation(JFrameAirFighter.getWidth() - 115, JFrameAirFighter.getHeight()-70);
form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight());
JFrameAirFighter.repaint();
}
});
buttonUp.addActionListener(e -> {
form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight());
form.MoveButtonsAction(MovementDirection.Up);
JFrameAirFighter.repaint();
});
buttonDown.addActionListener(e -> {
form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight());
form.MoveButtonsAction(MovementDirection.Down);
JFrameAirFighter.repaint();
});
buttonLeft.addActionListener(e -> {
form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight());
form.MoveButtonsAction(MovementDirection.Left);
JFrameAirFighter.repaint();
});
buttonRight.addActionListener(e -> {
form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight());
form.MoveButtonsAction(MovementDirection.Right);
JFrameAirFighter.repaint();
});
buttonStrategyStep.addActionListener(e -> {
form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight());
form.buttonStrategyStep(comboBoxStrategy);
JFrameAirFighter.repaint();
});
}
}

View File

@ -0,0 +1,90 @@
package Forms;
import Drawnings.DrawningConstructor;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
public class FormConstructor extends JFrame {
private JFrame jFrameConstructor = new JFrame();
public JFrame getjFrameConstructor() {
return jFrameConstructor;
}
private JButton addButton = new JButton("Добавить объект");
public JButton getAddButton() {
return addButton;
}
public JButton reCreateButton = new JButton("Пересоздать");
private final DrawningConstructor constructor = new DrawningConstructor();
public DrawningConstructor getConstructor() {
return constructor;
}
JPanel entitiesInfoPanel = new JPanel();
JLabel firstEntityLabel = new JLabel();
JLabel secondEntityLabel = new JLabel();
JLabel thirdEntityLabel = new JLabel();
JPanel engineInfoPanel = new JPanel();
JLabel firstEngineLabel = new JLabel();
JLabel secondEngineLabel = new JLabel();
JLabel thirdEngineLabel = new JLabel();
public void OpenFrame() {
Toolkit tolls = Toolkit.getDefaultToolkit();
Dimension dimension = tolls.getScreenSize();
jFrameConstructor.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
800, 300);
jFrameConstructor.setLayout(new BorderLayout());
firstEntityLabel.setText(constructor.getEntityString(0));
secondEntityLabel.setText(constructor.getEntityString(1));
thirdEntityLabel.setText(constructor.getEntityString(2));
entitiesInfoPanel.setLayout(new BoxLayout(entitiesInfoPanel, BoxLayout.Y_AXIS));
entitiesInfoPanel.setBorder(BorderFactory.createTitledBorder("Entities"));
entitiesInfoPanel.setSize(500, 130);
entitiesInfoPanel.setLocation(150, 10);
entitiesInfoPanel.add(firstEntityLabel);
entitiesInfoPanel.add(secondEntityLabel);
entitiesInfoPanel.add(thirdEntityLabel);
firstEngineLabel.setText(constructor.getEngineString(0));
secondEngineLabel.setText(constructor.getEngineString(1));
thirdEngineLabel.setText(constructor.getEngineString(2));
engineInfoPanel.setLayout(new BoxLayout(engineInfoPanel, BoxLayout.Y_AXIS));
engineInfoPanel.setBorder(BorderFactory.createTitledBorder("Engine"));
engineInfoPanel.setSize(500, 130);
engineInfoPanel.setLocation(150, 150);
engineInfoPanel.add(firstEngineLabel);
engineInfoPanel.add(secondEngineLabel);
engineInfoPanel.add(thirdEngineLabel);
addButton.setBounds(0, jFrameConstructor.getHeight() - 105, 150, 50);
reCreateButton.setBounds(0, jFrameConstructor.getHeight() - 135, 150, 30);
jFrameConstructor.add(engineInfoPanel);
jFrameConstructor.add(entitiesInfoPanel);
jFrameConstructor.add(addButton);
jFrameConstructor.add(reCreateButton);
jFrameConstructor.add(constructor);
jFrameConstructor.revalidate();
jFrameConstructor.repaint();
jFrameConstructor.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent componentEvent) {
addButton.setLocation(0, jFrameConstructor.getSize().height - 105);
reCreateButton.setLocation(0, jFrameConstructor.getSize().height - 135);
}
});
reCreateButton.addActionListener(e -> {
constructor.reCreateObj();
jFrameConstructor.repaint();
});
jFrameConstructor.setVisible(true);
}
}

View File

@ -1,4 +1,7 @@
import Forms.FormAirCraftCollection;
public class Main {
public static void main(String[] args) {
FormAirCraftCollection formAirCraftCollection = new FormAirCraftCollection();
formAirCraftCollection.OpenFrame();
}
}

View File

@ -0,0 +1,66 @@
package MovementStrategy;
public abstract class AbstractStrategy {
private IMoveableObject _moveableObject;
private StrategyStatus _state = StrategyStatus.NotInit;
protected int FieldWidth;
protected int FieldHeight;
public StrategyStatus GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
{
_state = StrategyStatus.NotInit;
return;
}
_state = StrategyStatus.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != StrategyStatus.InProgress)
{
return;
}
if (IsTargetDestination())
{
_state = StrategyStatus.Finish;
return;
}
MoveToTarget();
}
protected boolean MoveLeft() { return MoveTo(MovementDirection.Left); }
protected boolean MoveRight() { return MoveTo(MovementDirection.Right); }
protected boolean MoveUp() { return MoveTo(MovementDirection.Up); }
protected boolean MoveDown() { return MoveTo(MovementDirection.Down); }
protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); }
protected int GetStep()
{
if (_state != StrategyStatus.InProgress)
{
return 0;
}
return _moveableObject.GetStep();
}
protected abstract void MoveToTarget();
protected abstract boolean IsTargetDestination();
private boolean MoveTo(MovementDirection directionType)
{
if (_state != StrategyStatus.InProgress)
{
return false;
}
if (_moveableObject.TryMoveObject(directionType))
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}

View File

@ -0,0 +1,8 @@
package MovementStrategy;
public interface IMoveableObject {
ObjectParameters GetObjectPosition();
int GetStep();
boolean TryMoveObject(MovementDirection direction);
void MoveObject(MovementDirection direction);
}

View File

@ -0,0 +1,47 @@
package MovementStrategy;
public class MoveToBorder extends AbstractStrategy {
@Override
protected boolean IsTargetDestination()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return false;
}
return objParams.RightBorder() + GetStep() >= FieldWidth &&
objParams.DownBorder() + GetStep() >= FieldHeight;
}
@Override
protected void MoveToTarget()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return;
}
int diffX = objParams.RightBorder() - FieldWidth;
if (Math.abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
int diffY = objParams.DownBorder() - FieldHeight;
if (Math.abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,47 @@
package MovementStrategy;
public class MoveToCenter extends AbstractStrategy {
@Override
protected boolean IsTargetDestination()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return false;
}
return (objParams.ObjectMiddleHorizontal() - GetStep() <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical() - GetStep() <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
}
@Override
protected void MoveToTarget()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return;
}
var diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
if (Math.abs(diffX) > GetStep()) {
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
if (Math.abs(diffY) > GetStep()) {
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,24 @@
package MovementStrategy;
import Drawnings.DrawningAirCraft;
public class MoveableAirCraft implements IMoveableObject {
private DrawningAirCraft _airCraft = null;
public MoveableAirCraft(DrawningAirCraft drawningAirCraft)
{
_airCraft = drawningAirCraft;
}
public ObjectParameters GetObjectPosition()
{
if (_airCraft == null || _airCraft.getEntityAirCraft() == null)
{
return null;
}
return new ObjectParameters(_airCraft.GetPosX(), _airCraft.GetPosY(), _airCraft.GetWidth(), _airCraft.GetHeight());
}
public int GetStep() { return (int) _airCraft.getEntityAirCraft().getStep(); }
public boolean TryMoveObject(MovementDirection direction) { return _airCraft.moveTransport(direction); }
public void MoveObject(MovementDirection direction) { _airCraft.moveTransport(direction); }
}

View File

@ -0,0 +1,8 @@
package MovementStrategy;
public enum MovementDirection {
Up,
Down,
Left,
Right;
}

View File

@ -0,0 +1,25 @@
package MovementStrategy;
public class ObjectParameters {
private int _x;
private int _y;
private int _width;
private int _height;
public int LeftBorder() { return _x; }
public int TopBorder() { return _y; }
public int RightBorder() { return _x + _width; }
public int DownBorder() { return _y + _height; }
public int ObjectMiddleHorizontal () { return _x + _width / 2; }
public int ObjectMiddleVertical () { return _y + _height / 2; }
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}

View File

@ -0,0 +1,7 @@
package MovementStrategy;
public enum StrategyStatus {
NotInit,
InProgress,
Finish
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 965 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1005 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 978 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1012 B