Uraaaaa
This commit is contained in:
parent
c70b820dbe
commit
4db9d1e162
@ -7,7 +7,6 @@ import java.awt.event.*;
|
|||||||
|
|
||||||
public class FormTrain{
|
public class FormTrain{
|
||||||
private class Canvas extends JComponent{
|
private class Canvas extends JComponent{
|
||||||
public DrawingTrain _drawingTrain;
|
|
||||||
public Canvas(){
|
public Canvas(){
|
||||||
}
|
}
|
||||||
public void paintComponent (Graphics g){
|
public void paintComponent (Graphics g){
|
||||||
@ -147,7 +146,6 @@ public class FormTrain{
|
|||||||
pictureBoxWidth,
|
pictureBoxWidth,
|
||||||
pictureBoxHeight);
|
pictureBoxHeight);
|
||||||
_drawingTrain.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
_drawingTrain.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||||
canv._drawingTrain = _drawingTrain;
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +170,6 @@ public class FormTrain{
|
|||||||
pictureBoxWidth,
|
pictureBoxWidth,
|
||||||
pictureBoxHeight);
|
pictureBoxHeight);
|
||||||
_drawingTrain.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
_drawingTrain.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||||
canv._drawingTrain = _drawingTrain;
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import java.awt.Graphics;
|
|||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import javax.swing.DefaultListModel;
|
import javax.swing.DefaultListModel;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@ -45,6 +46,7 @@ public class FormTrainCollecltion {
|
|||||||
canv.repaint();
|
canv.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LinkedList<DrawingTrain> linkedListRemoved;
|
||||||
private JList<String> jListStorage;
|
private JList<String> jListStorage;
|
||||||
private DefaultListModel<String> listModel;
|
private DefaultListModel<String> listModel;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -111,6 +113,7 @@ public class FormTrainCollecltion {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
linkedListRemoved = new LinkedList<DrawingTrain>();
|
||||||
JTextField TextBoxNumber = new JTextField();
|
JTextField TextBoxNumber = new JTextField();
|
||||||
JButton ButtonRemoveTrain = new JButton("Remove Train");
|
JButton ButtonRemoveTrain = new JButton("Remove Train");
|
||||||
ButtonRemoveTrain.addActionListener(
|
ButtonRemoveTrain.addActionListener(
|
||||||
@ -145,8 +148,10 @@ public class FormTrainCollecltion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int pos = Integer.parseInt(TextBoxNumber.getText());
|
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);
|
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||||
System.out.println("Объект удален");
|
System.out.println("Объект удален");
|
||||||
Draw();
|
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");
|
JButton ButtonRefreshCollection = new JButton("Refresh Collection");
|
||||||
ButtonRefreshCollection.addActionListener(
|
ButtonRefreshCollection.addActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
@ -236,6 +258,8 @@ public class FormTrainCollecltion {
|
|||||||
jListStorage.setBounds(pictureBoxWidth, 210, 160, 80);
|
jListStorage.setBounds(pictureBoxWidth, 210, 160, 80);
|
||||||
buttonRemoveSet.setBounds(pictureBoxWidth, 300, 160, 20);
|
buttonRemoveSet.setBounds(pictureBoxWidth, 300, 160, 20);
|
||||||
|
|
||||||
|
buttonGetRemoved.setBounds(pictureBoxWidth, 330, 160, 20);
|
||||||
|
|
||||||
w.add(canv);
|
w.add(canv);
|
||||||
w.add(ButtonAddTrain);
|
w.add(ButtonAddTrain);
|
||||||
w.add(ButtonRemoveTrain);
|
w.add(ButtonRemoveTrain);
|
||||||
@ -248,6 +272,8 @@ public class FormTrainCollecltion {
|
|||||||
w.add(jListStorage);
|
w.add(jListStorage);
|
||||||
w.add(buttonRemoveSet);
|
w.add(buttonRemoveSet);
|
||||||
|
|
||||||
|
w.add(buttonGetRemoved);
|
||||||
|
|
||||||
w.setVisible(true);
|
w.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,11 @@ public class TrainsGenericStorage {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Словарь (хранилище)
|
/// Словарь (хранилище)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>> _carStorages;
|
HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>> _trainStorages;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращение списка названий наборов
|
/// Возвращение списка названий наборов
|
||||||
/// </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>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -28,7 +28,7 @@ public class TrainsGenericStorage {
|
|||||||
/// <param name="pictureHeight"></param>
|
/// <param name="pictureHeight"></param>
|
||||||
public TrainsGenericStorage(int pictureWidth, int pictureHeight)
|
public TrainsGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_carStorages = new HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>>();
|
_trainStorages = new HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>>();
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
@ -38,9 +38,9 @@ public class TrainsGenericStorage {
|
|||||||
/// <param name="name">Название набора</param>
|
/// <param name="name">Название набора</param>
|
||||||
public void AddSet(String name)
|
public void AddSet(String name)
|
||||||
{
|
{
|
||||||
if (_carStorages.containsKey(name))
|
if (_trainStorages.containsKey(name))
|
||||||
return;
|
return;
|
||||||
_carStorages.put(name, new TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>(_pictureWidth, _pictureHeight));
|
_trainStorages.put(name, new TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>(_pictureWidth, _pictureHeight));
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление набора
|
/// Удаление набора
|
||||||
@ -48,9 +48,9 @@ public class TrainsGenericStorage {
|
|||||||
/// <param name="name">Название набора</param>
|
/// <param name="name">Название набора</param>
|
||||||
public void DelSet(String name)
|
public void DelSet(String name)
|
||||||
{
|
{
|
||||||
if (!_carStorages.containsKey(name))
|
if (!_trainStorages.containsKey(name))
|
||||||
return;
|
return;
|
||||||
_carStorages.remove(name);
|
_trainStorages.remove(name);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Доступ к набору
|
/// Доступ к набору
|
||||||
@ -59,8 +59,14 @@ public class TrainsGenericStorage {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public TrainsGenericCollection<DrawingTrain, DrawningObjectTrain> get(String ind)
|
public TrainsGenericCollection<DrawingTrain, DrawningObjectTrain> get(String ind)
|
||||||
{
|
{
|
||||||
if (_carStorages.containsKey(ind))
|
if (_trainStorages.containsKey(ind))
|
||||||
return _carStorages.get(ind);
|
return _trainStorages.get(ind);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrawningObjectTrain get(String ind1, int ind2){
|
||||||
|
if (!_trainStorages.containsKey(ind1))
|
||||||
|
return null;
|
||||||
|
return _trainStorages.get(ind1).GetU(ind2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user