almost ready lab 5 without buttonClose

This commit is contained in:
ekallin 2023-12-04 13:28:12 +04:00
parent 89c0ed3e48
commit 11104b9690
3 changed files with 56 additions and 92 deletions

View File

@ -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;

View File

@ -179,7 +179,7 @@
<text value="Скорость"/>
</properties>
</component>
<component id="6d54a" class="javax.swing.JSpinner" binding="numericUpDownSpeed">
<component id="6d54a" class="javax.swing.JSpinner" binding="numericUpDownSpeed" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@ -193,7 +193,7 @@
<text value="Вес"/>
</properties>
</component>
<component id="73fe9" class="javax.swing.JSpinner" binding="numericUpDownWeight">
<component id="73fe9" class="javax.swing.JSpinner" binding="numericUpDownWeight" custom-create="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@ -232,6 +232,20 @@
<text value="Колеса добавить?..."/>
</properties>
</component>
<component id="f2170" class="javax.swing.JLabel" binding="labelCountWheels">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Количество колес"/>
</properties>
</component>
<component id="f9057" class="javax.swing.JSpinner" binding="numericUpDownWheels" custom-create="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<component id="8989b" class="javax.swing.JButton" binding="buttonOk">

View File

@ -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);
}
}