diff --git a/src/frames/FrameShipsCollection.java b/src/frames/FrameShipsCollection.java index 28d4717..e0b4678 100644 --- a/src/frames/FrameShipsCollection.java +++ b/src/frames/FrameShipsCollection.java @@ -5,15 +5,15 @@ import javax.swing.border.StrokeBorder; import java.awt.*; import java.io.IOException; import java.util.ArrayList; +import java.util.LinkedList; import java.util.Objects; import drawing_objects.DrawingShip; import generics.ShipsGenericStorage; -import generics.TrashCollection; public class FrameShipsCollection extends JFrame { private final ShipsGenericStorage storage; - TrashCollection trashCollection = new TrashCollection<>(); + LinkedList trashCollection = new LinkedList<>(); private JComponent pictureBoxCollection; private TextField textFieldNumber; private TextField textFieldStorageName; @@ -45,6 +45,7 @@ public class FrameShipsCollection extends JFrame { pictureBoxCollection.setPreferredSize(new Dimension(700, 450)); JButton buttonAddShip = new JButton("Добавить корабль"); textFieldNumber = new TextField(); + textFieldNumber.setText("0"); JButton buttonRemoveShip = new JButton("Удалить корабль"); JButton buttonRefreshCollection = new JButton("Обновить коллекцию"); JButton buttonAddSet = new JButton("Добавить набор"); @@ -167,7 +168,7 @@ public class FrameShipsCollection extends JFrame { }); } private void buttonRemoveShipClick(){ - if (listStorages.getSelectedIndex() == -1) + if (listStorages.getSelectedIndex() == -1 || Objects.equals(textFieldNumber.getText(), "") || textFieldNumber.getText() == null) return; var obj = storage.getSet(listStorages.getSelectedValue()); if (obj == null) @@ -187,7 +188,7 @@ public class FrameShipsCollection extends JFrame { pictureBoxCollection.repaint(); } private void buttonTrashClick(){ - if(trashCollection.getSize() == 0) + if(trashCollection.peek() == null) return; FrameBattleship form; try { diff --git a/src/generics/TrashCollection.java b/src/generics/TrashCollection.java deleted file mode 100644 index 52373d7..0000000 --- a/src/generics/TrashCollection.java +++ /dev/null @@ -1,21 +0,0 @@ -package generics; - -import java.util.LinkedList; - -public class TrashCollection { - LinkedList list; - public TrashCollection(){ - list = new LinkedList<>(); - } - public int getSize(){ - return list.size(); - } - public void add(T ship){ - list.add(ship); - } - public T pop(){ - if(list.size() == 0) - return null; - return list.pop(); - } -}