Eliseev E.E. LabWork04 #4

Closed
ElEgEv wants to merge 14 commits from LabWork04 into LabWork03
3 changed files with 44 additions and 51 deletions
Showing only changes of commit df30a7abc5 - Show all commits

View File

@ -181,7 +181,7 @@ public class FormMapWithSetPlanesGeneric {
}
FormPlane form = new FormPlane(plane);
form.setSize(500, 300);
form.setSize(700, 500);
form.setVisible(true);
}
});
@ -190,7 +190,7 @@ public class FormMapWithSetPlanesGeneric {
ButtonAddPlane.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(_mapsCollection == null)
if(ListBoxMaps.getSelectedIndex() == -1)
{
return;
}

View File

@ -91,8 +91,6 @@ public class FormPlane extends JDialog
public void CreateWindow()
{
/*setModal(true);*/
//создание строки отображения скорости, веса и цвета объекта
Box LableBox = Box.createHorizontalBox();
LableBox.setMinimumSize(new Dimension(1, 20));
@ -184,7 +182,7 @@ public class FormPlane extends JDialog
return;
}
_plane.ChangeBorders(PictureBoxPlaneWidth, PictureBoxPlaneHeight);
_plane.ChangeBorders(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
try
{

View File

@ -1,18 +1,25 @@
public class SetPlanesGeneric<T extends Object>
import java.util.ArrayList;
import java.util.Iterator;
public class SetPlanesGeneric<T extends Object> implements Iterable<T>
{
//массив объектов, которые храним
private final Object[] _places;
private ArrayList<T> _places;
//максимальное кол-во элементов в списке
private final int _maxCount;
//количество объектов в массиве
public int Count()
{
return _places.length;
return _places.size();
}
//конструктор
public SetPlanesGeneric(int count)
{
_places = new Object[count];
_maxCount = count;
_places = new ArrayList<>();
}
//добавление объекта в набор
@ -25,43 +32,12 @@ public class SetPlanesGeneric<T extends Object>
public int Insert(T plane, int position)
{
//проверка на корректность значения индекса
if (position >= _places.length || position < 0)
if (position >= _maxCount|| position < 0)
{
return -1;
}
//проверка ячейки на пустоту
if (_places[position] == null)
{
_places[position] = plane;
return position;
}
//поиск первой свободной ячейки
int _emptyPositionIndex = -1;
for (int i = position + 1; i < Count(); i++)
{
if (_places[i] == null)
{
_emptyPositionIndex = i;
break;
}
}
//есла пустых ячеек нет
if (_emptyPositionIndex < 0)
{
return -1;
}
//сдвиг объектов
for (int i = _emptyPositionIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = plane;
_places.add(plane);
return position;
}
@ -70,14 +46,14 @@ public class SetPlanesGeneric<T extends Object>
public T Remove(int position)
{
// проверка позиции
if (position >= _places.length || position < 0)
if (position >= _maxCount || position < 0)
{
return null;
}
// удаление объекта из массива, присовив элементу массива значение null
T temp = (T)_places[position];
_places[position] = null;
T temp = _places.get(position);
_places.remove(position);
return temp;
}
@ -85,15 +61,34 @@ public class SetPlanesGeneric<T extends Object>
//получение объекта из набора по позиции
public T Get(int position)
{
if (position >= _places.length || position < 0)
{
return null;
}
else if (_places[position] == null)
if (position >= _maxCount || position < 0)
{
return null;
}
return (T)_places[position];
/*
if (_places.get(position) == null)
{
return null;
}
*/
return _places.get(position);
}
public void Set(int position, T value)
{
if(position >= _maxCount || position < 0)
{
return;
}
Insert(value, position);
}
@Override
public Iterator<T> iterator()
{
return _places.iterator();
}
}