From 087acf10809d53ea1051d419699c48d76a90e7f4 Mon Sep 17 00:00:00 2001 From: insideq Date: Sat, 8 Jun 2024 11:43:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/FormAdditionalCollection.java | 61 ++++++++++++++++++------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/src/FormAdditionalCollection.java b/src/FormAdditionalCollection.java index 8dec13d..d5a1042 100644 --- a/src/FormAdditionalCollection.java +++ b/src/FormAdditionalCollection.java @@ -22,7 +22,8 @@ public class FormAdditionalCollection extends JFrame { private CanvasExcavator canvasExc = new CanvasExcavator(); private AdditionalCollections additionalCollection = null; private Random random = new Random(); - private JButton buttonGenerate = new JButton("Создать"); + private JButton buttonCreate = new JButton("Создать"); + private JButton buttonAdd = new JButton("Добавить"); private JList listEntity = new JList(); private JList listRollers = new JList(); public FormAdditionalCollection() { @@ -31,39 +32,49 @@ public class FormAdditionalCollection extends JFrame { additionalCollection = new AdditionalCollections(3, (Class) EntityBulldozer.class, (Class) IDifferentRollers.class); AddEntities(); AddRollers(); - buttonGenerate.addActionListener(new ActionListener() { + + buttonCreate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - drawingBulldozer = additionalCollection.CreateAdditionalCollectionBulldozer(); drawingBulldozer.SetPictureSize(getWidth(), getHeight()); - drawingBulldozer.SetPosition(50,50); + drawingBulldozer.SetPosition(50, 50); canvasExc._drawingBulldozer = drawingBulldozer; canvasExc.repaint(); - DrawingBulldozer copyBulldozer; - if (drawingBulldozer instanceof DrawingExcavator) - copyBulldozer = new DrawingExcavator((EntityExcavator) drawingBulldozer.EntityBulldozer, drawingBulldozer.drawingRollers); - else - copyBulldozer = new DrawingBulldozer(drawingBulldozer.EntityBulldozer, drawingBulldozer.drawingRollers); - company._collection.Insert(copyBulldozer); - FormBulldozerCollection.canvasShow(); - + String[] data1 = new String[additionalCollection.CountEntities]; - for (int i = 0; i < additionalCollection.CountEntities; i++) { - EntityBulldozer entity = additionalCollection._collectionEntity[i]; - data1[i] = ToString(entity); - } - String[] data2 = new String[additionalCollection.CountRollers]; - for (int i = 0; i < additionalCollection.CountRollers; i++) { - IDifferentRollers rollers = additionalCollection._collectionRollers[i]; - data2[i] = ToString(rollers); - } - listEntity.setListData(data1); - listRollers.setListData(data2); + for (int i = 0; i < additionalCollection.CountEntities; i++) { + EntityBulldozer entity = additionalCollection._collectionEntity[i]; + data1[i] = ToString(entity); + } + String[] data2 = new String[additionalCollection.CountRollers]; + for (int i = 0; i < additionalCollection.CountRollers; i++) { + IDifferentRollers rollers = additionalCollection._collectionRollers[i]; + data2[i] = ToString(rollers); + } + listEntity.setListData(data1); + listRollers.setListData(data2); } }); - buttonGenerate.setBounds(450, 10, 100, 50); - add(buttonGenerate); + + buttonAdd.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (drawingBulldozer != null) { + DrawingBulldozer copyBulldozer; + if (drawingBulldozer instanceof DrawingExcavator) + copyBulldozer = new DrawingExcavator((EntityExcavator) drawingBulldozer.EntityBulldozer, drawingBulldozer.drawingRollers); + else + copyBulldozer = new DrawingBulldozer(drawingBulldozer.EntityBulldozer, drawingBulldozer.drawingRollers); + company._collection.Insert(copyBulldozer); + FormBulldozerCollection.canvasShow(); + } + } + }); + buttonCreate.setBounds(300, 10, 100, 50); + buttonAdd.setBounds(450, 10, 100, 50); + add(buttonCreate); + add(buttonAdd); listEntity.setBounds(10,200,300,60); listRollers.setBounds(320,200,300,60); add(listEntity);