laba4 Кувшинов Тимур ПИбд-21 Сложная #6

Closed
TImourka wants to merge 7 commits from laba4 into laba3
3 changed files with 43 additions and 14 deletions
Showing only changes of commit b96bc6dcad - Show all commits

View File

@ -7,7 +7,6 @@ import java.awt.event.*;
public class FormTrain{
private class Canvas extends JComponent{
public DrawingTrain _drawingTrain;
public Canvas(){
}
public void paintComponent (Graphics g){
@ -147,7 +146,6 @@ public class FormTrain{
pictureBoxWidth,
pictureBoxHeight);
_drawingTrain.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
canv._drawingTrain = _drawingTrain;
Draw();
}
}
@ -172,7 +170,6 @@ public class FormTrain{
pictureBoxWidth,
pictureBoxHeight);
_drawingTrain.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
canv._drawingTrain = _drawingTrain;
Draw();
}
}

View File

@ -4,6 +4,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
@ -45,6 +46,7 @@ public class FormTrainCollecltion {
canv.repaint();
}
private LinkedList<DrawingTrain> linkedListRemoved;
private JList<String> jListStorage;
private DefaultListModel<String> listModel;
/// <summary>
@ -110,7 +112,8 @@ public class FormTrainCollecltion {
}
}
);
linkedListRemoved = new LinkedList<DrawingTrain>();
JTextField TextBoxNumber = new JTextField();
JButton ButtonRemoveTrain = new JButton("Remove Train");
ButtonRemoveTrain.addActionListener(
@ -145,8 +148,10 @@ public class FormTrainCollecltion {
}
int pos = Integer.parseInt(TextBoxNumber.getText());
if (obj.remove(pos) != null)
var removed = obj.remove(pos);
if (removed != null)
{
linkedListRemoved.add(removed);
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
System.out.println("Объект удален");
Draw();
@ -160,6 +165,23 @@ public class FormTrainCollecltion {
}
);
JButton buttonGetRemoved = new JButton("buttonGetRemoved");
buttonGetRemoved.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e){
if (linkedListRemoved.size()==0){
JOptionPane.showMessageDialog(null, "Нет удалённых", "Информация", JOptionPane.INFORMATION_MESSAGE);
System.out.println("Нет удалённых");
return;
}
FormTrain form = new FormTrain();
form._drawingTrain = linkedListRemoved.getLast();
linkedListRemoved.removeLast();
form.Draw();
}
}
);
JButton ButtonRefreshCollection = new JButton("Refresh Collection");
ButtonRefreshCollection.addActionListener(
new ActionListener() {
@ -236,6 +258,8 @@ public class FormTrainCollecltion {
jListStorage.setBounds(pictureBoxWidth, 210, 160, 80);
buttonRemoveSet.setBounds(pictureBoxWidth, 300, 160, 20);
buttonGetRemoved.setBounds(pictureBoxWidth, 330, 160, 20);
w.add(canv);
w.add(ButtonAddTrain);
w.add(ButtonRemoveTrain);
@ -248,6 +272,8 @@ public class FormTrainCollecltion {
w.add(jListStorage);
w.add(buttonRemoveSet);
w.add(buttonGetRemoved);
w.setVisible(true);
}
}

View File

@ -8,11 +8,11 @@ public class TrainsGenericStorage {
/// <summary>
/// Словарь (хранилище)
/// </summary>
HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>> _carStorages;
HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>> _trainStorages;
/// <summary>
/// Возвращение списка названий наборов
/// </summary>
public List<String> Keys(){return _carStorages.keySet().stream().collect(Collectors.toList());}
public List<String> Keys(){return _trainStorages.keySet().stream().collect(Collectors.toList());}
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -28,7 +28,7 @@ public class TrainsGenericStorage {
/// <param name="pictureHeight"></param>
public TrainsGenericStorage(int pictureWidth, int pictureHeight)
{
_carStorages = new HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>>();
_trainStorages = new HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
@ -38,9 +38,9 @@ public class TrainsGenericStorage {
/// <param name="name">Название набора</param>
public void AddSet(String name)
{
if (_carStorages.containsKey(name))
if (_trainStorages.containsKey(name))
return;
_carStorages.put(name, new TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>(_pictureWidth, _pictureHeight));
_trainStorages.put(name, new TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>(_pictureWidth, _pictureHeight));
}
/// <summary>
/// Удаление набора
@ -48,9 +48,9 @@ public class TrainsGenericStorage {
/// <param name="name">Название набора</param>
public void DelSet(String name)
{
if (!_carStorages.containsKey(name))
if (!_trainStorages.containsKey(name))
return;
_carStorages.remove(name);
_trainStorages.remove(name);
}
/// <summary>
/// Доступ к набору
@ -59,8 +59,14 @@ public class TrainsGenericStorage {
/// <returns></returns>
public TrainsGenericCollection<DrawingTrain, DrawningObjectTrain> get(String ind)
{
if (_carStorages.containsKey(ind))
return _carStorages.get(ind);
if (_trainStorages.containsKey(ind))
return _trainStorages.get(ind);
return null;
}
public DrawningObjectTrain get(String ind1, int ind2){
if (!_trainStorages.containsKey(ind1))
return null;
return _trainStorages.get(ind1).GetU(ind2);
}
}