2023-10-21 19:25:05 +04:00
|
|
|
|
package ProjectElectricLocomotive;
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
2023-11-06 20:57:19 +04:00
|
|
|
|
//готовая лаба 3
|
|
|
|
|
|
2023-10-21 22:32:22 +04:00
|
|
|
|
public class FormLocomotiveCollections {
|
2023-11-06 20:57:19 +04:00
|
|
|
|
FrameDopClassParameters frameDopClassParameters;
|
2023-10-21 19:25:05 +04:00
|
|
|
|
private JPanel MainPanel;
|
|
|
|
|
private JPanel pictureBoxCollections;
|
|
|
|
|
private JPanel Instruments;
|
|
|
|
|
private JButton ButtonAddLocomotive;
|
2023-10-21 22:32:22 +04:00
|
|
|
|
private JTextField textFieldNumber;
|
2023-10-21 19:25:05 +04:00
|
|
|
|
private JButton ButtonRefreshCollection;
|
|
|
|
|
private JButton ButtonRemoveLocomotive;
|
2023-11-06 20:57:19 +04:00
|
|
|
|
private JButton ButtonCreateRandomLoco;
|
2023-11-07 00:52:46 +04:00
|
|
|
|
private JTextField textBoxStorageName;
|
|
|
|
|
private JButton ButtonAddObject;
|
|
|
|
|
private JList listBoxStorage;
|
|
|
|
|
private JButton ButtomRemoveObject;
|
2023-10-21 19:25:05 +04:00
|
|
|
|
public DrawingLocomotive loco;
|
2023-11-06 20:57:19 +04:00
|
|
|
|
LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
|
2023-10-21 22:32:22 +04:00
|
|
|
|
|
2023-10-21 19:25:05 +04:00
|
|
|
|
public JPanel getPictureBoxCollections() {
|
|
|
|
|
return MainPanel;
|
|
|
|
|
}
|
2023-10-21 22:32:22 +04:00
|
|
|
|
|
|
|
|
|
public FormLocomotiveCollections() {
|
|
|
|
|
_locomotives = new LocomotiveGenericCollection<>(400, 300);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ButtonAddLocomotive.addActionListener(e -> {
|
|
|
|
|
FrameElectricLocomotive frameElectricLocomotive = new FrameElectricLocomotive();
|
|
|
|
|
frameElectricLocomotive.setVisible(true);
|
|
|
|
|
frameElectricLocomotive._formLocomotiveCollection.ButtonSelectLocomotive.addActionListener(e2 -> {
|
|
|
|
|
loco = frameElectricLocomotive._formLocomotiveCollection._drawingLocomotive;
|
|
|
|
|
frameElectricLocomotive.dispose();
|
|
|
|
|
if (loco != null) {
|
|
|
|
|
//проверяем, удалось ли нам загрузить объект
|
|
|
|
|
if (_locomotives.AddOverload(loco) != -1) {
|
|
|
|
|
JOptionPane.showMessageDialog(getPictureBoxCollections(), "Объект добавлен");
|
|
|
|
|
Refresh();
|
|
|
|
|
} else {
|
|
|
|
|
JOptionPane.showMessageDialog(getPictureBoxCollections(), "Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-06 20:57:19 +04:00
|
|
|
|
ButtonCreateRandomLoco.addActionListener(e->{
|
|
|
|
|
if(frameDopClassParameters!=null) frameDopClassParameters.dispose();
|
|
|
|
|
frameDopClassParameters = new FrameDopClassParameters();
|
|
|
|
|
frameDopClassParameters.setVisible(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ButtonRemoveLocomotive.addActionListener(e -> {
|
2023-10-21 22:32:22 +04:00
|
|
|
|
try {
|
|
|
|
|
int pos = Integer.parseInt(textFieldNumber.getText());
|
|
|
|
|
if (_locomotives.SubOverload(pos) != null) {
|
2023-10-21 19:25:05 +04:00
|
|
|
|
Refresh();
|
2023-10-21 22:32:22 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
|
|
|
|
"Объект удален",
|
|
|
|
|
"Успех",
|
|
|
|
|
JOptionPane.INFORMATION_MESSAGE);
|
2023-10-21 19:25:05 +04:00
|
|
|
|
} else {
|
2023-10-21 22:32:22 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
|
|
|
|
"Не удалось удалить объект",
|
|
|
|
|
"Ошибка",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
2023-10-21 19:25:05 +04:00
|
|
|
|
}
|
2023-10-21 22:32:22 +04:00
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
|
|
|
|
"Неверное значение",
|
|
|
|
|
"Ошибка",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
2023-10-21 19:25:05 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-06 20:57:19 +04:00
|
|
|
|
ButtonRefreshCollection.addActionListener(e -> {
|
2023-10-21 22:32:22 +04:00
|
|
|
|
Refresh();
|
|
|
|
|
});
|
2023-11-06 20:57:19 +04:00
|
|
|
|
|
2023-10-21 22:32:22 +04:00
|
|
|
|
}
|
|
|
|
|
public void Refresh() {
|
2023-10-21 19:25:05 +04:00
|
|
|
|
Graphics g = pictureBoxCollections.getGraphics();
|
|
|
|
|
pictureBoxCollections.paint(g);
|
|
|
|
|
_locomotives.ShowLocomotives(g);
|
|
|
|
|
}
|
|
|
|
|
}
|