сделанная работа
This commit is contained in:
parent
3e27acda2c
commit
ef8c9c6e6b
@ -3,58 +3,57 @@ package CollectionGenericObjects;
|
|||||||
import Drawnings.DrawningBoat;
|
import Drawnings.DrawningBoat;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public abstract class AbstractCompany {
|
public abstract class AbstractCompany {
|
||||||
protected final int _placeSizeWidth = 210;
|
protected final int _placeSizeWidth = 210;
|
||||||
protected final int _placeSizeHeight = 80;
|
protected final int _placeSizeHeight = 120;
|
||||||
protected final int _pictureWidth;
|
protected final int _pictureWidth;
|
||||||
protected final int _pictureHeight;
|
protected final int _pictureHeight;
|
||||||
protected ICollectionGenericObjects<DrawningBoat> _collection = null;
|
protected ICollectionGenericObjects<DrawningBoat> _collection = null;
|
||||||
private int maxCount = getMaxCount();
|
|
||||||
public int getMaxCount() {
|
public int getMaxCount() {
|
||||||
return _pictureWidth * _pictureHeight / (_placeSizeWidth*_placeSizeHeight);
|
return _pictureWidth * _pictureHeight / (_placeSizeWidth*_placeSizeHeight);
|
||||||
}
|
}
|
||||||
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat> collection) {
|
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat> collection) {
|
||||||
_pictureWidth = picWidth;
|
this._pictureWidth = picWidth;
|
||||||
_pictureHeight = picHeight;
|
this._pictureHeight = picHeight;
|
||||||
_collection = collection;
|
this._collection = collection;
|
||||||
|
int maxCount = getMaxCount();
|
||||||
_collection.setMaxCount(maxCount);
|
_collection.setMaxCount(maxCount);
|
||||||
}
|
}
|
||||||
public boolean add(AbstractCompany company ,DrawningBoat boat) {
|
public static int add(AbstractCompany company ,DrawningBoat boat) {
|
||||||
if (company != null && company._collection != null) {
|
if (company._collection == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return company._collection.insert(boat);
|
return company._collection.insert(boat);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean remove(AbstractCompany company, int position) {
|
public static DrawningBoat remove(AbstractCompany company, int position) {
|
||||||
if (company != null && company._collection != null) {
|
if (company._collection == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return company._collection.remove(position);
|
return company._collection.remove(position);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public DrawningBoat getRandomObject() {
|
public DrawningBoat getRandomObject() {
|
||||||
|
if (_collection == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
return _collection.get(rnd.nextInt(getMaxCount()));
|
return _collection.get(rnd.nextInt(0, _collection.getCount() + 1));
|
||||||
}
|
}
|
||||||
public BufferedImage show() {
|
public void show(Graphics g) {
|
||||||
BufferedImage bitmap = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
drawBackground(g);
|
||||||
Graphics2D g2d = bitmap.createGraphics();
|
|
||||||
|
|
||||||
drawBackground(g2d);
|
|
||||||
|
|
||||||
setObjectsPosition();
|
setObjectsPosition();
|
||||||
for (int i = 0; i < (_collection != null ? _collection.getCount() : 0); ++i) {
|
if (_collection == null) {
|
||||||
DrawningBoat obj = _collection.get(i);
|
return;
|
||||||
obj.drawBoat(g2d);
|
|
||||||
}
|
}
|
||||||
|
for(int i = 0; i < _collection.getCount(); i++) {
|
||||||
g2d.dispose();
|
if(_collection.get(i) != null) {
|
||||||
return bitmap;
|
_collection.get(i).drawBoat(g);
|
||||||
}
|
}
|
||||||
protected abstract void drawBackground(Graphics2D g2d);
|
}
|
||||||
|
}
|
||||||
|
protected abstract void drawBackground(Graphics g);
|
||||||
protected abstract void setObjectsPosition();
|
protected abstract void setObjectsPosition();
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,22 +7,24 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BoatSharingService extends AbstractCompany {
|
public class BoatSharingService extends AbstractCompany {
|
||||||
private List<Point> locCoord = new ArrayList<>();
|
private final List<Point> locCoord = new ArrayList<>();
|
||||||
private int numRows, numCols;
|
private int numRows, numCols;
|
||||||
public BoatSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat> collection) {
|
public BoatSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat> collection) {
|
||||||
super(picWidth, picHeight, collection);
|
super(picWidth, picHeight, collection);
|
||||||
|
_collection.setMaxCount(30);
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void drawBackground(Graphics2D g) {
|
protected void drawBackground(Graphics g) {
|
||||||
Color backgroundColor = new Color(135, 206, 235);
|
Color backgroundColor = new Color(135, 206, 235);
|
||||||
|
|
||||||
g.setColor(backgroundColor);
|
g.setColor(backgroundColor);
|
||||||
g.fillRect(0, 0, _pictureWidth, _pictureHeight);
|
g.fillRect(0, 0, _pictureWidth, _pictureHeight);
|
||||||
|
|
||||||
g.setColor(new Color(165, 42, 42)); // Brown
|
g.setColor(new Color(165, 42, 42)); // Brown
|
||||||
int offsetX = 10, offsetY = -12;
|
int offsetX = 10, offsetY = -5;
|
||||||
int x = 1 + offsetX, y = _pictureHeight - _placeSizeHeight + offsetY;
|
int x = 1 + offsetX, y = _pictureHeight - _placeSizeHeight + offsetY;
|
||||||
int numRows = 0;
|
numRows = 0;
|
||||||
while (y >= 0) {
|
while (y >= 0) {
|
||||||
int numCols = 0;
|
int numCols = 0;
|
||||||
while (x + _placeSizeWidth <= _pictureWidth) {
|
while (x + _placeSizeWidth <= _pictureWidth) {
|
||||||
@ -46,13 +48,16 @@ public class BoatSharingService extends AbstractCompany {
|
|||||||
}
|
}
|
||||||
int row = numRows - 1, col = numCols;
|
int row = numRows - 1, col = numCols;
|
||||||
for (int i=0;i< _collection.getCount(); i++, col--) {
|
for (int i=0;i< _collection.getCount(); i++, col--) {
|
||||||
|
if (_collection.get(i) != null) {
|
||||||
_collection.get(i).setPictureSize(_pictureWidth, _pictureHeight);
|
_collection.get(i).setPictureSize(_pictureWidth, _pictureHeight);
|
||||||
_collection.get(i).setPosition((int)locCoord.get(row*numCols - col).getX() + 5,
|
_collection.get(i).setPosition((int)locCoord.get(row*numCols - col).getX() + 5,
|
||||||
(int)locCoord.get(row*numCols - col).getY() + 5);
|
(int)locCoord.get(row*numCols - col).getY() + 9);
|
||||||
if (col == 1) {
|
if (col == 1) {
|
||||||
col = numCols + 1;
|
col = numCols + 1;
|
||||||
row--;
|
row--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
package CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Drawnings.DrawningBoat;
|
||||||
|
import Drawnings.DrawningCatamaran;
|
||||||
|
import Drawnings.IDrawPaddles;
|
||||||
|
import Entities.EntityBoat;
|
||||||
|
import Entities.EntityCatamaran;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Constructor<T extends EntityBoat, U extends IDrawPaddles> {
|
||||||
|
private ArrayList<T> entitiesList = new ArrayList<>();
|
||||||
|
private ArrayList<U> paddlesList = new ArrayList<>();
|
||||||
|
public void addBoat(T obj) {
|
||||||
|
entitiesList.add(obj);
|
||||||
|
}
|
||||||
|
public void addBoat(U obj) {
|
||||||
|
paddlesList.add(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawningBoat getRandomBoat() {
|
||||||
|
Random rnd = new Random();
|
||||||
|
int entityIndex = rnd.nextInt(0, 3);
|
||||||
|
int paddlesIndex = rnd.nextInt(0, 3);
|
||||||
|
|
||||||
|
T entity = entitiesList.get(entityIndex);
|
||||||
|
U paddles = paddlesList.get(paddlesIndex);
|
||||||
|
|
||||||
|
return (entity instanceof EntityCatamaran) ?
|
||||||
|
new DrawningCatamaran((EntityCatamaran) entity, paddles) :
|
||||||
|
new DrawningBoat(entity, paddles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEntityDescription(int index) {
|
||||||
|
if (index < 0 || index >= entitiesList.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
T entity = entitiesList.get(index);
|
||||||
|
String entityClassName = (entity instanceof EntityCatamaran) ? "EntityCatamaran" : "EntityBoat";
|
||||||
|
|
||||||
|
return String.format("<html><i><u>%s</u></i> = %s</html>", entityClassName, entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPaddlesDescription(int index) {
|
||||||
|
if (index < 0 || index >= paddlesList.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return paddlesList.get(index).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,17 @@
|
|||||||
package CollectionGenericObjects;
|
package CollectionGenericObjects;
|
||||||
|
|
||||||
public interface ICollectionGenericObjects<T extends Object> {
|
import Drawnings.DrawningBoat;
|
||||||
|
|
||||||
|
public interface ICollectionGenericObjects<T extends DrawningBoat> {
|
||||||
int getCount();
|
int getCount();
|
||||||
void setMaxCount(int maxCount);
|
|
||||||
boolean insert(T obj);
|
void setMaxCount(int count);
|
||||||
boolean insert(T obj, int position);
|
|
||||||
boolean remove(int position);
|
int insert(T obj);
|
||||||
T get(int position);
|
|
||||||
|
int insert(T obj, int index);
|
||||||
|
|
||||||
|
T remove(int index);
|
||||||
|
|
||||||
|
T get(int index);
|
||||||
}
|
}
|
||||||
|
@ -1,65 +1,66 @@
|
|||||||
package CollectionGenericObjects;
|
package CollectionGenericObjects;
|
||||||
|
|
||||||
import java.sql.Array;
|
import Drawnings.DrawningBoat;
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class MassiveGenericObjects<T extends Object> implements ICollectionGenericObjects<T> {
|
public class MassiveGenericObjects<T extends DrawningBoat> implements ICollectionGenericObjects<T> {
|
||||||
private T[] _collection;
|
private ArrayList<T> _collection;
|
||||||
public MassiveGenericObjects() {
|
public MassiveGenericObjects() {
|
||||||
_collection = (T[]) new Object[getCount()];
|
_collection = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
int maxCount = 0;
|
||||||
|
int realSize = 0;
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return _collection.length;
|
return _collection.size();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean insert(T obj) {
|
public int insert(T obj) {
|
||||||
for (int i = 0; i < getCount(); i++) {
|
return insert(obj, 0);
|
||||||
if (_collection[i] == null) {
|
|
||||||
_collection[i] = obj;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean insert(T obj, int position) {
|
|
||||||
if (position < 0 || position >= getCount()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (_collection[position] == null) {
|
|
||||||
_collection[position] = obj;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for (int i = position + 1;i < getCount(); i++) {
|
|
||||||
if (_collection[i] == null) {
|
|
||||||
_collection[i] = obj;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = position - 1;i >= 0; i--) {
|
|
||||||
if (_collection[i] == null) {
|
|
||||||
_collection[i] = obj;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(int position) {
|
public int insert(T obj, int position) {
|
||||||
if (position < 0 || position >= getCount()) {
|
if (position > maxCount|| position < 0) {
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
_collection[position] = null;
|
|
||||||
return true;
|
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
|
@Override
|
||||||
public T get(int position) {
|
public T get(int position) {
|
||||||
if (position >= 0 && position < getCount()) {
|
if (position >= 0 && position < _collection.size()) {
|
||||||
return _collection[position];
|
return _collection.get(position);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
@ -67,13 +68,24 @@ public class MassiveGenericObjects<T extends Object> implements ICollectionGener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMaxCount(int value) {
|
public void setMaxCount(int count) {
|
||||||
if (value > 0) {
|
if (count > 0) {
|
||||||
if (_collection.length > 0) {
|
if (!_collection.isEmpty()) {
|
||||||
_collection = Arrays.copyOf(_collection, value);
|
ArrayList<T> bfLoc = new ArrayList<>(count);
|
||||||
} else {
|
bfLoc.addAll(0, _collection);
|
||||||
_collection = (T[]) new Object[value];
|
_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;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
134
ProjectCatamaran/src/Drawnings/DrawningAbstractCompany.java
Normal file
134
ProjectCatamaran/src/Drawnings/DrawningAbstractCompany.java
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import CollectionGenericObjects.AbstractCompany;
|
||||||
|
import CollectionGenericObjects.BoatSharingService;
|
||||||
|
import CollectionGenericObjects.MassiveGenericObjects;
|
||||||
|
import Forms.FormCatamaran;
|
||||||
|
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 BoatSharingService(width, height, new MassiveGenericObjects<DrawningBoat>());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void createObject(int type, JFrame obj) {
|
||||||
|
if (_company == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawningBoat _drawningBoat;
|
||||||
|
Random random = new Random();
|
||||||
|
switch (type) {
|
||||||
|
case 0:
|
||||||
|
_drawningBoat = new DrawningBoat(random.nextInt(70 - 30) + 30, random.nextInt(500 - 100) + 100,
|
||||||
|
getColorR(obj, random), random.nextInt(3));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_drawningBoat = new DrawningCatamaran(random.nextInt(70 - 30) + 30, random.nextInt(500 - 100) + 100,
|
||||||
|
getColorR(obj, random), random.nextInt(3),
|
||||||
|
getColorR(obj, random),
|
||||||
|
random.nextBoolean(), random.nextBoolean());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (AbstractCompany.add(_company, _drawningBoat) != -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;
|
||||||
|
}
|
||||||
|
DrawningBoat boat = null;
|
||||||
|
int counter = 100;
|
||||||
|
while (boat == null && counter > 0) {
|
||||||
|
boat = _company.getRandomObject();
|
||||||
|
--counter;
|
||||||
|
}
|
||||||
|
if (boat == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||||
|
JFrame frame = new JFrame("Катамаран");
|
||||||
|
FormCatamaran formCatamaran = new FormCatamaran();
|
||||||
|
frame.setContentPane(formCatamaran.PanelWrapper);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setLocation(500, 200);
|
||||||
|
formCatamaran.setBoat(boat);
|
||||||
|
frame.pack();
|
||||||
|
frame.setSize(1000, 725);
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private DrawningBoat 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);
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ import java.awt.*;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DrawningBoat {
|
public class DrawningBoat {
|
||||||
private final EntityBoat entityBoat;
|
public Entities.EntityBoat entityBoat;
|
||||||
public EntityBoat getEntityBoat() {
|
public EntityBoat getEntityBoat() {
|
||||||
return entityBoat;
|
return entityBoat;
|
||||||
}
|
}
|
||||||
@ -15,12 +15,12 @@ public class DrawningBoat {
|
|||||||
protected Integer _startPosX;
|
protected Integer _startPosX;
|
||||||
protected Integer _startPosY;
|
protected Integer _startPosY;
|
||||||
private int _drawingBoatWidth = 107;
|
private int _drawingBoatWidth = 107;
|
||||||
private int _drawingBoatHeight = 72;
|
private int _drawingBoatHeight = 80;
|
||||||
public int GetPosX(){return _startPosX;}
|
public int GetPosX(){return _startPosX;}
|
||||||
public int GetPosY(){return _startPosY;}
|
public int GetPosY(){return _startPosY;}
|
||||||
public int GetWidth(){return _drawingBoatWidth;}
|
public int GetWidth(){return _drawingBoatWidth;}
|
||||||
public int GetHeight(){return _drawingBoatHeight;}
|
public int GetHeight(){return _drawingBoatHeight;}
|
||||||
private IDrawPaddles drawPaddles;
|
public IDrawPaddles drawPaddles;
|
||||||
|
|
||||||
public DrawningBoat(int speed, float weight, Color bodyColor, int paddlesType) {
|
public DrawningBoat(int speed, float weight, Color bodyColor, int paddlesType) {
|
||||||
entityBoat = new EntityBoat(speed, weight, bodyColor);
|
entityBoat = new EntityBoat(speed, weight, bodyColor);
|
||||||
@ -51,6 +51,10 @@ public class DrawningBoat {
|
|||||||
_drawingBoatWidth = boatWidth;
|
_drawingBoatWidth = boatWidth;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public DrawningBoat(EntityBoat _entityBoat, IDrawPaddles _drawPaddles) {
|
||||||
|
entityBoat = _entityBoat;
|
||||||
|
drawPaddles = _drawPaddles;
|
||||||
|
}
|
||||||
public void setPosition(int x, int y) {
|
public void setPosition(int x, int y) {
|
||||||
if (_pictureHeight == null || _pictureWidth == null)
|
if (_pictureHeight == null || _pictureWidth == null)
|
||||||
return;
|
return;
|
||||||
@ -78,10 +82,7 @@ public class DrawningBoat {
|
|||||||
if (_startPosY + _drawingBoatHeight > height)
|
if (_startPosY + _drawingBoatHeight > height)
|
||||||
_startPosY = height - _drawingBoatHeight;
|
_startPosY = height - _drawingBoatHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean moveTransport(MovementDirection direction) {
|
public boolean moveTransport(MovementDirection direction) {
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
package Drawnings;
|
package Drawnings;
|
||||||
|
|
||||||
import Entities.*;
|
import Entities.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawningCatamaran extends DrawningBoat {
|
public class DrawningCatamaran extends DrawningBoat {
|
||||||
EntityCatamaran EntityBoat;
|
|
||||||
|
|
||||||
public DrawningCatamaran(int speed, float weight, Color bodyColor, int paddlesType, Color additionalColor, boolean sail, boolean floaters) {
|
public DrawningCatamaran(int speed, float weight, Color bodyColor, int paddlesType, Color additionalColor, boolean sail, boolean floaters) {
|
||||||
super(speed, weight, bodyColor, paddlesType, 110, 68);
|
super(speed, weight, bodyColor, paddlesType, 110, 80);
|
||||||
EntityBoat = new EntityCatamaran(speed, weight, bodyColor, additionalColor, floaters, sail);
|
entityBoat = new EntityCatamaran(speed, weight, bodyColor, additionalColor, floaters, sail);
|
||||||
|
}
|
||||||
|
public DrawningCatamaran(EntityCatamaran entity, IDrawPaddles paddles) {
|
||||||
|
super(entity, paddles);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawFloater(int y0, Color additionalColor, Graphics2D g2d)
|
private void drawFloater(int y0, Color additionalColor, Graphics2D g2d)
|
||||||
{
|
{
|
||||||
g2d.setColor(additionalColor);
|
g2d.setColor(additionalColor);
|
||||||
@ -30,27 +31,27 @@ public class DrawningCatamaran extends DrawningBoat {
|
|||||||
g2d.fillPolygon(floaterPolygon);
|
g2d.fillPolygon(floaterPolygon);
|
||||||
g2d.drawPolygon(floaterPolygon);
|
g2d.drawPolygon(floaterPolygon);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void drawBoat(Graphics g) {
|
public void drawBoat(Graphics g) {
|
||||||
|
|
||||||
if (EntityBoat == null || !(EntityBoat instanceof EntityCatamaran) || _startPosX == null || _startPosY == null) {
|
if (entityBoat == null || !(entityBoat instanceof EntityCatamaran entityCatamaran) || _startPosX == null || _startPosY == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.drawBoat(g);
|
super.drawBoat(g);
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
if (EntityBoat.getFloaters()) {
|
if (entityCatamaran.getFloaters()) {
|
||||||
g2d.setColor(Color.BLACK);
|
g2d.setColor(Color.BLACK);
|
||||||
g2d.drawLine(_startPosX+20, _startPosY+20, _startPosX + 20, _startPosY+17);
|
g2d.drawLine(_startPosX+20, _startPosY+20, _startPosX + 20, _startPosY+17);
|
||||||
g2d.drawLine(_startPosX+80, _startPosY+20, _startPosX + 80, _startPosY+17);
|
g2d.drawLine(_startPosX+80, _startPosY+20, _startPosX + 80, _startPosY+17);
|
||||||
g2d.drawLine(_startPosX+20, _startPosY+55, _startPosX + 20, _startPosY+58);
|
g2d.drawLine(_startPosX+20, _startPosY+55, _startPosX + 20, _startPosY+58);
|
||||||
g2d.drawLine(_startPosX+80, _startPosY+55, _startPosX + 80, _startPosY+58);
|
g2d.drawLine(_startPosX+80, _startPosY+55, _startPosX + 80, _startPosY+58);
|
||||||
|
|
||||||
drawFloater(11, EntityBoat.getAdditionalColor(), g2d);
|
drawFloater(11, entityCatamaran.getAdditionalColor(), g2d);
|
||||||
drawFloater(58, EntityBoat.getAdditionalColor(), g2d);
|
drawFloater(58, entityCatamaran.getAdditionalColor(), g2d);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EntityBoat.getSail()) {
|
if (entityCatamaran.getSail()) {
|
||||||
g2d.setColor(Color.BLACK);
|
g2d.setColor(Color.BLACK);
|
||||||
g2d.setStroke(new BasicStroke(1));
|
g2d.setStroke(new BasicStroke(1));
|
||||||
Point[] sail = new Point[] {
|
Point[] sail = new Point[] {
|
||||||
@ -65,7 +66,7 @@ public class DrawningCatamaran extends DrawningBoat {
|
|||||||
sailPolygon.addPoint(point.x, point.y);
|
sailPolygon.addPoint(point.x, point.y);
|
||||||
}
|
}
|
||||||
g2d.drawPolygon(sailPolygon);
|
g2d.drawPolygon(sailPolygon);
|
||||||
g2d.setColor(EntityBoat.getAdditionalColor());
|
g2d.setColor(entityCatamaran.getAdditionalColor());
|
||||||
g2d.fillPolygon(sailPolygon);
|
g2d.fillPolygon(sailPolygon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
79
ProjectCatamaran/src/Drawnings/DrawningConstructor.java
Normal file
79
ProjectCatamaran/src/Drawnings/DrawningConstructor.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import CollectionGenericObjects.Constructor;
|
||||||
|
import Entities.EntityBoat;
|
||||||
|
import Entities.EntityCatamaran;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawningConstructor extends JComponent {
|
||||||
|
|
||||||
|
Constructor<EntityBoat, IDrawPaddles> constructor = new Constructor<>();
|
||||||
|
private DrawningBoat obj;
|
||||||
|
public DrawningBoat getObj() {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
public DrawningConstructor() {
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
EntityBoat _entityBoat = null;
|
||||||
|
IDrawPaddles _drawPaddles = null;
|
||||||
|
Random rnd = new Random();
|
||||||
|
int paddlesType = rnd.nextInt(3);
|
||||||
|
switch (paddlesType) {
|
||||||
|
case 0:
|
||||||
|
_drawPaddles = new DrawningPaddles();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_drawPaddles = new DrawningOvalPaddles();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
_drawPaddles = new DrawningRectanglePaddles();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int paddlesCount = rnd.nextInt(1,4);
|
||||||
|
_drawPaddles.setNumber(paddlesCount);
|
||||||
|
|
||||||
|
int typeBoat = rnd.nextInt(0,2);
|
||||||
|
|
||||||
|
switch (typeBoat) {
|
||||||
|
case 0:
|
||||||
|
_entityBoat = new EntityBoat(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:
|
||||||
|
_entityBoat = new EntityCatamaran(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.addBoat(_entityBoat);
|
||||||
|
constructor.addBoat(_drawPaddles);
|
||||||
|
}
|
||||||
|
obj = constructor.getRandomBoat();
|
||||||
|
|
||||||
|
}
|
||||||
|
public void reCreateObj() {
|
||||||
|
obj = constructor.getRandomBoat();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEntityString(int index) {
|
||||||
|
return constructor.getEntityDescription(index);
|
||||||
|
}
|
||||||
|
public String getPaddlesString(int index) {
|
||||||
|
return constructor.getPaddlesDescription(index);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
if (obj != null) {
|
||||||
|
obj.setPosition(10, 30);
|
||||||
|
obj.setPictureSize(400, 300);
|
||||||
|
obj.drawBoat(g);
|
||||||
|
}
|
||||||
|
super.repaint();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -35,4 +35,10 @@ public class DrawningOvalPaddles implements IDrawPaddles {
|
|||||||
g2d.fillOval(posX + 9 - halfStrokeWidth - ovalSize / 2, posY + 68 - ovalSize / 2, ovalSize, ovalSize);
|
g2d.fillOval(posX + 9 - halfStrokeWidth - ovalSize / 2, posY + 68 - ovalSize / 2, ovalSize, ovalSize);
|
||||||
g2d.fillOval(posX + 9 - halfStrokeWidth - ovalSize / 2, posY - 3 - ovalSize / 2, ovalSize, ovalSize);
|
g2d.fillOval(posX + 9 - halfStrokeWidth - ovalSize / 2, posY - 3 - ovalSize / 2, ovalSize, ovalSize);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String buffer = "";
|
||||||
|
buffer += "Тип: овальные, Количество вёсел: " + _paddlesCount.getEnumNumber() * 2;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,15 @@ public class DrawningPaddles implements IDrawPaddles {
|
|||||||
drawPaddlePair(g2d, posX, (int)_startY + 5);
|
drawPaddlePair(g2d, posX, (int)_startY + 5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void drawPaddlePair(Graphics2D g2d, int posX, int posY) {
|
private void drawPaddlePair(Graphics2D g2d, int posX, int posY) {
|
||||||
g2d.drawLine(posX + 20, posY + 15, posX + 9, posY - 3); // Рисуем левое весло
|
g2d.drawLine(posX + 20, posY + 15, posX + 9, posY - 3); // Рисуем левое весло
|
||||||
g2d.drawLine(posX + 20, posY + 50, posX + 9, posY + 68); // Рисуем правое весло
|
g2d.drawLine(posX + 20, posY + 50, posX + 9, posY + 68); // Рисуем правое весло
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String buffer = "";
|
||||||
|
buffer += "Тип: обычные, Количество вёсел: " + _paddlesCount.getEnumNumber() * 2;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
}
|
}
|
@ -36,4 +36,10 @@ public class DrawningRectanglePaddles implements IDrawPaddles {
|
|||||||
g2d.fillRect(posX + 9 - halfStrokeWidth - rectangleSize / 2, posY + 68 - rectangleSize / 2, rectangleSize, rectangleSize);
|
g2d.fillRect(posX + 9 - halfStrokeWidth - rectangleSize / 2, posY + 68 - rectangleSize / 2, rectangleSize, rectangleSize);
|
||||||
g2d.fillRect(posX + 9 - halfStrokeWidth - rectangleSize / 2, posY - 3 - rectangleSize / 2, rectangleSize, rectangleSize);
|
g2d.fillRect(posX + 9 - halfStrokeWidth - rectangleSize / 2, posY - 3 - rectangleSize / 2, rectangleSize, rectangleSize);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String buffer = "";
|
||||||
|
buffer += "Тип: прямоугольники, Количество вёсел: " + _paddlesCount.getEnumNumber() * 2;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,14 @@ public class EntityBoat {
|
|||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,4 +21,13 @@ public class EntityCatamaran extends EntityBoat {
|
|||||||
Sail = sail;
|
Sail = sail;
|
||||||
Floaters = floaters;
|
Floaters = floaters;
|
||||||
}
|
}
|
||||||
|
@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.Sail;
|
||||||
|
buffer += ", Поплавки: " + this.Floaters;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,134 +0,0 @@
|
|||||||
import CollectionGenericObjects.AbstractCompany;
|
|
||||||
import CollectionGenericObjects.BoatSharingService;
|
|
||||||
import CollectionGenericObjects.MassiveGenericObjects;
|
|
||||||
import Drawnings.DrawningBoat;
|
|
||||||
import Drawnings.DrawningCatamaran;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.text.NumberFormatter;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.text.NumberFormat;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class FormBoatCollection extends JFrame {
|
|
||||||
private AbstractCompany _company;
|
|
||||||
private JPanel pictureBox, instrumentsBox;
|
|
||||||
private JComboBox<String> comboBoxSelectorCompany;
|
|
||||||
private JButton buttonAddBoat, buttonAddCatamaran, buttonRemoveBoat, buttonGoToCheck, buttonRefresh;
|
|
||||||
private JTextField textBoxPosition;
|
|
||||||
|
|
||||||
public FormBoatCollection() {
|
|
||||||
setTitle("Коллекция лодок");
|
|
||||||
setSize(900, 500);
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
instrumentsBox = new JPanel();
|
|
||||||
instrumentsBox.setLayout(new GridLayout(0,1));
|
|
||||||
|
|
||||||
comboBoxSelectorCompany = new JComboBox<>();
|
|
||||||
comboBoxSelectorCompany.addItem("Хранилище");
|
|
||||||
comboBoxSelectorCompany.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
String selectedItem = Integer.toString(comboBoxSelectorCompany.getSelectedIndex());
|
|
||||||
switch (selectedItem) {
|
|
||||||
case "Хранилище":
|
|
||||||
_company = new BoatSharingService(pictureBox.getWidth(), pictureBox.getHeight(),
|
|
||||||
new MassiveGenericObjects<DrawningBoat>());
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instrumentsBox.add(comboBoxSelectorCompany);
|
|
||||||
|
|
||||||
buttonAddBoat = new JButton("Добавить лодку");
|
|
||||||
buttonAddBoat.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
createObject("Drawnings.DrawningBoat");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instrumentsBox.add(buttonAddBoat);
|
|
||||||
|
|
||||||
buttonAddCatamaran = new JButton("Добавить катамаран");
|
|
||||||
buttonAddCatamaran.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
createObject("Drawnings.DrawningCatamaran");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instrumentsBox.add(buttonAddCatamaran);
|
|
||||||
|
|
||||||
NumberFormat format = NumberFormat.getInstance();
|
|
||||||
NumberFormatter formatter = new NumberFormatter(format);
|
|
||||||
formatter.setValueClass(Integer.class);
|
|
||||||
formatter.setMinimum(0);
|
|
||||||
formatter.setMaximum(100);
|
|
||||||
formatter.setAllowsInvalid(false);
|
|
||||||
formatter.setCommitsOnValidEdit(true);
|
|
||||||
|
|
||||||
textBoxPosition = new JFormattedTextField(formatter);
|
|
||||||
textBoxPosition.setPreferredSize(buttonAddBoat.getPreferredSize());
|
|
||||||
|
|
||||||
instrumentsBox.add(textBoxPosition);
|
|
||||||
|
|
||||||
buttonRemoveBoat = new JButton("Удалить объект");
|
|
||||||
buttonRemoveBoat.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (textBoxPosition.getText() == null || textBoxPosition.getText().isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int result = JOptionPane.showConfirmDialog(null, "Удалить объект?",
|
|
||||||
"Удаление", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
||||||
if (result == JOptionPane.NO_OPTION) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int pos = Integer.valueOf(textBoxPosition.getText());
|
|
||||||
if (_company.remove(_company, pos)) {
|
|
||||||
JOptionPane.showMessageDialog(null,"Объект удален");
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instrumentsBox.add(buttonRemoveBoat);
|
|
||||||
|
|
||||||
pictureBox = new JPanel();
|
|
||||||
getContentPane().add(instrumentsBox, BorderLayout.EAST);
|
|
||||||
getContentPane().add(pictureBox); // Добавляем pictureBox в центр
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createObject(String type) {
|
|
||||||
if (_company == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DrawningBoat _drawningBoat;
|
|
||||||
Random random = new Random();
|
|
||||||
switch (type) {
|
|
||||||
case "Drawnings.DrawningBoat":
|
|
||||||
_drawningBoat = new DrawningBoat(random.nextInt(100 - 30) + 30, random.nextInt(500 - 100) + 100,
|
|
||||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3));
|
|
||||||
break;
|
|
||||||
case "Drawnings.DrawningCatamaran":
|
|
||||||
_drawningBoat = new DrawningCatamaran(random.nextInt(100 - 30) + 30, random.nextInt(500 - 100) + 100,
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
if (_company.add(_company, _drawningBoat)) {
|
|
||||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
|
||||||
//pictureBox.setIcon(new ImageIcon(_company.show()));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
163
ProjectCatamaran/src/Forms/FormBoatCollection.java
Normal file
163
ProjectCatamaran/src/Forms/FormBoatCollection.java
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
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 FormBoatCollection extends JFrame {
|
||||||
|
final private JFrame jFrameCollectionBoats = 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 buttonAddBoat = new JButton("Добавить лодку");
|
||||||
|
final private JButton buttonAddCatamaran = 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() {
|
||||||
|
|
||||||
|
jFrameCollectionBoats.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||||
|
Dimension dimension = tolls.getScreenSize();
|
||||||
|
jFrameCollectionBoats.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||||
|
1200, 665);
|
||||||
|
jFrameCollectionBoats.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(buttonAddBoat, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
addCatamaranPanel.setLayout(new BorderLayout());
|
||||||
|
addCatamaranPanel.setSize(170, 40);
|
||||||
|
addCatamaranPanel.add(buttonAddCatamaran, 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);
|
||||||
|
|
||||||
|
jFrameCollectionBoats.add(toolsPanel);
|
||||||
|
jFrameCollectionBoats.add(labelPanel);
|
||||||
|
jFrameCollectionBoats.add(comboBoxPanel);
|
||||||
|
jFrameCollectionBoats.add(addBoatPanel);
|
||||||
|
jFrameCollectionBoats.add(addCatamaranPanel);
|
||||||
|
jFrameCollectionBoats.add(textBoxPanel);
|
||||||
|
jFrameCollectionBoats.add(removePanel);
|
||||||
|
jFrameCollectionBoats.add(goToCheckPanel);
|
||||||
|
jFrameCollectionBoats.add(refreshPanel);
|
||||||
|
jFrameCollectionBoats.add(addFromConstructorPanel);
|
||||||
|
jFrameCollectionBoats.add(_company);
|
||||||
|
|
||||||
|
jFrameCollectionBoats.addComponentListener(new ComponentAdapter() {
|
||||||
|
public void componentResized(ComponentEvent componentEvent) {
|
||||||
|
labelPanel.setLocation(jFrameCollectionBoats.getWidth() - 210, 0);
|
||||||
|
toolsPanel.setLocation(jFrameCollectionBoats.getWidth() - 233, 0);
|
||||||
|
comboBoxPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 30);
|
||||||
|
addBoatPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 70);
|
||||||
|
addCatamaranPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 120);
|
||||||
|
textBoxPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 220);
|
||||||
|
removePanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 260);
|
||||||
|
goToCheckPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 300);
|
||||||
|
refreshPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 340);
|
||||||
|
addFromConstructorPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 170);
|
||||||
|
toolsPanel.setSize(new Dimension(10, jFrameCollectionBoats.getHeight()));
|
||||||
|
|
||||||
|
jFrameCollectionBoats.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
comboBoxSelectorCompany.addActionListener(e -> {
|
||||||
|
|
||||||
|
_company.collectionComboBox_SelectedIndexChanged(comboBoxSelectorCompany,
|
||||||
|
jFrameCollectionBoats.getWidth() - 233, jFrameCollectionBoats.getHeight());
|
||||||
|
jFrameCollectionBoats.repaint();
|
||||||
|
|
||||||
|
});
|
||||||
|
buttonAddBoat.addActionListener(e -> {
|
||||||
|
_company.createObject(0, jFrameCollectionBoats);
|
||||||
|
jFrameCollectionBoats.repaint();
|
||||||
|
});
|
||||||
|
buttonAddCatamaran.addActionListener(e -> {
|
||||||
|
_company.createObject(1, jFrameCollectionBoats);
|
||||||
|
jFrameCollectionBoats.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, jFrameCollectionBoats);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jFrameCollectionBoats.repaint();
|
||||||
|
|
||||||
|
});
|
||||||
|
refreshButton.addActionListener(e -> {
|
||||||
|
jFrameCollectionBoats.repaint();
|
||||||
|
});
|
||||||
|
goToCheckButton.addActionListener(e -> {
|
||||||
|
_company.goToCheckButtonAction();
|
||||||
|
jFrameCollectionBoats.repaint();
|
||||||
|
});
|
||||||
|
addFromConstructorButton.addActionListener(e -> {
|
||||||
|
_company.getObjFromConstructor(jFrameCollectionBoats);
|
||||||
|
});
|
||||||
|
jFrameCollectionBoats.setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormCatamaran">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Forms.FormCatamaran">
|
||||||
<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">
|
<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"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
@ -30,30 +30,6 @@
|
|||||||
<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"/>
|
<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>
|
</constraints>
|
||||||
</hspacer>
|
</hspacer>
|
||||||
<component id="a8c2" class="javax.swing.JButton" binding="buttonCreateCatamaran">
|
|
||||||
<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="buttonCreateBoat">
|
|
||||||
<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">
|
<component id="fe25b" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
<constraints>
|
<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">
|
<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">
|
@ -1,3 +1,5 @@
|
|||||||
|
package Forms;
|
||||||
|
|
||||||
import Drawnings.*;
|
import Drawnings.*;
|
||||||
import MovementStrategy.*;
|
import MovementStrategy.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -5,70 +7,33 @@ import java.awt.*;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FormCatamaran extends JFrame {
|
public class FormCatamaran extends JFrame {
|
||||||
protected DrawningBoat _drawningBoat;
|
protected DrawningBoat _drawningBoat;
|
||||||
JPanel PanelWrapper;
|
public JPanel PanelWrapper;
|
||||||
private JPanel PictureBox;
|
private JPanel PictureBox;
|
||||||
private JButton buttonCreateCatamaran;
|
|
||||||
private JButton buttonRight;
|
private JButton buttonRight;
|
||||||
private JButton buttonDown;
|
private JButton buttonDown;
|
||||||
private JButton buttonLeft;
|
private JButton buttonLeft;
|
||||||
private JButton buttonUp;
|
private JButton buttonUp;
|
||||||
private JButton buttonCreateBoat;
|
|
||||||
private JComboBox comboBoxStrategy;
|
private JComboBox comboBoxStrategy;
|
||||||
private JButton buttonStrategyStep;
|
private JButton buttonStrategyStep;
|
||||||
private AbstractStrategy _strategy;
|
private AbstractStrategy _strategy;
|
||||||
|
|
||||||
private List<JComponent> controls;
|
private List<JComponent> controls;
|
||||||
private void createObject(String type) {
|
|
||||||
Random random = new Random();
|
|
||||||
switch (type) {
|
|
||||||
case "Drawnings.DrawningBoat":
|
|
||||||
_drawningBoat = new DrawningBoat(random.nextInt(100 - 30) + 30, random.nextInt(500 - 100) + 100,
|
|
||||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3));
|
|
||||||
break;
|
|
||||||
case "Drawnings.DrawningCatamaran":
|
|
||||||
_drawningBoat = new DrawningCatamaran(random.nextInt(100 - 30) + 30, random.nextInt(500 - 100) + 100,
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
_drawningBoat.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
|
||||||
_drawningBoat.setPosition(random.nextInt(25, 100),
|
|
||||||
random.nextInt(25, 100));
|
|
||||||
_strategy = null;
|
|
||||||
comboBoxStrategy.setEnabled(true);
|
|
||||||
|
|
||||||
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
public FormCatamaran() {
|
public FormCatamaran() {
|
||||||
buttonUp.setName("buttonUp");
|
buttonUp.setName("buttonUp");
|
||||||
buttonDown.setName("buttonDown");
|
buttonDown.setName("buttonDown");
|
||||||
buttonLeft.setName("buttonLeft");
|
buttonLeft.setName("buttonLeft");
|
||||||
buttonRight.setName("buttonRight");
|
buttonRight.setName("buttonRight");
|
||||||
|
_strategy = null;
|
||||||
|
Draw();
|
||||||
|
|
||||||
InitializeControlsRepaintList();
|
InitializeControlsRepaintList();
|
||||||
|
|
||||||
buttonCreateCatamaran.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
createObject("Drawnings.DrawningCatamaran");
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
buttonCreateBoat.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
createObject("Drawnings.DrawningBoat");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ActionListener buttonMoveClickedListener = new ActionListener() {
|
ActionListener buttonMoveClickedListener = new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@ -138,6 +103,7 @@ public class FormCatamaran extends JFrame {
|
|||||||
if (_strategy == null) {
|
if (_strategy == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
comboBoxStrategy.setEnabled(false);
|
||||||
_strategy.MakeStep();
|
_strategy.MakeStep();
|
||||||
Draw();
|
Draw();
|
||||||
|
|
||||||
@ -149,10 +115,8 @@ public class FormCatamaran extends JFrame {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void Draw() {
|
private void Draw() {
|
||||||
if (_drawningBoat.getEntityBoat() == null)
|
if (_drawningBoat == null)
|
||||||
return;
|
return;
|
||||||
if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
|
if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
|
||||||
return;
|
return;
|
||||||
@ -164,6 +128,16 @@ public class FormCatamaran extends JFrame {
|
|||||||
|
|
||||||
RepaintControls();
|
RepaintControls();
|
||||||
|
|
||||||
|
}
|
||||||
|
public void setBoat(DrawningBoat boat) {
|
||||||
|
_drawningBoat = boat;
|
||||||
|
_drawningBoat.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
comboBoxStrategy.setEnabled(true);
|
||||||
|
_strategy = null;
|
||||||
|
PictureBox.repaint();
|
||||||
|
|
||||||
|
Draw();
|
||||||
|
|
||||||
}
|
}
|
||||||
private void RepaintControls() {
|
private void RepaintControls() {
|
||||||
for (JComponent control : controls) {
|
for (JComponent control : controls) {
|
||||||
@ -173,8 +147,6 @@ public class FormCatamaran extends JFrame {
|
|||||||
|
|
||||||
private void InitializeControlsRepaintList() {
|
private void InitializeControlsRepaintList() {
|
||||||
controls = new LinkedList<>();
|
controls = new LinkedList<>();
|
||||||
controls.add(buttonCreateCatamaran);
|
|
||||||
controls.add(buttonCreateBoat);
|
|
||||||
controls.add(buttonUp);
|
controls.add(buttonUp);
|
||||||
controls.add(buttonDown);
|
controls.add(buttonDown);
|
||||||
controls.add(buttonLeft);
|
controls.add(buttonLeft);
|
92
ProjectCatamaran/src/Forms/FormConstructor.java
Normal file
92
ProjectCatamaran/src/Forms/FormConstructor.java
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
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.getPaddlesString(0));
|
||||||
|
secondPaddlesLabel.setText(constructor.getPaddlesString(1));
|
||||||
|
thirdPaddlesLabel.setText(constructor.getPaddlesString(2));
|
||||||
|
|
||||||
|
|
||||||
|
paddlesInfoPanel.setLayout(new BoxLayout(paddlesInfoPanel, BoxLayout.Y_AXIS));
|
||||||
|
paddlesInfoPanel.setBorder(BorderFactory.createTitledBorder("Paddles"));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,7 @@
|
|||||||
import javax.swing.*;
|
import Forms.FormBoatCollection;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// JFrame.setDefaultLookAndFeelDecorated(false);
|
FormBoatCollection formBoatCollection = new FormBoatCollection();
|
||||||
// JFrame frame = new JFrame("Катамаран");
|
formBoatCollection.OpenFrame();
|
||||||
// frame.setContentPane(new FormBoatCollection());
|
|
||||||
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
// frame.setLocation(500, 200);
|
|
||||||
// frame.pack();
|
|
||||||
// frame.setSize(700, 500);
|
|
||||||
// frame.setVisible(true);
|
|
||||||
new FormBoatCollection();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,21 +1,19 @@
|
|||||||
package MovementStrategy;
|
package MovementStrategy;
|
||||||
|
|
||||||
public class MoveToBorder extends AbstractStrategy {
|
public class MoveToBorder extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
protected boolean IsTargetDestination()
|
protected boolean IsTargetDestination()
|
||||||
{
|
{
|
||||||
var objParams = GetObjectParameters();
|
var objParams = GetObjectParameters();
|
||||||
if (objParams == null) {
|
if (objParams == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return objParams.RightBorder() <= FieldWidth &&
|
return objParams.RightBorder() + GetStep() >= FieldWidth - GetStep() &&
|
||||||
objParams.RightBorder() + GetStep() >= FieldWidth &&
|
objParams.DownBorder() + GetStep() >= FieldHeight - GetStep();
|
||||||
objParams.DownBorder() <= FieldHeight &&
|
|
||||||
objParams.DownBorder() + GetStep() >= FieldHeight;
|
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
protected void MoveToTarget()
|
protected void MoveToTarget()
|
||||||
{
|
{
|
||||||
|
|
||||||
var objParams = GetObjectParameters();
|
var objParams = GetObjectParameters();
|
||||||
if (objParams == null) {
|
if (objParams == null) {
|
||||||
return;
|
return;
|
||||||
@ -43,7 +41,6 @@ public class MoveToBorder extends AbstractStrategy {
|
|||||||
{
|
{
|
||||||
MoveDown();
|
MoveDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
package MovementStrategy;
|
package MovementStrategy;
|
||||||
|
|
||||||
public class MoveToCenter extends AbstractStrategy {
|
public class MoveToCenter extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
protected boolean IsTargetDestination()
|
protected boolean IsTargetDestination()
|
||||||
{
|
{
|
||||||
var objParams = GetObjectParameters();
|
var objParams = GetObjectParameters();
|
||||||
if (objParams == null) {
|
if (objParams == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (objParams.ObjectMiddleHorizontal() <= FieldWidth / 2 &&
|
return (objParams.ObjectMiddleHorizontal() - GetStep() <= FieldWidth / 2 &&
|
||||||
objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
|
objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
|
||||||
objParams.ObjectMiddleVertical() <= FieldHeight / 2 &&
|
objParams.ObjectMiddleVertical() - GetStep() <= FieldHeight / 2 &&
|
||||||
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
|
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
protected void MoveToTarget()
|
protected void MoveToTarget()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user