Лабораторная работа №4 (2 часть)
This commit is contained in:
parent
2040af37fc
commit
a0fbbbb129
@ -31,7 +31,7 @@ public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
|||||||
@Override
|
@Override
|
||||||
public int Insert(T obj, int position) {
|
public int Insert(T obj, int position) {
|
||||||
if (Count() == _maxCount) return -1;
|
if (Count() == _maxCount) return -1;
|
||||||
if (position >= Count() || position < 0) return -1;
|
if (position > Count() || position < 0) return -1;
|
||||||
_collection.add(position, obj);
|
_collection.add(position, obj);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{
|
|||||||
@Override
|
@Override
|
||||||
public void SetMaxCount(int value, Class<T> type) {
|
public void SetMaxCount(int value, Class<T> type) {
|
||||||
if (value > 0) {
|
if (value > 0) {
|
||||||
|
if (_collection == null)
|
||||||
_collection = (T[]) Array.newInstance(type, value);
|
_collection = (T[]) Array.newInstance(type, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class FormCleaningCar extends JFrame {
|
public class FormCleaningCar extends JFrame {
|
||||||
protected DrawningTruck _drawningTruck;
|
private DrawningTruck _drawningTruck;
|
||||||
private JPanel pictureBox;
|
private JPanel pictureBox;
|
||||||
private JButton buttonRight;
|
private JButton buttonRight;
|
||||||
private JButton buttonLeft;
|
private JButton buttonLeft;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<children>
|
||||||
<grid id="ed6cf" binding="tools" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="ed6cf" binding="tools" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="1" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="1" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
@ -168,6 +168,14 @@
|
|||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
|
<component id="b5aef" class="javax.swing.JButton" binding="buttonResurrected">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Из удалённых"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
<grid id="abc4c" binding="pictureBox" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="abc4c" binding="pictureBox" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
@ -8,6 +8,7 @@ import java.awt.*;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ import static java.lang.Integer.parseInt;
|
|||||||
public class FormCleaningCarCollection extends JFrame{
|
public class FormCleaningCarCollection extends JFrame{
|
||||||
private AbstractCompany _company = null;
|
private AbstractCompany _company = null;
|
||||||
private StorageCollection<DrawningTruck> _storageCollection;
|
private StorageCollection<DrawningTruck> _storageCollection;
|
||||||
|
private LinkedList<DrawningTruck> _resurrected;
|
||||||
private JPanel panel;
|
private JPanel panel;
|
||||||
private JPanel tools;
|
private JPanel tools;
|
||||||
private JComboBox comboBoxSelectorCompany;
|
private JComboBox comboBoxSelectorCompany;
|
||||||
@ -37,6 +39,7 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
private JButton buttonCollectionDel;
|
private JButton buttonCollectionDel;
|
||||||
private JButton buttonCreateCompany;
|
private JButton buttonCreateCompany;
|
||||||
private JPanel panelCompanyTools;
|
private JPanel panelCompanyTools;
|
||||||
|
private JButton buttonResurrected;
|
||||||
|
|
||||||
public FormCleaningCarCollection() {
|
public FormCleaningCarCollection() {
|
||||||
setTitle("Коллекция уборочных машин");
|
setTitle("Коллекция уборочных машин");
|
||||||
@ -46,6 +49,7 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
add(panel);
|
add(panel);
|
||||||
|
|
||||||
_storageCollection = new StorageCollection<>();
|
_storageCollection = new StorageCollection<>();
|
||||||
|
_resurrected = new LinkedList<>();
|
||||||
|
|
||||||
tools.setBackground(new Color(220, 220, 220));
|
tools.setBackground(new Color(220, 220, 220));
|
||||||
tools.setBorder(BorderFactory.createTitledBorder("Инструменты"));
|
tools.setBorder(BorderFactory.createTitledBorder("Инструменты"));
|
||||||
@ -69,6 +73,9 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
});
|
});
|
||||||
ButtonGroup group = new ButtonGroup();
|
ButtonGroup group = new ButtonGroup();
|
||||||
group.add(radioButtonList); group.add(radioButtonMassive);
|
group.add(radioButtonList); group.add(radioButtonMassive);
|
||||||
|
for (Component i : panelCompanyTools.getComponents()) {
|
||||||
|
i.setBackground(Color.GRAY);
|
||||||
|
}
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
private void Init() {
|
private void Init() {
|
||||||
@ -77,6 +84,9 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
panelCompanyTools.setEnabled(false);
|
panelCompanyTools.setEnabled(false);
|
||||||
|
for (Component i : panelCompanyTools.getComponents()) {
|
||||||
|
i.setBackground(Color.GRAY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -92,6 +102,8 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
switch (JOptionPane.showConfirmDialog(null, "Удалить?", "Удаление", JOptionPane.YES_NO_OPTION)) {
|
switch (JOptionPane.showConfirmDialog(null, "Удалить?", "Удаление", JOptionPane.YES_NO_OPTION)) {
|
||||||
case 0:
|
case 0:
|
||||||
int pos = parseInt(maskedTextBox.getText());
|
int pos = parseInt(maskedTextBox.getText());
|
||||||
|
DrawningTruck truck = _company._collection.Get(pos);
|
||||||
|
if (truck != null) _resurrected.add(truck);
|
||||||
if (_company._collection.Remove(pos) != null) {
|
if (_company._collection.Remove(pos) != null) {
|
||||||
JOptionPane.showMessageDialog(null, "Объект удалён");
|
JOptionPane.showMessageDialog(null, "Объект удалён");
|
||||||
repaint();
|
repaint();
|
||||||
@ -207,9 +219,23 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
}
|
}
|
||||||
|
|
||||||
panelCompanyTools.setEnabled(true);
|
panelCompanyTools.setEnabled(true);
|
||||||
|
for (Component i : panelCompanyTools.getComponents()) {
|
||||||
|
i.setBackground(buttonCreateCompany.getBackground());
|
||||||
|
}
|
||||||
RefreshListBoxItems();
|
RefreshListBoxItems();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
buttonResurrected.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_resurrected.peek() != null) {
|
||||||
|
FormCleaningCar form = new FormCleaningCar();
|
||||||
|
System.out.println(_resurrected.peek());
|
||||||
|
form.SetTruck(_resurrected.pop());
|
||||||
|
System.out.println(_resurrected.peek());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
private void CreateObject(String type) {
|
private void CreateObject(String type) {
|
||||||
if (_company == null) return;
|
if (_company == null) return;
|
||||||
@ -227,7 +253,7 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
break;
|
break;
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
if (_company._collection.Insert(drawningTruck, 0) != -1) {
|
if (_company._collection.Insert(drawningTruck) != -1) {
|
||||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||||
repaint();
|
repaint();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user