2023-11-06 17:02:05 +04:00

77 lines
3.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ProjectElectricLocomotive;
import javax.swing.*;
import java.awt.*;
public class FormLocomotiveCollections {
private JPanel MainPanel;
private JPanel pictureBoxCollections;
private JPanel Instruments;
private JButton ButtonAddLocomotive;
private JTextField textFieldNumber;
private JButton ButtonRefreshCollection;
private JButton ButtonRemoveLocomotive;
public DrawingLocomotive loco;
FormElectricLocomotive _formElectricLocomotive;
private final LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
public JPanel getPictureBoxCollections() {
return MainPanel;
}
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(), "Не удалось добавить объект");
}
}
});
});
ButtonRemoveLocomotive.addActionListener(e->{
try {
int pos = Integer.parseInt(textFieldNumber.getText());
if (_locomotives.SubOverload(pos) != null) {
Refresh();
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
"Объект удален",
"Успех",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
"Не удалось удалить объект",
"Ошибка",
JOptionPane.ERROR_MESSAGE);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
"Неверное значение",
"Ошибка",
JOptionPane.ERROR_MESSAGE);
}
});
ButtonRefreshCollection.addActionListener(e->{
Refresh();
});
}
public void Refresh() {
Graphics g = pictureBoxCollections.getGraphics();
pictureBoxCollections.paint(g);
_locomotives.ShowLocomotives(g);
}
}