diff --git a/src/src/Drawings/DrawingWarship.java b/src/src/Drawings/DrawingWarship.java index b45be0d..d8d9a73 100644 --- a/src/src/Drawings/DrawingWarship.java +++ b/src/src/Drawings/DrawingWarship.java @@ -11,6 +11,7 @@ import java.awt.*; import java.lang.reflect.Type; public class DrawingWarship extends JPanel { + public IDrawingBlocks drawingBlocks; public Entities.EntityWarship EntityWarship; public Integer _pictureWidth; diff --git a/src/src/FormAdditionalCollection.java b/src/src/FormAdditionalCollection.java index 1a29fb3..9cbe3c4 100644 --- a/src/src/FormAdditionalCollection.java +++ b/src/src/FormAdditionalCollection.java @@ -23,6 +23,7 @@ public class FormAdditionalCollection extends JFrame { private AdditionalCollections additionalCollection = null; private Random random = new Random(); private JButton buttonGenerate = new JButton("Создать"); + private JButton buttonAdd = new JButton("Добавить"); private JList listEntity = new JList(); private JList listBlocks = new JList(); public FormAdditionalCollection() { @@ -34,20 +35,11 @@ public class FormAdditionalCollection extends JFrame { buttonGenerate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - drawingWarship = additionalCollection.CreateAdditionalCollectionWarship(); drawingWarship.SetPictureSize(getWidth(), getHeight()); drawingWarship.SetPosition(50,50); canvasBattleship._drawingWarship = drawingWarship; canvasBattleship.repaint(); - DrawingWarship copyWarship; - if (drawingWarship instanceof DrawingBattleship) - copyWarship = new DrawingBattleship((EntityBattleship) drawingWarship.EntityWarship, drawingWarship.drawingBlocks); - else - copyWarship = new DrawingWarship(drawingWarship.EntityWarship, drawingWarship.drawingBlocks); - company._collection.Insert(copyWarship); - FormWarshipCollection.canvasShow(); - String[] data1 = new String[additionalCollection.CountEntities]; for (int i = 0; i < additionalCollection.CountEntities; i++) { EntityWarship entity = additionalCollection._collectionEntity[i]; @@ -62,8 +54,24 @@ public class FormAdditionalCollection extends JFrame { listBlocks.setListData(data2); } }); + buttonAdd.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (drawingWarship != null) { + DrawingWarship copyWarship; + if (drawingWarship instanceof DrawingBattleship) + copyWarship = new DrawingBattleship((EntityBattleship) drawingWarship.EntityWarship, drawingWarship.drawingBlocks); + else + copyWarship = new DrawingWarship(drawingWarship.EntityWarship, drawingWarship.drawingBlocks); + company._collection.Insert(copyWarship); + FormWarshipCollection.canvasShow(); + } + } + }); buttonGenerate.setBounds(450, 10, 100, 50); + buttonAdd.setBounds(450, 70, 100, 50); add(buttonGenerate); + add(buttonAdd); listEntity.setBounds(10,200,300,60); listBlocks.setBounds(320,200,300,60); add(listEntity); @@ -82,8 +90,8 @@ public class FormAdditionalCollection extends JFrame { if (blocks == null || blocks.getNumBlocks() == null) return "Не имеет блоки"; String str = "Blocks "; - if (blocks instanceof DrawingBlocksType1) str += "Type 1 "; - else if (blocks instanceof DrawingBlocksType2) str += "Type 2 "; + if (blocks instanceof DrawingBlocksType1) str += "Тип 1 "; + else if (blocks instanceof DrawingBlocksType2) str += "Тип 2 "; else str += "Type Blocks "; str += blocks.getNumBlocks().toString(); return str; diff --git a/src/src/FormWarshipCollection.java b/src/src/FormWarshipCollection.java index 1400202..b1e0449 100644 --- a/src/src/FormWarshipCollection.java +++ b/src/src/FormWarshipCollection.java @@ -148,7 +148,8 @@ public class FormWarshipCollection extends JFrame{ return; } FormBattleship form = new FormBattleship("Линкор", new Dimension(900,565)); - form.Init(warship); + form.Init(warship); + } });