Лабораторная работа №4 (2 часть)
This commit is contained in:
parent
2040af37fc
commit
a0fbbbb129
@ -31,7 +31,7 @@ public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||
@Override
|
||||
public int Insert(T obj, int position) {
|
||||
if (Count() == _maxCount) return -1;
|
||||
if (position >= Count() || position < 0) return -1;
|
||||
if (position > Count() || position < 0) return -1;
|
||||
_collection.add(position, obj);
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{
|
||||
@Override
|
||||
public void SetMaxCount(int value, Class<T> type) {
|
||||
if (value > 0) {
|
||||
_collection = (T[]) Array.newInstance(type, value);
|
||||
if (_collection == null)
|
||||
_collection = (T[]) Array.newInstance(type, value);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class FormCleaningCar extends JFrame {
|
||||
protected DrawningTruck _drawningTruck;
|
||||
private DrawningTruck _drawningTruck;
|
||||
private JPanel pictureBox;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonLeft;
|
||||
|
@ -8,7 +8,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<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"/>
|
||||
<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"/>
|
||||
@ -168,6 +168,14 @@
|
||||
</component>
|
||||
</children>
|
||||
</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>
|
||||
</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">
|
||||
|
@ -8,6 +8,7 @@ import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.ParseException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
@ -16,6 +17,7 @@ import static java.lang.Integer.parseInt;
|
||||
public class FormCleaningCarCollection extends JFrame{
|
||||
private AbstractCompany _company = null;
|
||||
private StorageCollection<DrawningTruck> _storageCollection;
|
||||
private LinkedList<DrawningTruck> _resurrected;
|
||||
private JPanel panel;
|
||||
private JPanel tools;
|
||||
private JComboBox comboBoxSelectorCompany;
|
||||
@ -37,6 +39,7 @@ public class FormCleaningCarCollection extends JFrame{
|
||||
private JButton buttonCollectionDel;
|
||||
private JButton buttonCreateCompany;
|
||||
private JPanel panelCompanyTools;
|
||||
private JButton buttonResurrected;
|
||||
|
||||
public FormCleaningCarCollection() {
|
||||
setTitle("Коллекция уборочных машин");
|
||||
@ -46,6 +49,7 @@ public class FormCleaningCarCollection extends JFrame{
|
||||
add(panel);
|
||||
|
||||
_storageCollection = new StorageCollection<>();
|
||||
_resurrected = new LinkedList<>();
|
||||
|
||||
tools.setBackground(new Color(220, 220, 220));
|
||||
tools.setBorder(BorderFactory.createTitledBorder("Инструменты"));
|
||||
@ -69,6 +73,9 @@ public class FormCleaningCarCollection extends JFrame{
|
||||
});
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(radioButtonList); group.add(radioButtonMassive);
|
||||
for (Component i : panelCompanyTools.getComponents()) {
|
||||
i.setBackground(Color.GRAY);
|
||||
}
|
||||
Init();
|
||||
}
|
||||
private void Init() {
|
||||
@ -77,6 +84,9 @@ public class FormCleaningCarCollection extends JFrame{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
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)) {
|
||||
case 0:
|
||||
int pos = parseInt(maskedTextBox.getText());
|
||||
DrawningTruck truck = _company._collection.Get(pos);
|
||||
if (truck != null) _resurrected.add(truck);
|
||||
if (_company._collection.Remove(pos) != null) {
|
||||
JOptionPane.showMessageDialog(null, "Объект удалён");
|
||||
repaint();
|
||||
@ -207,9 +219,23 @@ public class FormCleaningCarCollection extends JFrame{
|
||||
}
|
||||
|
||||
panelCompanyTools.setEnabled(true);
|
||||
for (Component i : panelCompanyTools.getComponents()) {
|
||||
i.setBackground(buttonCreateCompany.getBackground());
|
||||
}
|
||||
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) {
|
||||
if (_company == null) return;
|
||||
@ -227,7 +253,7 @@ public class FormCleaningCarCollection extends JFrame{
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
if (_company._collection.Insert(drawningTruck, 0) != -1) {
|
||||
if (_company._collection.Insert(drawningTruck) != -1) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
repaint();
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user