Lab4 Done

This commit is contained in:
Yunusov_Niyaz 2023-12-07 18:03:57 +04:00
parent 4aedc22ade
commit 4efda8d15b
5 changed files with 10 additions and 39 deletions

View File

@ -24,10 +24,7 @@ public class BusesGenericCollection<T extends DrawingBus, U extends IMoveableObj
}
public boolean remove(int pos)
{
T obj = _collection.Get(pos);
if (obj != null)
return _collection.remove(pos);
return false;
}
public U GetU(int pos) {
if(_collection.Get(pos) == null)

View File

@ -1,4 +1,3 @@
import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

View File

@ -2,21 +2,19 @@ import javax.swing.*;
import javax.swing.border.StrokeBorder;
import java.awt.*;
import java.io.IOException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.ArrayDeque;
import java.util.Queue;
public class FrameBusCollection extends JFrame {
private BusesGenericStorage storage;
private JList<String> listBoxStorages;
private DefaultListModel<String> listBoxModel;
TrashCollection<DrawingBus> trashCollection = new TrashCollection<>();
JComponent pictureBoxCollection;
TextField textFieldNumber;
TextField textFieldStorageName;
Queue <DrawingBus> queue = new ArrayDeque<>();
public FrameBusCollection(){
super("Набор автобусов");
setSize(new Dimension(1000,500));
@ -132,8 +130,7 @@ public class FrameBusCollection extends JFrame {
if (obj == null)
return;
int pos = Integer.parseInt(textFieldNumber.getText());
var bus = obj.Get(pos);
trashCollection.push(obj.Get(pos));
queue.add(obj.Get(pos));
if (obj.remove(pos))
{
JOptionPane.showMessageDialog(this,"Объект удалён");
@ -179,16 +176,17 @@ public class FrameBusCollection extends JFrame {
reloadObjects();
}
private void buttonTrashClick(){
if(trashCollection.getSize() == 0)
if(queue.size() == 0)
return;
FrameTrolleybus form;
try{
form = new FrameTrolleybus();
form.ChangeTrolleybus(queue.peek());
queue.remove();
}
catch (IOException e){
throw new RuntimeException();
}
form.ChangeTrolleybus(trashCollection.getTop());
trashCollection.pop();
}
}

View File

@ -12,8 +12,7 @@ public class SetGeneric<T extends Object>{
public boolean insert(T bus){
if(places.size() == maxCount)
return false;
insert(bus, 0);
return true;
return insert(bus, 0);
}
public boolean insert(T bus, int position){
if (!(position >= 0 && position <= places.size() && places.size() < maxCount))

View File

@ -1,22 +0,0 @@
import java.util.ArrayDeque;
import java.util.Queue;
public class TrashCollection <T> {
Queue <T> _queue;
public TrashCollection(){
_queue = new ArrayDeque<>();
}
public void push(T bus){
_queue.add(bus);
}
public int getSize(){
return _queue.size();
}
public void pop(){
if(_queue.size() ==0)
return;
_queue.remove();
}
public T getTop(){
return _queue.peek();
}
}