From 057e5a46e0bbb7aaffc89b7aa1d27b006b2b7d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Thu, 30 Nov 2023 23:51:48 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/.idea/misc.xml | 1 - Tank/src/ExtentionDrawingTank.java | 77 ++++++++++++ Tank/src/FormTankCollection.java | 151 +++++++++++++++++++++--- Tank/src/SetGeneric.java | 3 +- Tank/src/TanksGenericCollections.java | 5 + Tank/src/TanksGenericStorage.java | 164 ++++++++++++++++++++++++++ 6 files changed, 385 insertions(+), 16 deletions(-) create mode 100644 Tank/src/ExtentionDrawingTank.java diff --git a/Tank/.idea/misc.xml b/Tank/.idea/misc.xml index 5d30da4..1e4328b 100644 --- a/Tank/.idea/misc.xml +++ b/Tank/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/Tank/src/ExtentionDrawingTank.java b/Tank/src/ExtentionDrawingTank.java new file mode 100644 index 0000000..f1b644c --- /dev/null +++ b/Tank/src/ExtentionDrawingTank.java @@ -0,0 +1,77 @@ +import java.awt.Color; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.Vector; + +public class ExtentionDrawingTank { + // Создание объекта из строки + public static DrawingArmoVehicle CreateDrawingTank(String info, String separatorForObject, int width, int height) { + String[] strs = info.split(separatorForObject); + if (strs.length == 5) + { + String[] colorValues = strs[2].split(","); + + DrawingArmoVehicle drawingVehicle = new DrawingArmoVehicle(Integer.parseInt(strs[0]), (double)Integer.parseInt(strs[1]), + new Color(Integer.parseInt(colorValues[0].replaceAll("\\D", "")), + Integer.parseInt(colorValues[1].replaceAll("\\D", "")), + Integer.parseInt(colorValues[2].replaceAll("\\D", ""))), + Integer.parseInt(strs[3]), + width, height + ); + + try{ + drawingVehicle.OrnamentsForm = (IOrnamentForm) Class.forName(strs[4]).getDeclaredConstructor().newInstance(); + drawingVehicle.OrnamentsForm.setDigit(drawingVehicle.ArmoVehicle.numWheel); + } catch (Exception e) { + return null; + } + return drawingVehicle; + } + + if(strs.length == 9) { + String[] colorValues = strs[2].split(","); + String[] colorValues2 = strs[5].split(","); + DrawingTank drawingTank = new DrawingTank( + Integer.parseInt(strs[0]), + (float)Integer.parseInt(strs[1]), + new Color( + Integer.parseInt(colorValues[0].replaceAll("\\D", "")), + Integer.parseInt(colorValues[1].replaceAll("\\D", "")), + Integer.parseInt(colorValues[2].replaceAll("\\D", "")) + ), + Integer.parseInt(strs[3]), + new Color( + Integer.parseInt(colorValues2[0].replaceAll("\\D", "")), + Integer.parseInt(colorValues2[1].replaceAll("\\D", "")), + Integer.parseInt(colorValues2[2].replaceAll("\\D", "")) + ), + strs[6].equals("true"), + strs[7].equals("true"), + strs[8].equals("true"), + width, height + ); + try { + drawingTank.OrnamentsForm = (IOrnamentForm)Class.forName(strs[4]).getDeclaredConstructor().newInstance(); + drawingTank.OrnamentsForm.setDigit(drawingTank.ArmoVehicle.numWheel); + } catch (Exception e) { + return null; + } + return drawingTank; + } + return null; + } + + // Получение данных для сохранения в файл + public static String GetDataForSave(DrawingArmoVehicle drawingArmoVehicle, String separatorForObject) { + EntityArmoVehicle vehicle = drawingArmoVehicle.ArmoVehicle; + if (vehicle == null) { + return null; + } + + String str = "" + vehicle.Speed + separatorForObject + (int)vehicle.Weight + separatorForObject + vehicle.BodyColor + separatorForObject + vehicle.numWheel + separatorForObject + drawingArmoVehicle.OrnamentsForm.getClass().getName(); + if (!(vehicle instanceof EntityTank)) { + return str; + } + return str+separatorForObject+((EntityTank)vehicle).AdditionalColor.toString()+separatorForObject+((EntityTank)vehicle).BodyKit+separatorForObject+((EntityTank)vehicle).Caterpillar+separatorForObject+((EntityTank)vehicle).Tower; + } +} \ No newline at end of file diff --git a/Tank/src/FormTankCollection.java b/Tank/src/FormTankCollection.java index a0b96b0..7fb5fd6 100644 --- a/Tank/src/FormTankCollection.java +++ b/Tank/src/FormTankCollection.java @@ -4,10 +4,17 @@ import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.File; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileNameExtensionFilter; import java.util.LinkedList; import java.util.Queue; + public class FormTankCollection { private class Canvas extends JComponent { public Canvas() { @@ -152,14 +159,14 @@ public class FormTankCollection { JButton ButtonRefreshCollection = new JButton("Обновить коллекцию"); ButtonRefreshCollection.addActionListener( new ActionListener() { - public void actionPerformed(ActionEvent e){ + public void actionPerformed(ActionEvent e) { Draw(); } } ); - JButton toFormTankGenerate = new JButton("Генерировать технику"); - toFormTankGenerate.addActionListener( + JButton FormTankGenerate = new JButton("Генерация"); + FormTankGenerate.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { FormTankGenerate formTankGenerate = new FormTankGenerate(); @@ -206,29 +213,144 @@ public class FormTankCollection { } ); + // Создаём панель меню + JMenuBar menuBar = new JMenuBar(); + + // Создаём пункты меню + JMenu fileMenu = new JMenu("File"); + + // Создаём пункты меню + JMenuItem openItem = new JMenuItem("Открыть"); + openItem.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + JFileChooser fileChooser = new JFileChooser(); + + fileChooser.setDialogTitle("Выберите файл для загрузки данных"); + + // Установка фильтра для файлов с определённым расширеним (например, txt) + fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt")); + + fileChooser.setDialogTitle("Выберите файл для загрузки данных"); + if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { + File selectedFile = fileChooser.getSelectedFile(); + if (_storage.LoadData(selectedFile.getAbsolutePath())) { + JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат", JOptionPane.INFORMATION_MESSAGE); + } else { + JOptionPane.showMessageDialog(null, "Не загрузилось", "Результат", JOptionPane.ERROR_MESSAGE); + } + } + ReloadObjects(); + } + }); + + JMenuItem saveItem = new JMenuItem("Сохранить"); + saveItem.addActionListener( + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("Выберите файл для сохранения данных"); + + // Установка фильтра для файлов с определённым расширением (например, txt) + fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt")); + + if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { + File selectedFile = fileChooser.getSelectedFile(); + if(_storage.SaveData(selectedFile.getAbsolutePath())) + JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат", JOptionPane.INFORMATION_MESSAGE); + else + JOptionPane.showMessageDialog(null, "Не сохранилось", "Результат", JOptionPane.ERROR_MESSAGE); + } + } + } + ); + + JMenuItem openItemSingle = new JMenuItem("Открыть одиночный"); + openItemSingle.addActionListener( + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JFileChooser fileChooser = new JFileChooser(); + + fileChooser.setDialogTitle("Выберите файл для загрузки данных"); + + //Установка фильтра для файлов с определённым расширением (например, txt) + fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt")); + + fileChooser.setDialogTitle("Выберите файл для загрузки данных"); + if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { + File selectedFile = fileChooser.getSelectedFile(); + + if (_storage.LoadDataSingle(selectedFile.getAbsolutePath())) { + JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат", JOptionPane.INFORMATION_MESSAGE); + } else { + JOptionPane.showMessageDialog(null, "Не загрузилось", "Результат", JOptionPane.ERROR_MESSAGE); + } + } + ReloadObjects(); + } + }); + + JMenuItem saveItemSingle = new JMenuItem("Сохранение одиночного"); + saveItemSingle.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e){ + if (jListStorage.getSelectedValue() == null){ + JOptionPane.showMessageDialog(null, "Не выбран гараж", "Ошибка", JOptionPane.ERROR_MESSAGE); + return; + } + + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("Выберите файл для сохранения данных"); + + // Установка фильтра для файлов с определенным расширением (например, .txt) + fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt")); + + if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { + File selectedFile = fileChooser.getSelectedFile(); + if (_storage.SaveDataSingle(selectedFile.getAbsolutePath(), jListStorage.getSelectedValue())) + JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат", JOptionPane.INFORMATION_MESSAGE); + else + JOptionPane.showMessageDialog(null, "Не сохранилось", "Результат", JOptionPane.ERROR_MESSAGE); + } + } + } + ); + + // Добавляем пункты в меню + fileMenu.add(openItem); + fileMenu.add(saveItem); + fileMenu.add(openItemSingle); + fileMenu.add(saveItemSingle); + + // Добавляем меню в панель меню + menuBar.add(fileMenu); + Frame.setSize(880, 520); Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Frame.setLayout(null); canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight); - ButtonAddVehicle.setBounds(pictureBoxWidth - 10, 10, 170, 30); - TextBoxNumber.setBounds(pictureBoxWidth - 10, 50, 170, 30); - ButtonRemoveTank.setBounds(pictureBoxWidth - 10, 90, 170, 30); - ButtonRefreshCollection.setBounds(pictureBoxWidth - 10, 130, 170, 30); - toFormTankGenerate.setBounds(pictureBoxWidth - 10, 170, 170, 30); + ButtonAddVehicle.setBounds(pictureBoxWidth, 0, 160, 20); + TextBoxNumber.setBounds(pictureBoxWidth, 30, 160, 20); + ButtonRemoveTank.setBounds(pictureBoxWidth, 60, 160, 20); + ButtonRefreshCollection.setBounds(pictureBoxWidth, 90, 160, 20); + FormTankGenerate.setBounds(pictureBoxWidth, 120, 160, 20); - buttonAddSet.setBounds(pictureBoxWidth - 10, 210, 170, 20); - textBoxSetName.setBounds(pictureBoxWidth - 10, 240, 170, 20); - jListStorage.setBounds(pictureBoxWidth - 10, 270, 170, 80); - buttonRemoveSet.setBounds(pictureBoxWidth - 10, 360, 170, 20); + buttonAddSet.setBounds(pictureBoxWidth, 150, 160, 20); + textBoxSetName.setBounds(pictureBoxWidth, 180, 160, 20); + jListStorage.setBounds(pictureBoxWidth, 210, 160, 80); + buttonRemoveSet.setBounds(pictureBoxWidth, 300, 160, 20); + menuBar.setBounds(pictureBoxWidth, 360, 160, 20); - buttonGetRemoved.setBounds(pictureBoxWidth - 10, 390, 170, 20); + buttonGetRemoved.setBounds(pictureBoxWidth, 330, 160, 20); Frame.add(canv); Frame.add(ButtonAddVehicle); Frame.add(ButtonRemoveTank); Frame.add(ButtonRefreshCollection); Frame.add(TextBoxNumber); - Frame.add(toFormTankGenerate); + Frame.add(FormTankGenerate); Frame.add(buttonAddSet); Frame.add(textBoxSetName); @@ -236,6 +358,7 @@ public class FormTankCollection { Frame.add(buttonRemoveSet); Frame.add(buttonGetRemoved); + Frame.add(menuBar); Frame.setVisible(true); } diff --git a/Tank/src/SetGeneric.java b/Tank/src/SetGeneric.java index 7ab88d6..ee9f04e 100644 --- a/Tank/src/SetGeneric.java +++ b/Tank/src/SetGeneric.java @@ -4,7 +4,7 @@ public class SetGeneric { // Массив объектов, которые храним private final ArrayList _places; // Количество объектов в массиве - public int Count() { return _places.size(); } + public int Count() { return _places.size(); } // Максимальное количество объектов в списке private final int _maxCount; @@ -86,4 +86,5 @@ public class SetGeneric { } }; } + public void clear() { _places.clear(); } } \ No newline at end of file diff --git a/Tank/src/TanksGenericCollections.java b/Tank/src/TanksGenericCollections.java index 6a9654b..8632d9c 100644 --- a/Tank/src/TanksGenericCollections.java +++ b/Tank/src/TanksGenericCollections.java @@ -14,6 +14,11 @@ public class TanksGenericCollections _collection; + // Получение объектов коллекции + public Iterable getTanks(final Integer maxTanks) { return _collection.GetTanks(maxTanks); } + + public void clear() { _collection.clear(); } + // Конструктор public TanksGenericCollections(int pictureWidth, int pictureHeight) { int width = pictureWidth / _placeSizeWidth; diff --git a/Tank/src/TanksGenericStorage.java b/Tank/src/TanksGenericStorage.java index 4be661a..755d5ac 100644 --- a/Tank/src/TanksGenericStorage.java +++ b/Tank/src/TanksGenericStorage.java @@ -1,7 +1,171 @@ import java.util.*; import java.util.stream.Collectors; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; public class TanksGenericStorage { + // Разделитель для записи ключа и значения элемента словаря + private static String _separatorForKeyValueWR = "|"; + private static String _separatorForKeyValue = "\\|"; + + // Разделитель для записей коллекции данных в файл + private String _separatorRecordsWR = ";"; + private String _separatorRecords = "\\;"; + + // Разделитель для записи информации по объекту в файл + private static String _separatorForObjectWR = ":"; + private static String _separatorForObject = "\\:"; + + public boolean SaveDataSingle(String filename, String key) { + if(new File(filename).exists()) { + new File(filename).delete(); + } + + StringBuilder data = new StringBuilder(); + data.append(key).append("\n"); + for (DrawingArmoVehicle elem: _tankStorages.get(key).getTanks(100)) { + if(_tankStorages.get(key).getTanks(100) == null) + break; + data.append(elem != null ? ExtentionDrawingTank.GetDataForSave(elem, _separatorForObjectWR) + "\n" : ""); + } + + if(data.length() == 0) + return false; + + try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) { + writer.write("TankStorageSingle" + System.lineSeparator() + data.toString()); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + public boolean LoadDataSingle(String filename) { + if(!new File(filename).exists()) { + return false; + } + + try (BufferedReader reader = new BufferedReader(new FileReader(filename))) { + String s = reader.readLine(); + if(s == null || s.length() == 0) + return false; + + if(!s.startsWith("TankStorageSingle")) + return false; + + String key = reader.readLine(); + if(key == null || key.length() == 0) + return false; + + TanksGenericCollections collections = new TanksGenericCollections<>(_pictureWidth, _pictureHeight); + if (_tankStorages.containsKey(key)){ + collections = _tankStorages.get(key); + collections.clear(); + } + else + collections = new TanksGenericCollections<>(_pictureWidth, _pictureHeight); + + List tanksStrings = new ArrayList(); + + s = reader.readLine(); + while (s != null && s.length() != 0) { + tanksStrings.add(s); + s = reader.readLine(); + } + + Collections.reverse(tanksStrings); + for (String elem : tanksStrings) { + DrawingArmoVehicle vehicle = ExtentionDrawingTank.CreateDrawingTank(elem, _separatorForObject, _pictureWidth, _pictureHeight); + if(vehicle == null || collections.Add(vehicle) == -1) + return false; + } + + if(_tankStorages.containsKey(key)) + _tankStorages.remove(key); + _tankStorages.put(key, collections); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + return true; + } + + // Сохранение информации по технике в хранилище в файл + public boolean SaveData(String filename) { + if(new File(filename).exists()) + new File(filename).delete(); + + StringBuilder data = new StringBuilder(); + + for (Map.Entry> record : _tankStorages.entrySet()) { + StringBuilder records = new StringBuilder(); + for (DrawingArmoVehicle elem : record.getValue().getTanks(100)) { + records.append(elem != null ? ExtentionDrawingTank.GetDataForSave(elem, _separatorForObjectWR) + _separatorRecordsWR : ""); + } + data.append(record.getKey()).append(_separatorForKeyValueWR).append(records).append("\n"); + } + + if (data.length() == 0) + return false; + + try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) { + writer.write("TankStorage" + System.lineSeparator() + data.toString()); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + return true; + } + + // Загрузка информации по технике в хранилище из файла + public boolean LoadData(String filename) { + if (!new File(filename).exists()) { + return false; + } + + try (BufferedReader reader = new BufferedReader(new FileReader(filename))) { + String s = reader.readLine(); + if (s == null || s.length() == 0) + return false; + + if (!s.startsWith("TankStorage")) + return false; + + _tankStorages.clear(); + + s = reader.readLine(); + while (s != null && s.length() != 0) { + String[] record = s.split(_separatorForKeyValue); + s = reader.readLine(); + if (record.length != 2) { + continue; + } + TanksGenericCollections collection = new TanksGenericCollections<>(_pictureWidth, _pictureHeight); + String[] set = record[1].split(_separatorRecords); + List reversedSet = Arrays.asList(set); + Collections.reverse(reversedSet); + for (String elem : reversedSet) { + DrawingArmoVehicle train = ExtentionDrawingTank.CreateDrawingTank(elem, _separatorForObject, _pictureWidth, _pictureHeight); + if (train == null || collection.Add(train) == -1) + return false; + } + _tankStorages.put(record[0], collection); + } + } catch (IOException e) { + e.printStackTrace(); + return false; + } + return true; + } + // Словарь (как хранилище) HashMap> _tankStorages; -- 2.25.1 From eba176d3cf18f142677688423a3302ce9e9306c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Fri, 1 Dec 2023 00:00:57 +0400 Subject: [PATCH 2/7] fix lab 6 --- Tank/.idea/misc.xml | 1 + Tank/src/FormTankCollection.java | 29 ++++++++++++++--------------- Tank/src/SetGeneric.java | 2 +- Tank/src/TanksGenericStorage.java | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Tank/.idea/misc.xml b/Tank/.idea/misc.xml index 1e4328b..5d30da4 100644 --- a/Tank/.idea/misc.xml +++ b/Tank/.idea/misc.xml @@ -1,3 +1,4 @@ + diff --git a/Tank/src/FormTankCollection.java b/Tank/src/FormTankCollection.java index 7fb5fd6..915f767 100644 --- a/Tank/src/FormTankCollection.java +++ b/Tank/src/FormTankCollection.java @@ -14,7 +14,6 @@ import javax.swing.filechooser.FileNameExtensionFilter; import java.util.LinkedList; import java.util.Queue; - public class FormTankCollection { private class Canvas extends JComponent { public Canvas() { @@ -165,8 +164,8 @@ public class FormTankCollection { } ); - JButton FormTankGenerate = new JButton("Генерация"); - FormTankGenerate.addActionListener( + JButton toFormTankGenerate = new JButton("Генерировать технику"); + toFormTankGenerate.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { FormTankGenerate formTankGenerate = new FormTankGenerate(); @@ -331,26 +330,26 @@ public class FormTankCollection { Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Frame.setLayout(null); canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight); - ButtonAddVehicle.setBounds(pictureBoxWidth, 0, 160, 20); - TextBoxNumber.setBounds(pictureBoxWidth, 30, 160, 20); - ButtonRemoveTank.setBounds(pictureBoxWidth, 60, 160, 20); - ButtonRefreshCollection.setBounds(pictureBoxWidth, 90, 160, 20); - FormTankGenerate.setBounds(pictureBoxWidth, 120, 160, 20); + ButtonAddVehicle.setBounds(pictureBoxWidth - 10, 10, 170, 30); + TextBoxNumber.setBounds(pictureBoxWidth - 10, 50, 170, 30); + ButtonRemoveTank.setBounds(pictureBoxWidth - 10, 90, 170, 30); + ButtonRefreshCollection.setBounds(pictureBoxWidth - 10, 130, 170, 30); + toFormTankGenerate.setBounds(pictureBoxWidth - 10, 170, 170, 30); - buttonAddSet.setBounds(pictureBoxWidth, 150, 160, 20); - textBoxSetName.setBounds(pictureBoxWidth, 180, 160, 20); - jListStorage.setBounds(pictureBoxWidth, 210, 160, 80); - buttonRemoveSet.setBounds(pictureBoxWidth, 300, 160, 20); - menuBar.setBounds(pictureBoxWidth, 360, 160, 20); + buttonAddSet.setBounds(pictureBoxWidth - 10, 210, 170, 20); + textBoxSetName.setBounds(pictureBoxWidth - 10, 240, 170, 20); + jListStorage.setBounds(pictureBoxWidth - 10, 270, 170, 80); + buttonRemoveSet.setBounds(pictureBoxWidth - 10, 360, 170, 20); + buttonGetRemoved.setBounds(pictureBoxWidth - 10, 390, 170, 20); - buttonGetRemoved.setBounds(pictureBoxWidth, 330, 160, 20); + menuBar.setBounds(pictureBoxWidth - 10, 420, 170, 20); Frame.add(canv); Frame.add(ButtonAddVehicle); Frame.add(ButtonRemoveTank); Frame.add(ButtonRefreshCollection); Frame.add(TextBoxNumber); - Frame.add(FormTankGenerate); + Frame.add(toFormTankGenerate); Frame.add(buttonAddSet); Frame.add(textBoxSetName); diff --git a/Tank/src/SetGeneric.java b/Tank/src/SetGeneric.java index ee9f04e..a404521 100644 --- a/Tank/src/SetGeneric.java +++ b/Tank/src/SetGeneric.java @@ -4,7 +4,7 @@ public class SetGeneric { // Массив объектов, которые храним private final ArrayList _places; // Количество объектов в массиве - public int Count() { return _places.size(); } + public int Count() { return _places.size(); } // Максимальное количество объектов в списке private final int _maxCount; diff --git a/Tank/src/TanksGenericStorage.java b/Tank/src/TanksGenericStorage.java index 755d5ac..1d8569f 100644 --- a/Tank/src/TanksGenericStorage.java +++ b/Tank/src/TanksGenericStorage.java @@ -31,7 +31,7 @@ public class TanksGenericStorage { StringBuilder data = new StringBuilder(); data.append(key).append("\n"); for (DrawingArmoVehicle elem: _tankStorages.get(key).getTanks(100)) { - if(_tankStorages.get(key).getTanks(100) == null) + if(_tankStorages.get(key) == null) break; data.append(elem != null ? ExtentionDrawingTank.GetDataForSave(elem, _separatorForObjectWR) + "\n" : ""); } -- 2.25.1 From 714984992e92784c9dab8b498e42b19b19fe4f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Sat, 2 Dec 2023 02:14:24 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/FormTankCollection.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tank/src/FormTankCollection.java b/Tank/src/FormTankCollection.java index 915f767..bd5f100 100644 --- a/Tank/src/FormTankCollection.java +++ b/Tank/src/FormTankCollection.java @@ -158,7 +158,7 @@ public class FormTankCollection { JButton ButtonRefreshCollection = new JButton("Обновить коллекцию"); ButtonRefreshCollection.addActionListener( new ActionListener() { - public void actionPerformed(ActionEvent e) { + public void actionPerformed(ActionEvent e){ Draw(); } } @@ -340,6 +340,7 @@ public class FormTankCollection { textBoxSetName.setBounds(pictureBoxWidth - 10, 240, 170, 20); jListStorage.setBounds(pictureBoxWidth - 10, 270, 170, 80); buttonRemoveSet.setBounds(pictureBoxWidth - 10, 360, 170, 20); + buttonGetRemoved.setBounds(pictureBoxWidth - 10, 390, 170, 20); menuBar.setBounds(pictureBoxWidth - 10, 420, 170, 20); -- 2.25.1 From 687b2aec17038a8b399d00e69d3a005a3ff5dc59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Sat, 2 Dec 2023 02:46:57 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/TanksGenericStorage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tank/src/TanksGenericStorage.java b/Tank/src/TanksGenericStorage.java index 1d8569f..f133745 100644 --- a/Tank/src/TanksGenericStorage.java +++ b/Tank/src/TanksGenericStorage.java @@ -32,7 +32,7 @@ public class TanksGenericStorage { data.append(key).append("\n"); for (DrawingArmoVehicle elem: _tankStorages.get(key).getTanks(100)) { if(_tankStorages.get(key) == null) - break; + return false; data.append(elem != null ? ExtentionDrawingTank.GetDataForSave(elem, _separatorForObjectWR) + "\n" : ""); } -- 2.25.1 From 23173f993653a365534a99e1b947d367c46f2880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Sat, 2 Dec 2023 03:00:35 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/TanksGenericStorage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tank/src/TanksGenericStorage.java b/Tank/src/TanksGenericStorage.java index f133745..7b03c24 100644 --- a/Tank/src/TanksGenericStorage.java +++ b/Tank/src/TanksGenericStorage.java @@ -100,8 +100,9 @@ public class TanksGenericStorage { // Сохранение информации по технике в хранилище в файл public boolean SaveData(String filename) { - if(new File(filename).exists()) + if(new File(filename).exists()) { new File(filename).delete(); + } StringBuilder data = new StringBuilder(); -- 2.25.1 From 92e00e4304589e546bd5c467582e34e0b4c8c94c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Sat, 2 Dec 2023 03:06:00 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/TanksGenericStorage.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tank/src/TanksGenericStorage.java b/Tank/src/TanksGenericStorage.java index 7b03c24..a6760e6 100644 --- a/Tank/src/TanksGenericStorage.java +++ b/Tank/src/TanksGenericStorage.java @@ -33,7 +33,9 @@ public class TanksGenericStorage { for (DrawingArmoVehicle elem: _tankStorages.get(key).getTanks(100)) { if(_tankStorages.get(key) == null) return false; - data.append(elem != null ? ExtentionDrawingTank.GetDataForSave(elem, _separatorForObjectWR) + "\n" : ""); + + if(_tankStorages.get(key) != null) + data.append(elem != null ? ExtentionDrawingTank.GetDataForSave(elem, _separatorForObjectWR) + "\n" : ""); } if(data.length() == 0) -- 2.25.1 From f4373424ba4c40086bb830af1f06c3f94d11b484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Tue, 5 Dec 2023 02:01:09 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/TanksGenericStorage.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tank/src/TanksGenericStorage.java b/Tank/src/TanksGenericStorage.java index a6760e6..624d8d1 100644 --- a/Tank/src/TanksGenericStorage.java +++ b/Tank/src/TanksGenericStorage.java @@ -156,8 +156,8 @@ public class TanksGenericStorage { List reversedSet = Arrays.asList(set); Collections.reverse(reversedSet); for (String elem : reversedSet) { - DrawingArmoVehicle train = ExtentionDrawingTank.CreateDrawingTank(elem, _separatorForObject, _pictureWidth, _pictureHeight); - if (train == null || collection.Add(train) == -1) + DrawingArmoVehicle vehicle = ExtentionDrawingTank.CreateDrawingTank(elem, _separatorForObject, _pictureWidth, _pictureHeight); + if (vehicle == null || collection.Add(vehicle) == -1) return false; } _tankStorages.put(record[0], collection); -- 2.25.1