Лабораторная работа №3

This commit is contained in:
victinass 2024-06-07 16:30:00 +04:00
parent 0a53208d5e
commit 9a08a6c0f0
3 changed files with 22 additions and 12 deletions

View File

@ -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;

View File

@ -23,6 +23,7 @@ public class FormAdditionalCollection extends JFrame {
private AdditionalCollections<EntityWarship, IDrawingBlocks> additionalCollection = null;
private Random random = new Random();
private JButton buttonGenerate = new JButton("Создать");
private JButton buttonAdd = new JButton("Добавить");
private JList<String> listEntity = new JList<String>();
private JList<String> listBlocks = new JList<String>();
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;

View File

@ -149,6 +149,7 @@ public class FormWarshipCollection extends JFrame{
}
FormBattleship form = new FormBattleship("Линкор", new Dimension(900,565));
form.Init(warship);
}
});