package ProjectElectricLocomotive; import javax.swing.*; import java.awt.*; public class FormLocomotiveCollections extends JFrame { private JPanel MainPanel; private JPanel pictureBoxCollections; private JPanel Instruments; private JButton ButtonAddLocomotive; private JTextField textField1; private JButton ButtonRefreshCollection; private JButton ButtonRemoveLocomotive; public DrawingLocomotive loco; FormElectricLocomotive _formElectricLocomotive; private final LocomotiveGenericCollection _locomotives; public JPanel getPictureBoxCollections() { return MainPanel; } public FormLocomotiveCollections() { _locomotives = new LocomotiveGenericCollection<>(pictureBoxCollections.getWidth(), pictureBoxCollections.getHeight()); ButtonAddLocomotive.addActionListener(e->{ FormElectricLocomotive form = new FormElectricLocomotive(); VisFormElectricLocomotive(); if (_locomotives == null) return; loco = form._drawingLocomotive; if(loco != null) { //проверяем, удалось ли нам загрузить объект if (_locomotives.AddOverload(loco) != -1 && form.IsSelect == true) { JOptionPane.showMessageDialog(getPictureBoxCollections(), "Объект добавлен"); Refresh(); //pictureBoxCollections = _locomotives.ShowLocomotives(); } else { JOptionPane.showMessageDialog(getPictureBoxCollections(), "Не удалось добавить объект"); } } }); } public void VisFormElectricLocomotive(){ setTitle("ElectroLoco"); _formElectricLocomotive = new FormElectricLocomotive(); setContentPane(_formElectricLocomotive.getPictureBox()); setDefaultLookAndFeelDecorated(false); setLocation(200, 500); pack(); setVisible(true); } public void Refresh(){ Graphics g = pictureBoxCollections.getGraphics(); pictureBoxCollections.paint(g); _locomotives.ShowLocomotives(g); } }