PIbd-14_Calimullin_A.R._Lab03_Hard #3

Closed
Bloody_Arthur wants to merge 10 commits from Lab3 into Lab2
25 changed files with 1005 additions and 367 deletions

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

@ -1,13 +1,13 @@
package Drawnings;
import Entities.EntityAirCraft;
import MovementStrategy.MovementDirection;
import Entities.*;
import MovementStrategy.*;
import java.awt.*;
import java.util.Random;
public class DrawningAirCraft {
private final EntityAirCraft entityAirCraft;
public Entities.EntityAirCraft entityAirCraft;
public EntityAirCraft getEntityAirCraft() {
return entityAirCraft;
@ -20,11 +20,11 @@ public class DrawningAirCraft {
private int _drawingAirCraftWidth = 66;
private int _drawingAirCraftHeight = 74;
public int GetPosX() {
public Integer GetPosX() {
return _startPosX;
}
public int GetPosY() {
public Integer GetPosY() {
return _startPosY;
}
@ -36,7 +36,7 @@ public class DrawningAirCraft {
return _drawingAirCraftHeight;
}
private IDrawEngine drawEngine;
public IDrawEngine drawEngine;
public DrawningAirCraft(int speed, float weight, Color bodyColor, int engineType) {
entityAirCraft = new EntityAirCraft(speed, weight, bodyColor);
@ -68,6 +68,11 @@ public class DrawningAirCraft {
_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;
@ -131,10 +136,10 @@ public class DrawningAirCraft {
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),
new Point(_startPosX + 10, _startPosY + 8),
new Point(_startPosX + 20, _startPosY + 17),
new Point(_startPosX + 20, _startPosY + 25),
};
Polygon rtailPolygon = new Polygon();
for (Point point : rtail)
@ -144,10 +149,10 @@ public class DrawningAirCraft {
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),
new Point(_startPosX + 10, _startPosY + 66),
new Point(_startPosX + 20, _startPosY + 57),
new Point(_startPosX + 20, _startPosY + 49),
};
Polygon ltailPolygon = new Polygon();
for (Point point : ltail)
@ -157,10 +162,10 @@ public class DrawningAirCraft {
g2d.fillPolygon(ltailPolygon);
Point[] rwing = new Point[]{
new Point(_startPosX + 45, _startPosY + 49),
new Point(_startPosX + 45, _startPosY + 74),
new Point(_startPosX + 37, _startPosY + 74),
new Point(_startPosX + 30, _startPosY + 49),
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)
@ -170,10 +175,10 @@ public class DrawningAirCraft {
g2d.fillPolygon(rwingPolygon);
Point[] lwing = new Point[]{
new Point(_startPosX + 45, _startPosY + 25),
new Point(_startPosX + 45, _startPosY),
new Point(_startPosX + 37, _startPosY),
new Point(_startPosX + 30, _startPosY + 25),
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)
@ -182,13 +187,13 @@ public class DrawningAirCraft {
g2d.setColor(entityAirCraft.getBodyColor());
g2d.fillPolygon(lwingPolygon);
g2d.drawRect(_startPosX + 10, _startPosY + 25, 50, 24);
g2d.fillRect(_startPosX + 10, _startPosY + 25, 50, 24);
g2d.drawRect(_startPosX , _startPosY + 24, 50, 25);
g2d.fillRect(_startPosX , _startPosY + 24, 50, 25);
Point[] nose = new Point[]{
new Point(_startPosX + 60, _startPosY + 25),
new Point(_startPosX + 76, _startPosY + 37),
new Point(_startPosX + 60, _startPosY + 49),
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)

View File

@ -5,15 +5,16 @@ import Entities.EntityAirFighter;
import java.awt.*;
public class DrawningAirFighter extends DrawningAirCraft {
private EntityAirFighter entityAirFighter;
public DrawningAirFighter(int speed, float weight, Color bodyColor, int engineType, Color additionalColor, boolean pgo, boolean rockets) {
super(speed, weight, bodyColor, engineType, 76, 80);
entityAirFighter = new EntityAirFighter(speed, weight, bodyColor, additionalColor, pgo, rockets);
entityAirCraft = new EntityAirFighter(speed, weight, bodyColor, additionalColor, pgo, rockets);
}
public DrawningAirFighter(EntityAirFighter entity, IDrawEngine engine) {
super(entity, engine);
}
public void drawAirCraft(Graphics g) {
if (entityAirFighter == null || _startPosX == null || _startPosY == null) {
if (entityAirCraft == null|| !(entityAirCraft instanceof EntityAirFighter entityAirFighter) || _startPosX == null || _startPosY == null) {
return;
}
super.drawAirCraft(g);
@ -21,9 +22,9 @@ public class DrawningAirFighter extends DrawningAirCraft {
if (entityAirFighter.getPgo()) {
Point[] pgo1 = new Point[]{
new Point(_startPosX + 50, _startPosY + 25),
new Point(_startPosX + 50, _startPosY + 15),
new Point(_startPosX + 55, _startPosY + 25),
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)
@ -33,9 +34,9 @@ public class DrawningAirFighter extends DrawningAirCraft {
g2d.fillPolygon(pgo1Polygon);
Point[] pgo2 = new Point[]{
new Point(_startPosX + 50, _startPosY + 49),
new Point(_startPosX + 50, _startPosY + 59),
new Point(_startPosX + 55, _startPosY + 49),
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)
@ -47,10 +48,10 @@ public class DrawningAirFighter extends DrawningAirCraft {
if (entityAirFighter.getRockets()) {
Point[] rocket1 = new Point[]{
new Point(_startPosX + 50, _startPosY + 71),
new Point(_startPosX + 50, _startPosY + 74),
new Point(_startPosX + 55, _startPosY + 69),
new Point(_startPosX + 50, _startPosY + 64),
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)
@ -59,14 +60,14 @@ public class DrawningAirFighter extends DrawningAirCraft {
g2d.setColor(entityAirFighter.getAdditionalColor());
g2d.fillPolygon(rocket1Polygon);
g.drawRect(_startPosX + 45, _startPosY + 67, 5, 4);
g.fillRect(_startPosX + 45, _startPosY + 67, 5, 4);
g.drawRect(_startPosX + 35, _startPosY + 67, 5, 4);
g.fillRect(_startPosX + 35, _startPosY + 67, 5, 4);
Point[] rocket2 = new Point[]{
new Point(_startPosX + 50, _startPosY + 7),
new Point(_startPosX + 50, _startPosY + 10),
new Point(_startPosX + 55, _startPosY + 5),
new Point(_startPosX + 50, _startPosY),
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)
@ -75,8 +76,8 @@ public class DrawningAirFighter extends DrawningAirCraft {
g2d.setColor(entityAirFighter.getAdditionalColor());
g2d.fillPolygon(rocket2Polygon);
g.drawRect(_startPosX + 45, _startPosY + 3, 5, 4);
g.fillRect(_startPosX + 45, _startPosY + 3, 5, 4);
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

@ -35,4 +35,10 @@ public class DrawningEngine implements IDrawEngine {
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

@ -35,4 +35,10 @@ public class DrawningLongEngine implements IDrawEngine {
g2d.drawRoundRect(_startX + 25, _startY + 17, 15, 2, 5, 5);
}
}
@Override
public String toString() {
String buffer = "";
buffer += "Тип: длиные, Количество двигателей: " + _engineCount.getEnumNumber();
return buffer;
}
}

View File

@ -35,4 +35,10 @@ public class DrawningOvalEngine implements IDrawEngine {
g2d.drawOval(_startX + 30, _startY + 17, 10, 2);
}
}
@Override
public String toString() {
String buffer = "";
buffer += "Тип: овальные, Количество двигателей: " + _engineCount.getEnumNumber();
return buffer;
}
}

View File

@ -25,4 +25,14 @@ public class EntityAirCraft {
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

@ -21,4 +21,14 @@ public class EntityAirFighter extends EntityAirCraft {
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

@ -1,131 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormAirFighter">
<grid id="27dc6" binding="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="599" height="476"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="1ff9a" binding="PictureBox" layout-manager="GridLayoutManager" row-count="6" 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>
<toolTipText value=""/>
</properties>
<border type="none"/>
<children>
<vspacer id="7b40c">
<constraints>
<grid row="2" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<preferred-size width="88" height="14"/>
</grid>
</constraints>
</vspacer>
<hspacer id="e0b21">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="a8c2" class="javax.swing.JButton" binding="buttonCreateAirFighter">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="150" height="30"/>
<preferred-size width="150" height="30"/>
<maximum-size width="150" height="30"/>
</grid>
</constraints>
<properties>
<text value="Создать истребитель"/>
</properties>
</component>
<component id="79b3e" class="javax.swing.JButton" binding="buttonCreateAirCraft">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="10" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="150" height="30"/>
<preferred-size width="150" height="30"/>
<maximum-size width="150" height="30"/>
</grid>
</constraints>
<properties>
<text value="Создать самолёт"/>
</properties>
</component>
<component id="fe25b" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" 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="arrowLeft.png"/>
<text value=""/>
</properties>
</component>
<component id="3eabd" class="javax.swing.JButton" binding="buttonStrategyStep">
<constraints>
<grid row="1" column="3" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Шаг"/>
</properties>
</component>
<component id="86d84" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="5" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" 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="arrowRight.png"/>
<text value=""/>
</properties>
</component>
<component id="3dc0" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" 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="arrowDown.png"/>
<text value=""/>
</properties>
</component>
<component id="ccb2a" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" 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="arrowUp.png"/>
<text value=""/>
</properties>
</component>
<component id="988c8" class="javax.swing.JComboBox" binding="comboBoxStrategy">
<constraints>
<grid row="0" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<actionCommand value=""/>
<doubleBuffered value="false"/>
<toolTipText value=""/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -1,176 +0,0 @@
import Drawnings.DrawningAirCraft;
import Drawnings.DrawningAirFighter;
import MovementStrategy.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.Random;
import java.util.List;
public class FormAirFighter extends JFrame {
protected DrawningAirCraft _drawningAirCraft;
JPanel PanelWrapper;
private JPanel PictureBox;
private JButton buttonCreateAirFighter;
private JButton buttonCreateAirCraft;
private JButton buttonRight;
private JButton buttonDown;
private JButton buttonLeft;
private JButton buttonUp;
private JComboBox comboBoxStrategy;
private JButton buttonStrategyStep;
private AbstractStrategy _strategy;
private List<JComponent> controls;
private void createObject(String type) {
Random random = new Random();
switch (type) {
case "Drawnings.DrawningAirCraft":
_drawningAirCraft = new DrawningAirCraft(random.nextInt(30,100), random.nextInt(100,500),
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3));
break;
case "Drawnings.DrawningAirFighter":
_drawningAirCraft = new DrawningAirFighter(random.nextInt(30,100), random.nextInt(100,500),
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3),
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
random.nextBoolean(), random.nextBoolean());
break;
default:
return;
}
_drawningAirCraft.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
_drawningAirCraft.setPosition(random.nextInt(25, 100),
random.nextInt(25, 100));
_strategy = null;
comboBoxStrategy.setEnabled(true);
Draw();
}
public FormAirFighter() {
buttonUp.setName("buttonUp");
buttonDown.setName("buttonDown");
buttonLeft.setName("buttonLeft");
buttonRight.setName("buttonRight");
InitializeControlsRepaintList();
buttonCreateAirFighter.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createObject("Drawnings.DrawningAirFighter");
}
});
buttonCreateAirCraft.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createObject("Drawnings.DrawningAirCraft");
}
});
ActionListener buttonMoveClickedListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String buttonName = ((JButton) e.getSource()).getName();
boolean result = false;
switch (buttonName) {
case "buttonUp": {
result = _drawningAirCraft.moveTransport(MovementDirection.Up);
}
break;
case "buttonDown": {
result = _drawningAirCraft.moveTransport(MovementDirection.Down);
}
break;
case "buttonLeft": {
result = _drawningAirCraft.moveTransport(MovementDirection.Left);
}
break;
case "buttonRight": {
result = _drawningAirCraft.moveTransport(MovementDirection.Right);
}
break;
}
if (result)
Draw();
}
};
buttonRight.addActionListener(buttonMoveClickedListener);
buttonDown.addActionListener(buttonMoveClickedListener);
buttonLeft.addActionListener(buttonMoveClickedListener);
buttonUp.addActionListener(buttonMoveClickedListener);
comboBoxStrategy.addItem("К центру");
comboBoxStrategy.addItem("К краю");
buttonStrategyStep.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_drawningAirCraft == null)
return;
if (comboBoxStrategy.isEnabled()) {
switch (comboBoxStrategy.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), PictureBox.getWidth(), PictureBox.getHeight());
}
if (_strategy == null) {
return;
}
_strategy.MakeStep();
Draw();
comboBoxStrategy.setEnabled(false);
if (_strategy.GetStatus() == StrategyStatus.Finish) {
comboBoxStrategy.setEnabled(true);
_strategy = null;
}
}
});
}
private void Draw() {
if (_drawningAirCraft.getEntityAirCraft() == null)
return;
if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
return;
}
Graphics g = PictureBox.getGraphics();
g.setColor(PictureBox.getBackground());
g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight());
_drawningAirCraft.drawAirCraft(g);
RepaintControls();
}
private void RepaintControls() {
for (JComponent control : controls) {
control.repaint();
}
}
private void InitializeControlsRepaintList() {
controls = new LinkedList<>();
controls.add(buttonCreateAirFighter);
controls.add(buttonCreateAirCraft);
controls.add(buttonUp);
controls.add(buttonDown);
controls.add(buttonLeft);
controls.add(buttonRight);
controls.add(comboBoxStrategy);
controls.add(buttonStrategyStep);
}
}

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,13 +1,7 @@
import javax.swing.*;
import Forms.FormAirCraftCollection;
public class Main {
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(false);
JFrame frame = new JFrame("Истребитель");
frame.setContentPane(new FormAirFighter().PanelWrapper);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(500, 200);
frame.pack();
frame.setSize(700, 500);
frame.setVisible(true);
FormAirCraftCollection formAirCraftCollection = new FormAirCraftCollection();
formAirCraftCollection.OpenFrame();
}
}

View File

@ -1,18 +1,18 @@
package MovementStrategy;
public class MoveToBorder extends AbstractStrategy {
@Override
protected boolean IsTargetDestination()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return false;
}
return objParams.RightBorder() <= FieldWidth &&
objParams.RightBorder() + GetStep() >= FieldWidth &&
objParams.DownBorder() <= FieldHeight &&
return objParams.RightBorder() + GetStep() >= FieldWidth &&
objParams.DownBorder() + GetStep() >= FieldHeight;
}
@Override
protected void MoveToTarget()
{
var objParams = GetObjectParameters();

View File

@ -1,6 +1,7 @@
package MovementStrategy;
public class MoveToCenter extends AbstractStrategy {
@Override
protected boolean IsTargetDestination()
{
var objParams = GetObjectParameters();
@ -12,9 +13,9 @@ public class MoveToCenter extends AbstractStrategy {
objParams.ObjectMiddleVertical() - GetStep() <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
}
@Override
protected void MoveToTarget()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return;