diff --git a/ProjectElectricLocomotive/FormLocomotiveCollections.java b/ProjectElectricLocomotive/FormLocomotiveCollections.java index 531169d..50afffe 100644 --- a/ProjectElectricLocomotive/FormLocomotiveCollections.java +++ b/ProjectElectricLocomotive/FormLocomotiveCollections.java @@ -75,10 +75,20 @@ public class FormLocomotiveCollections { frameLocomotiveConfig.setVisible(true); frameLocomotiveConfig._formLocomotiveConfig.buttonOk.addActionListener(e2 ->{ frameLocomotiveConfig.dispose(); + loco = frameLocomotiveConfig._formLocomotiveConfig._loco; + if(loco != null){ + if (obj.AddOverload(loco)!= -1) { + JOptionPane.showMessageDialog(getPictureBoxCollections(), "Объект добавлен"); + Refresh(); + } else { + JOptionPane.showMessageDialog(getPictureBoxCollections(), "Не удалось добавить объект"); + } + } + //loco = frameLocomotiveConfig._formLocomotiveConfig. }); - // FrameElectricLocomotive frameElectricLocomotive = new FrameElectricLocomotive(); +//12 FrameElectricLocomotive frameElectricLocomotive = new FrameElectricLocomotive(); // frameElectricLocomotive.setVisible(true); // frameElectricLocomotive._formElectricLocomotive.ButtonSelectLocomotive.addActionListener(e2 -> { // loco = frameElectricLocomotive._formElectricLocomotive._drawingLocomotive; diff --git a/ProjectElectricLocomotive/FormLocomotiveConfig.form b/ProjectElectricLocomotive/FormLocomotiveConfig.form index 55f0860..61f09a6 100644 --- a/ProjectElectricLocomotive/FormLocomotiveConfig.form +++ b/ProjectElectricLocomotive/FormLocomotiveConfig.form @@ -179,7 +179,7 @@ - + @@ -193,7 +193,7 @@ - + @@ -232,6 +232,20 @@ + + + + + + + + + + + + + + diff --git a/ProjectElectricLocomotive/FormLocomotiveConfig.java b/ProjectElectricLocomotive/FormLocomotiveConfig.java index 4297de3..cef832c 100644 --- a/ProjectElectricLocomotive/FormLocomotiveConfig.java +++ b/ProjectElectricLocomotive/FormLocomotiveConfig.java @@ -6,10 +6,11 @@ import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.border.Border; -import java.awt.event.MouseListener; import java.io.IOException; import java.util.Random; @@ -43,42 +44,16 @@ public class FormLocomotiveConfig{ private JPanel panelBodyColor; private JPanel panelAdditionalColor; private JLabel labelWheels; + private JLabel labelCountWheels; + private JSpinner numericUpDownWheels; public Canvas canvas; + FrameLocomotiveConfig frameLocomotiveConfig; public JPanel getPictureBoxObject(){ return MainPanel; } -// MouseListener ml = new MouseListener() { -// @Override -// public void mouseClicked(MouseEvent e) { -// -// } -// -// @Override -// public void mousePressed(MouseEvent e) { -// JComponent jc = (JComponent)e.getSource(); -// TransferHandler th = jc.getTransferHandler(); -// th.exportAsDrag(jc, e, TransferHandler.COPY); -// } -// -// @Override -// public void mouseReleased(MouseEvent e) { -// -// } -// -// @Override -// public void mouseEntered(MouseEvent e) { -// -// } -// -// @Override -// public void mouseExited(MouseEvent e) { -// -// } -// }; - private class Canvas extends JComponent{ public Canvas(){ } @@ -317,50 +292,6 @@ public class FormLocomotiveConfig{ } ); - - - - - /*labelWheels.setBorder(br); - labelWheels.setTransferHandler( - new TransferHandler(){ - @Override - public boolean canImport(TransferHandler.TransferSupport support) { - return support.isDataFlavorSupported(WheelTransferable.wheelDrawingDataFlavor); - } - - @Override - public boolean importData(TransferHandler.TransferSupport support){ - if(canImport(support)) { - try { - Random rnd = new Random(); - IDrawingWheels wheels = (IDrawingWheels) support.getTransferable().getTransferData(WheelTransferable.wheelDrawingDataFlavor); - if (_loco == null) return false; - - int wheelsChoice = rnd.nextInt(0, 3); - - wheels.SetWheelsCount(rnd.nextInt(2, 5)); - - if (wheelsChoice == 0) { - wheels = new DrawingWheel(); - } else if (wheelsChoice == 1) { - wheels = new DrawingEmptyWheels(); - } else { - wheels = new DrawingWheelsBlueCrom(); - } - _loco._drawingWheels = wheels; - pictureBoxObject.repaint(); - return true; - } catch (UnsupportedFlavorException | IOException e) { - e.printStackTrace(); - } - } - return false; - } - } - );*/ - - canvas = new Canvas(); pictureBoxObject.setTransferHandler( new TransferHandler(){ @@ -379,20 +310,19 @@ public class FormLocomotiveConfig{ _loco = new DrawingLocomotive( (int)numericUpDownSpeed.getValue(), (int)numericUpDownWeight.getValue(), - Color.WHITE,/* (int)numericWheelNum.getValue(),*/ /*CanvasWidth,CanvasHeight*/ -// pictureBoxObject.getWidth(), -// pictureBoxObject.getHeight() - 300,300 + Color.WHITE, + pictureBoxObject.getWidth(), + pictureBoxObject.getHeight() ); break; case "Сложный": _loco = new DrawingElectricLocomotive( (int)numericUpDownSpeed.getValue(), (int)numericUpDownWeight.getValue(), - Color.WHITE, /*(int)numericWheelNum.getValue(),*/ + Color.WHITE, Color.BLACK, checkBoxHorns.isSelected(), - checkBoxSeifBatteries.isSelected(), /*checkBoxLocoLine.isSelected(),*/ + checkBoxSeifBatteries.isSelected(), pictureBoxObject.getWidth(), pictureBoxObject.getHeight() ); @@ -406,6 +336,7 @@ public class FormLocomotiveConfig{ rnd = new Random(); IDrawingWheels iDrawingWheels; int wheelsChoice = rnd.nextInt(0, 3); + int wheelsCount = (int)numericUpDownWheels.getValue(); if (wheelsChoice == 0) { iDrawingWheels = new DrawingWheel(); } else if (wheelsChoice == 1) { @@ -413,7 +344,8 @@ public class FormLocomotiveConfig{ } else { iDrawingWheels = new DrawingWheelsBlueCrom(); } - iDrawingWheels.SetWheelsCount(rnd.nextInt(2, 5)); + + iDrawingWheels.SetWheelsCount(wheelsCount); _loco._drawingWheels = iDrawingWheels; } pictureBoxObject.repaint(); @@ -426,16 +358,15 @@ public class FormLocomotiveConfig{ } } ); + buttonClose.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + frameLocomotiveConfig.dispose(); + } + } + ); } - ComponentWheel componentWheelSimple = new ComponentWheel(new DrawingWheel()); - ComponentWheel componentWheelEmpty = new ComponentWheel(new DrawingEmptyWheels()); - ComponentWheel componentWheelBlue = new ComponentWheel(new DrawingWheelsBlueCrom()); - - -// lableSimpleObject.addMouseListener(ml); -// labelModifiedObject.setTransferHandler(new TransferHandler("rar")); - public void Draw() { pictureBoxObject.repaint(); } @@ -443,6 +374,15 @@ public class FormLocomotiveConfig{ private void createUIComponents(){ pictureBoxObject = new Canvas(); pictureBoxObject.setBounds(new Rectangle(300, 300)); + + SpinnerModel numSpeed = new SpinnerNumberModel(100, 100, 1000, 1); + numericUpDownSpeed = new JSpinner(numSpeed); + + SpinnerModel numWeight = new SpinnerNumberModel(100, 100, 1000, 1); + numericUpDownWeight = new JSpinner(numWeight); + + SpinnerModel numWheels = new SpinnerNumberModel(2,2, 4, 1); + numericUpDownWheels = new JSpinner(numWheels); } }