лаб3.2

This commit is contained in:
Ilya Ryabov 2024-04-27 17:38:24 +04:00
parent 029dcb4e42
commit 5f3ecf6c51
3 changed files with 64 additions and 72 deletions

View File

@ -17,55 +17,54 @@ import java.util.Random;
public class FormAdditionalCollection extends JFrame {
public DrawingBaseStormtrooper _drawingBaseStormtrooper = null;
private DrawingBaseStormtrooper copyStormtrooper = null;
private AbstractCompany _company = null;
private CanvasStormtrooper _canvasStormtrooper = new CanvasStormtrooper();
private AdditionalCollection<EntityBaseStormtrooper, IDrawingEngines> _additionalCollection = null;
private Random random = new Random();
private JButton buttonGenerate = new JButton("Создать");
private JButton buttonGoToCollection = new JButton("В коллекцию");
private JList<String> listEntity = new JList<String>();
private JList<String> listEngines = new JList<String>();
public FormAdditionalCollection() {
setTitle("Random stormtrooper");
setMinimumSize(new Dimension(650,310));
setTitle("Случайные бомбардировщики");
setMinimumSize(new Dimension(970,310));
_additionalCollection = new AdditionalCollection<EntityBaseStormtrooper,IDrawingEngines>(3,(Class)EntityBaseStormtrooper.class,(Class)IDrawingEngines.class);
AddEntities();
AddEngines();
buttonGoToCollection.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(_drawingBaseStormtrooper!=null){
_company._collection.Insert(copyStormtrooper);
FormStormtrooperCollection.canvasShow();
}
}
});
buttonGenerate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_drawingBaseStormtrooper = _additionalCollection.CreateAdditionalCollectionStormtrooper();
_drawingBaseStormtrooper.SetPictureSize(getWidth(), getHeight());
_drawingBaseStormtrooper.SetPosition(50,50);
_drawingBaseStormtrooper.SetPosition(360,30);
_canvasStormtrooper._drawingBaseStormtrooper = _drawingBaseStormtrooper;
_canvasStormtrooper.repaint();
DrawingBaseStormtrooper copyStormtrooper;
if (_drawingBaseStormtrooper instanceof DrawingStormtrooper)
copyStormtrooper = new DrawingStormtrooper((EntityStormtrooper) _drawingBaseStormtrooper.EntityBaseStormtrooper, _drawingBaseStormtrooper.drawingEngines);
else
copyStormtrooper = new DrawingBaseStormtrooper(_drawingBaseStormtrooper.EntityBaseStormtrooper, _drawingBaseStormtrooper.drawingEngines);
_company._collection.Insert(copyStormtrooper);
FormStormtrooperCollection.canvasShow();
String[] data1 = new String[_additionalCollection.CountEntities];
for (int i = 0; i < _additionalCollection.CountEntities; i++) {
EntityBaseStormtrooper entity = _additionalCollection._collectionEntity[i];
data1[i] = ToString(entity);
}
String[] data2 = new String[_additionalCollection.CountEngines];
for (int i = 0; i < _additionalCollection.CountEngines; i++) {
IDrawingEngines engines = _additionalCollection._collectionEngines[i];
data2[i] = ToString(engines);
}
listEntity.setListData(data1);
listEngines.setListData(data2);
}
});
buttonGenerate.setBounds(450, 10, 100, 50);
buttonGoToCollection.setBounds(830,200,120,60);
buttonGenerate.setBounds(830, 130, 120, 60);
listEntity.setBounds(10,200,400,60);
listEngines.setBounds(420,200,400,60);
add(buttonGenerate);
listEntity.setBounds(10,200,300,60);
listEngines.setBounds(320,200,300,60);
add(buttonGoToCollection);
add(listEntity);
add(listEngines);
add(_canvasStormtrooper);
@ -73,8 +72,8 @@ public class FormAdditionalCollection extends JFrame {
}
private String ToString(EntityBaseStormtrooper entity) {
String str = "";
if (entity instanceof EntityStormtrooper) str += "EntityWarmlyShip ";
else str += "EntityShip ";
if (entity instanceof EntityStormtrooper) str += "EntityStormtrooper ";
else str += "EntityBaseStormtrooper ";
str += entity.getBodyColor().toString();
return str;
}
@ -138,17 +137,17 @@ public class FormAdditionalCollection extends JFrame {
}
void setCompany(AbstractCompany company) {
this._company = company;
for (int i = 0; i < _additionalCollection.CountEntities; i++){
String[] data1 = new String[_additionalCollection.CountEntities];
for (int i = 0; i < _additionalCollection.CountEntities; i++) {
EntityBaseStormtrooper entity = _additionalCollection._collectionEntity[i];
DrawingBaseStormtrooper _listStormtrooper;
if(entity instanceof EntityStormtrooper){
_listStormtrooper = new DrawingStormtrooper((EntityStormtrooper) entity,_additionalCollection._collectionEngines[i]);
}else{
_listStormtrooper = new DrawingBaseStormtrooper(entity,_additionalCollection._collectionEngines[i]);
data1[i] = ToString(entity);
}
_company._collection.Insert(_listStormtrooper);
String[] data2 = new String[_additionalCollection.CountEngines];
for (int i = 0; i < _additionalCollection.CountEngines; i++) {
IDrawingEngines engines = _additionalCollection._collectionEngines[i];
data2[i] = ToString(engines);
}
listEntity.setListData(data1);
listEngines.setListData(data2);
}
}

View File

@ -37,17 +37,17 @@ public class FormStormtrooper extends JFrame {
Width = getWidth() - 10;
Height = getHeight() - 34;
_strategy = null;
Icon iconUp = new ImageIcon("Resources\\arrowUp.jpg");
Icon iconUp = new ImageIcon("E:\\ООП\\Java\\Lab3\\ProjectStormtrooper\\Resources\\arrowUp.jpg");
UpButton.setIcon(iconUp);
UpButton.setName("UP");
DownButton.setName("DOWN");
Icon iconDown = new ImageIcon("Resources\\arrowDown.jpg");
Icon iconDown = new ImageIcon("E:\\ООП\\Java\\Lab3\\ProjectStormtrooper\\Resources\\arrowDown.jpg");
DownButton.setIcon(iconDown);
LeftButton.setName("LEFT");
Icon iconLeft = new ImageIcon("Resources\\arrowLeft.jpg");
Icon iconLeft = new ImageIcon("E:\\ООП\\Java\\Lab3\\ProjectStormtrooper\\Resources\\arrowLeft.jpg");
LeftButton.setIcon(iconLeft);
RightButton.setName("RIGHT");
Icon iconRight = new ImageIcon("Resources\\arrowRight.jpg");
Icon iconRight = new ImageIcon("E:\\ООП\\Java\\Lab3\\ProjectStormtrooper\\Resources\\arrowRight.jpg");
RightButton.setIcon(iconRight);
ButtonStrategy.addActionListener(new ActionListener() {

View File

@ -20,11 +20,11 @@ public class FormStormtrooperCollection extends JFrame{
private JButton CreateButton = new JButton("Создать бомбардировщик");;
private JButton CreateShipButton = new JButton("Создать базовый бомбардировщик");
private JButton RemoveButton = new JButton("Удалить");
private JButton GoToCheckButton = new JButton("Check");
private JButton RandomButton = new JButton("RandomShip");
private JButton RefreshButton = new JButton("Refresh");
private JButton GoToCheckButton = new JButton("На проверку");
private JButton RandomButton = new JButton("Случайные");
private JButton RefreshButton = new JButton("Обновить");
private JComboBox ComboBoxCollections = new JComboBox(new String[]{"", "Хранилище"});
private JFormattedTextField MaskedTextField;
private JFormattedTextField TextField;
public FormStormtrooperCollection(String title, Dimension dimension) {
this.title = title;
this.dimension = dimension;
@ -72,15 +72,8 @@ public class FormStormtrooperCollection extends JFrame{
setMinimumSize(dimension);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MaskFormatter mask = null;
try {
mask = new MaskFormatter("##");
mask.setPlaceholder("00");
} catch (ParseException e) {
throw new RuntimeException(e);
}
MaskedTextField = new JFormattedTextField(mask);
TextField = new JFormattedTextField();
ComboBoxCollections.addActionListener(new ActionListener() {
@Override
@ -109,10 +102,10 @@ public class FormStormtrooperCollection extends JFrame{
RemoveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_company == null || MaskedTextField.getText() == null) {
if (_company == null || TextField.getText() == null) {
return;
}
int pos = parseInt(MaskedTextField.getText());
int pos = parseInt(TextField.getText());
int resultConfirmDialog = JOptionPane.showConfirmDialog(null, "Удалить", "Удаление", JOptionPane.YES_NO_OPTION);
if (resultConfirmDialog == JOptionPane.NO_OPTION) return;
if (_company._collection.Remove(pos) != null) {
@ -185,10 +178,10 @@ public class FormStormtrooperCollection extends JFrame{
ComboBoxCollections.setBounds(getWidth()-190, 10, 150, 20);
CreateShipButton.setBounds(getWidth()-190, 60, 150, 30);
CreateButton.setBounds(getWidth()-190, 100, 150, 30);
MaskedTextField.setBounds(getWidth()-190,200,150,30);
RandomButton.setBounds(getWidth()-190, 140, 150, 30);
TextField.setBounds(getWidth()-190,200,150,30);
RemoveButton.setBounds(getWidth()-190, 240, 150, 30);
GoToCheckButton.setBounds(getWidth()-190, 280, 150, 30);
RandomButton.setBounds(getWidth()-190, 320, 150, 30);
RefreshButton.setBounds(getWidth()-190, getHeight()-90, 150, 30);
setSize(dimension.width,dimension.height);
@ -197,7 +190,7 @@ public class FormStormtrooperCollection extends JFrame{
add(ComboBoxCollections);
add(CreateShipButton);
add(CreateButton);
add(MaskedTextField);
add(TextField);
add(RemoveButton);
add(GoToCheckButton);
add(RandomButton);
@ -210,10 +203,10 @@ public class FormStormtrooperCollection extends JFrame{
ComboBoxCollections.setBounds(getWidth()-190, 10, 150, 20);
CreateShipButton.setBounds(getWidth()-190, 60, 150, 30);
CreateButton.setBounds(getWidth()-190, 100, 150, 30);
MaskedTextField.setBounds(getWidth()-190,200,150,30);
TextField.setBounds(getWidth()-190,200,150,30);
RemoveButton.setBounds(getWidth()-190, 240, 150, 30);
GoToCheckButton.setBounds(getWidth()-190, 280, 150, 30);
RandomButton.setBounds(getWidth()-190, 320, 150, 30);
RandomButton.setBounds(getWidth()-190, 140, 150, 30);
RefreshButton.setBounds(getWidth()-190, getHeight()-90, 150, 30);
}
});