воркинг

This commit is contained in:
artur-kalimullin 2024-05-22 01:06:16 +04:00
parent 021b810748
commit c51d279cf8
11 changed files with 913 additions and 0 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 = 210;
protected final int _placeSizeHeight = 120;
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,62 @@
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<>();
private int numRows, numCols;
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(new Color(165, 42, 42)); // Brown
int offsetX = 10, offsetY = -5;
int x = 1 + offsetX, y = _pictureHeight - _placeSizeHeight + offsetY;
numRows = 0;
while (y >= 0) {
int numCols = 0;
while (x + _placeSizeWidth <= _pictureWidth) {
numCols++;
g.drawLine(x, y, x + _placeSizeWidth / 2, y);
g.drawLine(x, y, x, y + _placeSizeHeight + 4);
locCoord.add(new Point(x, y));
x += _placeSizeWidth + 2;
}
numRows++;
x = 1 + offsetX;
y -= _placeSizeHeight + 5 + offsetY;
}
}
@Override
protected void setObjectsPosition() {
if (locCoord == null || _collection == null) {
return;
}
int row = numRows - 1, col = numCols;
for (int i=0;i< _collection.getCount(); i++, col--) {
if (_collection.get(i) != null) {
_collection.get(i).setPictureSize(_pictureWidth, _pictureHeight);
_collection.get(i).setPosition((int)locCoord.get(row*numCols - col).getX() + 5,
(int)locCoord.get(row*numCols - col).getY() + 9);
if (col == 1) {
col = numCols + 1;
row--;
}
}
}
}
}

View File

@ -0,0 +1,52 @@
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,77 @@
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 paddlesType = rnd.nextInt(3);
switch (paddlesType) {
case 0:
_drawEngine = new DrawningEngine();
break;
case 1:
_drawEngine = new DrawningOvalEngine();
break;
case 2:
_drawEngine = new DrawningLongEngine();
break;
}
int engineCount = rnd.nextInt(1,4);
_drawEngine.setNumber(engineCount);
int typeBoat = rnd.nextInt(0,2);
switch (typeBoat) {
case 0:
_entityAirCraft = new EntityAirCraft(rnd.nextInt(30,100), rnd.nextInt(100,500),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
break;
case 1:
_entityAirCraft = new EntityAirFighter(rnd.nextInt(30,100), rnd.nextInt(100,500),
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(400, 300);
obj.drawAirCraft(g);
}
super.repaint();
}
}

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,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 addBoatPanel = new JPanel();
final private JPanel addCatamaranPanel = 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);
addBoatPanel.setLayout(new BorderLayout());
addBoatPanel.setSize(170, 40);
addBoatPanel.add(buttonAddAirCraft, BorderLayout.CENTER);
addCatamaranPanel.setLayout(new BorderLayout());
addCatamaranPanel.setSize(170, 40);
addCatamaranPanel.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(addBoatPanel);
jFrameCollectionAirCraft.add(addCatamaranPanel);
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);
addBoatPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 70);
addCatamaranPanel.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 paddlesInfoPanel = new JPanel();
JLabel firstPaddlesLabel = new JLabel();
JLabel secondPaddlesLabel = new JLabel();
JLabel thirdPaddlesLabel = 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);
firstPaddlesLabel.setText(constructor.getEngineString(0));
secondPaddlesLabel.setText(constructor.getEngineString(1));
thirdPaddlesLabel.setText(constructor.getEngineString(2));
paddlesInfoPanel.setLayout(new BoxLayout(paddlesInfoPanel, BoxLayout.Y_AXIS));
paddlesInfoPanel.setBorder(BorderFactory.createTitledBorder("Engine"));
paddlesInfoPanel.setSize(500, 130);
paddlesInfoPanel.setLocation(150, 150);
paddlesInfoPanel.add(firstPaddlesLabel);
paddlesInfoPanel.add(secondPaddlesLabel);
paddlesInfoPanel.add(thirdPaddlesLabel);
addButton.setBounds(0, jFrameConstructor.getHeight() - 105, 150, 50);
reCreateButton.setBounds(0, jFrameConstructor.getHeight() - 135, 150, 30);
jFrameConstructor.add(paddlesInfoPanel);
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);
}
}