Залил лаб5

This commit is contained in:
ujijrujijr 2023-12-13 11:17:37 +04:00
parent 24c3532ab2
commit 78c744f04e
11 changed files with 593 additions and 7 deletions

View File

@ -79,7 +79,7 @@ public class BusesGenericCollection <T extends DrawingBus, U extends IMoveableOb
DrawingBus bus = _collection.Get(k); DrawingBus bus = _collection.Get(k);
if (bus != null) if (bus != null)
{ {
bus.SetPosition(j * (_placeSizeWidth + 10) + 5, i * (_placeSizeHeight) + 10); bus.SetPosition(j * (_placeSizeWidth + 10) + 5, i * (_placeSizeHeight + 10) + 5);
bus.DrawTransport(g); bus.DrawTransport(g);
} }
j--; j--;

View File

@ -65,6 +65,24 @@ public class DrawingBus {
//Количество дверей //Количество дверей
Doors.SetCntOfDoors(random.nextInt(3, 6)); Doors.SetCntOfDoors(random.nextInt(3, 6));
} }
// Конструктор для формы с настройками автобуса
public DrawingBus(int speed, double weight, Color bodyColor, int width, int height, int cntOfDoors) {
if (width < _busWidth || height < _busHeight) {
return;
}
_startPosX = 10;
_startPosY = 10;
_pictureWidth = width;
_pictureHeight = height;
EntityBus = new EntityBus(speed, weight, bodyColor);
//По умолчанию обычные прямоугольные двери
Doors = new DrawingDoors();
Doors.SetCntOfDoors(cntOfDoors);
}
protected DrawingBus(int speed, double weight, Color bodyColor, int width, int height, int busWidth, int busHeight) { protected DrawingBus(int speed, double weight, Color bodyColor, int width, int height, int busWidth, int busHeight) {
if (width <= _busWidth || height <= _busHeight) { if (width <= _busWidth || height <= _busHeight) {
return; return;
@ -109,6 +127,13 @@ public class DrawingBus {
Doors = doors; Doors = doors;
} }
//Метод для изменения размеров панели для отрисовки, т.к. в FormBusConfig другие размеры
public void ChangePictureSize(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
}
public void SetPosition(int x, int y){ public void SetPosition(int x, int y){
_startPosX = Math.min(Math.max(x, 0), _pictureWidth - _busWidth); _startPosX = Math.min(Math.max(x, 0), _pictureWidth - _busWidth);
_startPosY = Math.min(Math.max(y, 0), _pictureHeight - _busHeight); _startPosY = Math.min(Math.max(y, 0), _pictureHeight - _busHeight);

View File

@ -15,6 +15,15 @@ public class DrawingDoors implements IDrawingDoors{
} }
} }
public int GetCntOfDoors() {
switch (_cntOfDoors) {
case Three: return 3;
case Four: return 4;
case Five: return 5;
default: return 3;
}
}
public void DrawDoors(Graphics2D g, Color BodyColor, int _startPosX, int _startPosY) { public void DrawDoors(Graphics2D g, Color BodyColor, int _startPosX, int _startPosY) {
switch (_cntOfDoors) switch (_cntOfDoors)
{ {

View File

@ -15,6 +15,16 @@ public class DrawingOvalDoors implements IDrawingDoors {
_cntOfDoors = CntOfDoors.Five; _cntOfDoors = CntOfDoors.Five;
} }
} }
public int GetCntOfDoors() {
switch (_cntOfDoors) {
case Three: return 3;
case Four: return 4;
case Five: return 5;
default: return 3;
}
}
public void DrawDoors(Graphics2D g, Color BodyColor, int _startPosX, int _startPosY) { public void DrawDoors(Graphics2D g, Color BodyColor, int _startPosX, int _startPosY) {
switch (_cntOfDoors) switch (_cntOfDoors)
{ {

View File

@ -15,6 +15,16 @@ public class DrawingTriangleDoors implements IDrawingDoors{
_cntOfDoors = CntOfDoors.Five; _cntOfDoors = CntOfDoors.Five;
} }
} }
public int GetCntOfDoors() {
switch (_cntOfDoors) {
case Three: return 3;
case Four: return 4;
case Five: return 5;
default: return 3;
}
}
public void DrawDoors(Graphics2D g, Color BodyColor, int _startPosX, int _startPosY) { public void DrawDoors(Graphics2D g, Color BodyColor, int _startPosX, int _startPosY) {
switch (_cntOfDoors) switch (_cntOfDoors)
{ {

View File

@ -12,6 +12,16 @@ public class DrawingTrolleybus extends DrawingBus{
EntityBus = new EntityTrolleybus(speed, weight, bodyColor, additionalColor, horns, batteries); EntityBus = new EntityTrolleybus(speed, weight, bodyColor, additionalColor, horns, batteries);
} }
} }
// Конструктор для формы с настройками автобуса
public DrawingTrolleybus(int speed, double weight, Color bodyColor, Color additionalColor, boolean horns, boolean batteries, int width, int height, int cntOfDoors)
{
super(speed, weight, bodyColor, width, height, cntOfDoors);
if (EntityBus != null)
{
EntityBus = new EntityTrolleybus(speed, weight, bodyColor, additionalColor, horns, batteries);
}
}
// Прорисовка объекта // Прорисовка объекта
@Override @Override
public void DrawTransport(Graphics g) public void DrawTransport(Graphics g)

View File

@ -20,6 +20,12 @@ public class EntityBus {
public double getStep() { public double getStep() {
return Step; return Step;
} }
// Для лаб 5
public void setBodyColor(Color color) {
BodyColor = color;
}
public EntityBus(int speed, double weight, Color bodyColor) { public EntityBus(int speed, double weight, Color bodyColor) {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;

View File

@ -6,7 +6,7 @@ public class EntityTrolleybus extends EntityBus{
public Color AdditionalColor; public Color AdditionalColor;
// Замена свойства // Замена свойства
public Color getAdditionalColor() {return AdditionalColor;} public Color getAdditionalColor() {return AdditionalColor;}
private void setAdditionalColor(Color additionalColor) {AdditionalColor = additionalColor;} public void setAdditionalColor(Color additionalColor) {AdditionalColor = additionalColor;}
// Признак (опция) наличия "рогов" // Признак (опция) наличия "рогов"
public boolean Horns; public boolean Horns;

View File

@ -0,0 +1,513 @@
package Trolleybus;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import javax.swing.*;
import java.awt.event.*;
import java.io.IOException;
public class FormBusConfig {
JFrame frameBusConfig;
JPanel panelConfig, panelColors, panelObject;
ComponentDrawingConfig drawingConfig; // Замена pictureBox
ComponentDoors rectangleDoors, triangleDoors, ovalDoors; // Компоненты - типы дверей
JPanel panelRed, panelOrange, panelYellow, panelGreen, panelBlue, panelPurple, panelGray, panelBlack;
JLabel labelSimpleObject, labelAdvancedObject, labelMainColor, labelAdditionalColor, labelTypeOfDoors, labelRectDoors, labelTrianDoors, labelOvalDoors;
JLabel labelSpeed, labelWeight, labelDoors;
JSpinner speedSpinner, weightSpinner, doorSpinner;
SpinnerNumberModel speedSpinnerModel, weightSpinnerModel, doorSpinnerModel;
JCheckBox checkBoxHorns, checkBoxBatteries;
JButton buttonAdd, buttonCancel;
public FormBusConfig() {
InitializeComponent();
}
private void InitializeComponent() {
//Само окно
frameBusConfig = new JFrame("Настройки автобуса");
frameBusConfig.setLayout(null);
frameBusConfig.setSize(1000, 450);
frameBusConfig.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// Панель создания автобуса
panelConfig = new JPanel();
panelConfig.setBounds(10, 20, 570, 360);
panelConfig.setBorder(BorderFactory.createLineBorder(Color.BLACK));
panelConfig.setLayout(null);
// Настройка скорости и веса
speedSpinnerModel = new SpinnerNumberModel(100, 100, 1000, 1);
weightSpinnerModel = new SpinnerNumberModel(100, 100, 1000, 1);
speedSpinner = new JSpinner(speedSpinnerModel);
speedSpinner.setBounds(100, 30, 150, 30);
weightSpinner = new JSpinner(weightSpinnerModel);
weightSpinner.setBounds(100, 70, 150, 30);
labelSpeed = new JLabel("Скорость:");
labelSpeed.setBounds(5, 30, 95, 20);
labelWeight = new JLabel("Вес:");
labelWeight.setBounds(5, 70, 95, 20);
// Настройка кол-ва дверей
doorSpinnerModel = new SpinnerNumberModel(3, 3, 5, 1);
doorSpinner = new JSpinner(doorSpinnerModel);
doorSpinner.setBounds(100, 110, 150, 30);
labelDoors = new JLabel("Кол-во дверей:");
labelDoors.setBounds(5, 110, 95, 20);
// Настройка доп. свойств для троллейбуса
checkBoxHorns = new JCheckBox("Наличие \"рогов\"");
checkBoxHorns.setBounds(5, 140, 200, 30);
checkBoxBatteries = new JCheckBox("Наличие отсека для батарей");
checkBoxBatteries.setBounds(5, 170, 200, 30);
// Панель с цветами
panelColors = new JPanel();
panelColors.setBounds(280, 30, 270, 150);
panelColors.setBorder(BorderFactory.createLineBorder(Color.BLACK));
panelColors.setLayout(null);
panelRed = new JPanel();
panelRed.setBackground(Color.RED);
panelRed.setBounds(5, 25, 50, 40);
panelRed.setTransferHandler(new PanelTransferHandler());
panelRed.addMouseListener(new PanelMouseAdapter());
panelOrange = new JPanel();
panelOrange.setBackground(Color.ORANGE);
panelOrange.setBounds(75, 25, 50, 40);
panelOrange.setTransferHandler(new PanelTransferHandler());
panelOrange.addMouseListener(new PanelMouseAdapter());
panelYellow = new JPanel();
panelYellow.setBackground(Color.YELLOW);
panelYellow.setBounds(145, 25, 50, 40);
panelYellow.setTransferHandler(new PanelTransferHandler());
panelYellow.addMouseListener(new PanelMouseAdapter());
panelGreen = new JPanel();
panelGreen.setBackground(Color.GREEN);
panelGreen.setBounds(215, 25, 50, 40);
panelGreen.setTransferHandler(new PanelTransferHandler());
panelGreen.addMouseListener(new PanelMouseAdapter());
panelBlue = new JPanel();
panelBlue.setBackground(Color.BLUE);
panelBlue.setBounds(5, 85, 50, 40);
panelBlue.setTransferHandler(new PanelTransferHandler());
panelBlue.addMouseListener(new PanelMouseAdapter());
panelPurple = new JPanel();
panelPurple.setBackground(Color.MAGENTA);
panelPurple.setBounds(75, 85, 50, 40);
panelPurple.setTransferHandler(new PanelTransferHandler());
panelPurple.addMouseListener(new PanelMouseAdapter());
panelGray = new JPanel();
panelGray.setBackground(Color.GRAY);
panelGray.setBounds(145, 85, 50, 40);
panelGray.setTransferHandler(new PanelTransferHandler());
panelGray.addMouseListener(new PanelMouseAdapter());
panelBlack = new JPanel();
panelBlack.setBackground(Color.BLACK);
panelBlack.setBounds(215, 85, 50, 40);
panelBlack.setTransferHandler(new PanelTransferHandler());
panelBlack.addMouseListener(new PanelMouseAdapter());
panelColors.add(panelRed);
panelColors.add(panelOrange);
panelColors.add(panelYellow);
panelColors.add(panelGreen);
panelColors.add(panelBlue);
panelColors.add(panelPurple);
panelColors.add(panelGray);
panelColors.add(panelBlack);
// Надписи с Drag&Drop на панели с параметрами
labelSimpleObject = new JLabel("Простой");
labelSimpleObject.setBounds(280, 190, 120, 30);
labelSimpleObject.setBorder(BorderFactory.createLineBorder(Color.BLACK));
labelSimpleObject.setHorizontalAlignment(SwingConstants.CENTER);
labelSimpleObject.setTransferHandler(new LabelTransferHandler());
labelSimpleObject.addMouseListener(new LabelMouseAdapter());
labelAdvancedObject = new JLabel("Продвинутый");
labelAdvancedObject.setBounds(430, 190, 120, 30);
labelAdvancedObject.setBorder(BorderFactory.createLineBorder(Color.BLACK));
labelAdvancedObject.setHorizontalAlignment(SwingConstants.CENTER);
labelAdvancedObject.setTransferHandler(new LabelTransferHandler());
labelAdvancedObject.addMouseListener(new LabelMouseAdapter());
// Компоненты - типы дверей
// Прямоугольные двери
rectangleDoors = new ComponentDoors(new DrawingDoors());
rectangleDoors.setBounds(330, 240, 170, 30);
rectangleDoors.setLayout(new GridLayout(1,1));
rectangleDoors.setBorder(BorderFactory.createLineBorder(Color.BLACK));
// Надпись для компонента прямоугольных дверей
labelRectDoors = new JLabel("Прямоугольные двери");
labelRectDoors.setHorizontalAlignment(SwingConstants.CENTER);
rectangleDoors.add(labelRectDoors);
// Треугольные двери
triangleDoors = new ComponentDoors(new DrawingTriangleDoors());
triangleDoors.setBounds(330, 280, 170, 30);
triangleDoors.setLayout(new GridLayout(1,1));
triangleDoors.setBorder(BorderFactory.createLineBorder(Color.BLACK));
// Надпись для компонента треугольных дверей
labelTrianDoors = new JLabel("Треугольные двери");
labelTrianDoors.setHorizontalAlignment(SwingConstants.CENTER);
triangleDoors.add(labelTrianDoors);
// Овальные двери
ovalDoors = new ComponentDoors(new DrawingOvalDoors());
ovalDoors.setBounds(330, 320, 170, 30);
ovalDoors.setLayout(new GridLayout(1,1));
ovalDoors.setBorder(BorderFactory.createLineBorder(Color.BLACK));
// Надпись для компонента овальных дверей
labelOvalDoors = new JLabel("Овальные двери");
labelOvalDoors.setHorizontalAlignment(SwingConstants.CENTER);
ovalDoors.add(labelOvalDoors);
panelConfig.add(panelColors);
panelConfig.add(speedSpinner);
panelConfig.add(labelSpeed);
panelConfig.add(weightSpinner);
panelConfig.add(labelWeight);
panelConfig.add(doorSpinner);
panelConfig.add(labelDoors);
panelConfig.add(checkBoxBatteries);
panelConfig.add(checkBoxHorns);
panelConfig.add(labelSimpleObject);
panelConfig.add(labelAdvancedObject);
panelConfig.add(rectangleDoors);
panelConfig.add(triangleDoors);
panelConfig.add(ovalDoors);
panelObject = new JPanel();
panelObject.setBounds(600, 20, 370, 360);
panelObject.setLayout(null);
// Надписи с Drag&Drop на панели отображения автобуса
labelMainColor = new JLabel("Основной цвет");
labelMainColor.setBounds(10, 10, 110, 60);
labelMainColor.setBorder(BorderFactory.createLineBorder(Color.BLACK));
labelMainColor.setHorizontalAlignment(SwingConstants.CENTER);
labelMainColor.setTransferHandler(new TransferHandler() {
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
}
@Override
public boolean importData(TransferSupport support) {
if (canImport(support))
{
try
{
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
if (drawingConfig._bus == null) {
return false;
}
drawingConfig._bus.getEntityBus().setBodyColor(color);
drawingConfig.repaint();
return true;
}
catch (UnsupportedFlavorException | IOException e)
{
e.printStackTrace();
}
}
return false;
}
});
labelAdditionalColor = new JLabel("Доп. цвет");
labelAdditionalColor.setBounds(130, 10, 110, 60);
labelAdditionalColor.setBorder(BorderFactory.createLineBorder(Color.BLACK));
labelAdditionalColor.setHorizontalAlignment(SwingConstants.CENTER);
labelAdditionalColor.setTransferHandler(new TransferHandler() {
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (canImport(support)) {
try {
Color color = (Color)support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
if (drawingConfig._bus == null) {
return false;
}
if (!(drawingConfig._bus instanceof DrawingTrolleybus)) {
return false;
}
EntityTrolleybus _trolleybus = (EntityTrolleybus)drawingConfig._bus.getEntityBus();
_trolleybus.setAdditionalColor(color);
drawingConfig.repaint();
return true;
}
catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
}
return false;
}
});
labelTypeOfDoors = new JLabel("Форма дверей");
labelTypeOfDoors.setBounds(250, 10, 110, 60);
labelTypeOfDoors.setBorder(BorderFactory.createLineBorder(Color.BLACK));
labelTypeOfDoors.setHorizontalAlignment(SwingConstants.CENTER);
labelTypeOfDoors.setTransferHandler(new TransferHandler() {
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
return support.isDataFlavorSupported(DoorsTransferable.drawingDoorsDataFlavor);
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (canImport(support)) {
try {
IDrawingDoors drawingDoors = (IDrawingDoors)support.getTransferable().getTransferData(DoorsTransferable.drawingDoorsDataFlavor);
if (drawingConfig._bus == null) {
return false;
}
int cntOfDoors = drawingConfig._bus.Doors.GetCntOfDoors();
drawingDoors.SetCntOfDoors(cntOfDoors);
drawingConfig._bus.Doors = drawingDoors;
drawingConfig.repaint();
return true;
}
catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
}
return false;
}
});
drawingConfig = new ComponentDrawingConfig();
drawingConfig.setBounds(10, 80, 350, 200);
drawingConfig.setBorder(BorderFactory.createLineBorder(Color.BLACK));
drawingConfig.setLayout(null);
drawingConfig.setTransferHandler(new TransferHandler() {
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
return support.isDataFlavorSupported(DataFlavor.stringFlavor);
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (canImport(support)) {
try {
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
if ("Простой".equals(data)) {
drawingConfig._bus = new DrawingBus((int)speedSpinner.getValue(), (int)weightSpinner.getValue(), Color.WHITE, drawingConfig.getWidth(), drawingConfig.getHeight(), (int)doorSpinner.getValue());
}
else if ("Продвинутый".equals(data)) {
drawingConfig._bus = new DrawingTrolleybus((int)speedSpinner.getValue(), (int)weightSpinner.getValue(), Color.WHITE, Color.BLACK, checkBoxHorns.isSelected(), checkBoxBatteries.isSelected(), drawingConfig.getWidth(), drawingConfig.getHeight(), (int)doorSpinner.getValue());
}
drawingConfig.repaint();
return true;
}
catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
}
return false;
}
});
buttonAdd = new JButton("Добавить");
buttonAdd.setBounds(10, 300, 100, 30);
buttonCancel = new JButton("Отмена");
buttonCancel.setBounds(260, 300, 100, 30);
buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frameBusConfig.dispose();
}
});
panelObject.add(labelMainColor);
panelObject.add(labelAdditionalColor);
panelObject.add(labelTypeOfDoors);
panelObject.add(drawingConfig);
panelObject.add(buttonAdd);
panelObject.add(buttonCancel);
frameBusConfig.add(panelConfig);
frameBusConfig.add(panelObject);
frameBusConfig.setVisible(true);
}
}
class LabelTransferHandler extends TransferHandler {
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
protected Transferable createTransferable(JComponent c) {
return new StringSelection(((JLabel) c).getText());
}
}
class ColorTransferable implements Transferable {
private Color color;
static final DataFlavor colorDataFlavor = new DataFlavor(Color.class, "Color");
public ColorTransferable(Color color) {
this.color = color;
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] {colorDataFlavor};
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return colorDataFlavor.equals(flavor);
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (isDataFlavorSupported(flavor)) {
return color;
}
else {
throw new UnsupportedFlavorException(flavor);
}
}
}
class PanelTransferHandler extends TransferHandler {
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
protected Transferable createTransferable(JComponent c) {
return new ColorTransferable(((JPanel)c).getBackground());
}
}
class LabelMouseAdapter extends MouseAdapter {
@Override
public void mousePressed(MouseEvent e) {
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
}
}
class PanelMouseAdapter extends MouseAdapter{
@Override
public void mousePressed(MouseEvent e) {
((JPanel)e.getComponent()).getTransferHandler().exportAsDrag(((JPanel)e.getComponent()), e, TransferHandler.COPY);
}
}
class DoorsTransferable implements Transferable {
private IDrawingDoors drawingDoors;
static final DataFlavor drawingDoorsDataFlavor = new DataFlavor(IDrawingDoors.class, "IDrawingDoors");
public DoorsTransferable(IDrawingDoors drawingDoors) {
this.drawingDoors = drawingDoors;
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[]{drawingDoorsDataFlavor};
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(drawingDoorsDataFlavor);
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (isDataFlavorSupported(flavor)) {
return drawingDoors;
}
else {
throw new UnsupportedFlavorException(flavor);
}
}
}
class ComponentDoors extends JComponent{
public IDrawingDoors drawingDoors;
public ComponentDoors(IDrawingDoors drawingDoors){
this.drawingDoors = drawingDoors;
this.addMouseListener(
new MouseAdapter(){
@Override
public void mousePressed(MouseEvent e) {
((ComponentDoors)e.getComponent()).getTransferHandler().exportAsDrag(((ComponentDoors)e.getComponent()), e, TransferHandler.COPY);
}
}
);
this.setTransferHandler(
new TransferHandler() {
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
protected Transferable createTransferable(JComponent c) {
return new DoorsTransferable(((ComponentDoors)c).drawingDoors);
}
}
);
}
}
// Замена pictureBox
class ComponentDrawingConfig extends JComponent {
public DrawingBus _bus; // Выбранный автобус
public ComponentDrawingConfig() {
_bus = null;
}
@Override
public void paintComponent(Graphics g)
{
if (_bus == null) {
return;
}
super.paintComponent(g);
_bus.DrawTransport(g);
super.repaint();
}
}

View File

@ -148,7 +148,7 @@ public class FormBusesCollection {
} }
private void buttonAddBus_Click(ActionEvent e) { private void buttonAddBus_Click(ActionEvent e) {
FormTrolleybus form = new FormTrolleybus(); FormBusConfig form = new FormBusConfig();
if (listBoxSets.getSelectedIndex() == -1) if (listBoxSets.getSelectedIndex() == -1)
{ {
return; return;
@ -160,10 +160,12 @@ public class FormBusesCollection {
} }
//Листенер для кнопки выбора автобуса на той форме //Листенер для кнопки выбора автобуса на той форме
form.buttonSelect.addActionListener(new ActionListener() { form.buttonAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
DrawingBus SelectedBus = form.getBus(); DrawingBus SelectedBus = form.drawingConfig._bus;
if (obj.Add(SelectedBus) != -1) //Возвращение объекту размеров pictureBox с этой формы (до этого создался с размерами pictureBox с FormBusConfig)
SelectedBus.ChangePictureSize(panelBusesCollection.getWidth(), panelBusesCollection.getHeight());
if (SelectedBus != null && obj.Add(SelectedBus) != -1)
{ {
JOptionPane.showMessageDialog(null, "Объект добавлен"); JOptionPane.showMessageDialog(null, "Объект добавлен");
obj.ShowBuses(panelBusesCollection); obj.ShowBuses(panelBusesCollection);
@ -172,7 +174,7 @@ public class FormBusesCollection {
{ {
JOptionPane.showMessageDialog(null, "Не удалось добавить объект"); JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
} }
form.getFrame().dispose(); form.frameBusConfig.dispose();
} }
}); });
} }

View File

@ -5,4 +5,5 @@ import java.awt.*;
public interface IDrawingDoors { public interface IDrawingDoors {
public void SetCntOfDoors(int cnt); public void SetCntOfDoors(int cnt);
public void DrawDoors(Graphics2D g, Color BodyColor, int _startPosX, int _startPosY); public void DrawDoors(Graphics2D g, Color BodyColor, int _startPosX, int _startPosY);
public int GetCntOfDoors();
} }