LabWork05_fix

This commit is contained in:
Кашин Максим 2022-12-02 00:27:40 +04:00
parent a432fd6516
commit 8c08a8b884
10 changed files with 517 additions and 19 deletions

16
src/Action.java Normal file
View File

@ -0,0 +1,16 @@
import java.util.ArrayList;
import java.util.function.Consumer;
public class Action<T> {
private final ArrayList<Consumer<T>> listeners = new ArrayList<>();
public void addListener(Consumer<T> listener) {
listeners.add(listener);
}
public void emit(T gasolineTanker) {
for (var listener : listeners) {
listener.accept(gasolineTanker);
}
}
}

View File

@ -25,11 +25,24 @@ public class DrawingGasolineTanker {
GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor);
Wheels= wheelsForm;
}
public DrawingGasolineTanker(int speed, float weight,int countwheel, Color bodyColor)
{
GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor);
Wheels= GetFormOfWheels((int)(2 + Math.random() + Math.random()*2));
Wheels.SetCountWheels(countwheel);
}
public DrawingGasolineTanker(EntityGasolineTanker gasolineTanker,IDrawningObjectWheels wheels)
{
GasolineTanker = gasolineTanker;
Wheels = wheels;
}
public void SetWheels(IDrawningObjectWheels wheels){
Wheels = wheels;
}
public void SetBodyColor(Color color){
GasolineTanker= new EntityGasolineTanker(GasolineTanker.getSpeed(), GasolineTanker.getWeight(), color);
}
public IDrawningObjectWheels GetFormOfWheels(int FormOfWheel){
OrnamentForm temp = null;

View File

@ -8,6 +8,11 @@ public class DrawingImprovedGasolineTanker extends DrawingGasolineTanker {
Wheels= GetFormOfWheels(wheelForm);
Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2));
}
public DrawingImprovedGasolineTanker(int speed, float weight,int countwheels, Color bodyColor, Color dopColor, boolean bodyKit,boolean antena) {
super(speed, weight, bodyColor, 120, 50);
GasolineTanker=new EntityImprovedGasolineTanker(speed,weight,bodyColor,dopColor,bodyKit,antena);
Wheels.SetCountWheels(countwheels);
}
public DrawingImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean antena,IDrawningObjectWheels wheelForm) {
super(speed, weight, bodyColor, 160, 70);
GasolineTanker=new EntityImprovedGasolineTanker(speed,weight,bodyColor,dopColor,bodyKit,antena);
@ -17,8 +22,15 @@ public class DrawingImprovedGasolineTanker extends DrawingGasolineTanker {
super(gasolineTanker,wheels);
GasolineTanker=gasolineTanker;
}
@Override
public void SetBodyColor(Color color){
var gasolineTanker=(EntityImprovedGasolineTanker) GasolineTanker;
GasolineTanker=new EntityImprovedGasolineTanker(gasolineTanker.getSpeed(),gasolineTanker.getWeight(),color,gasolineTanker.GetDopColor(), gasolineTanker.GetBodyKit(), gasolineTanker.GetAntena());
}
public void SetDopColor(Color color){
var gasolineTanker=(EntityImprovedGasolineTanker) GasolineTanker;
GasolineTanker=new EntityImprovedGasolineTanker(gasolineTanker.getSpeed(),gasolineTanker.getWeight(),gasolineTanker.getBodyColor(),color, gasolineTanker.GetBodyKit(), gasolineTanker.GetAntena());
}
@Override
public void DrawTransport(Graphics g) {

View File

@ -6,6 +6,9 @@ public class DrawingOrnamentWheelsFirst implements IDrawningObjectWheels{
public DrawingOrnamentWheelsFirst(CountWheels wheels){
_wheels=wheels;
}
public DrawingOrnamentWheelsFirst(int count) {
SetCountWheels(count);
}
@Override
public void SetCountWheels(int count) {
for (CountWheels temp: CountWheels.values())

View File

@ -6,6 +6,9 @@ public class DrawingOrnamentWheelsSecond implements IDrawningObjectWheels{
public DrawingOrnamentWheelsSecond(CountWheels wheels){
_wheels=wheels;
}
public DrawingOrnamentWheelsSecond(int count) {
SetCountWheels(count);
}
@Override
public void SetCountWheels(int count) {
for (CountWheels temp: CountWheels.values())

View File

@ -7,6 +7,9 @@ public class DrawingWheels implements IDrawningObjectWheels{
public DrawingWheels(CountWheels wheels) {
_wheels=wheels;
}
public DrawingWheels(int count) {
SetCountWheels(count);
}
public void SetCountWheels(int Count){
for (CountWheels temp: CountWheels.values())

View File

@ -42,9 +42,9 @@ public class FormGasolineTanker extends JFrame{
private void SetData() {
Random rand=new Random();
_gasolineTanker.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
SpeedLabel.setText("Speed: "+_gasolineTanker.getGasolineTanker().getSpeed());
WeightLabel.setText("Weight: "+_gasolineTanker.getGasolineTanker().getWeight());
BodyColorLabel.setText("Color: "+Integer.toHexString(_gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2));
SpeedLabel.setText("Скорость: "+_gasolineTanker.getGasolineTanker().getSpeed());
WeightLabel.setText("Вес: "+_gasolineTanker.getGasolineTanker().getWeight());
BodyColorLabel.setText("Цвет: "+Integer.toHexString(_gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2));
}
@Override

View File

@ -0,0 +1,296 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormGasolineTankerConfig">
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="683" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="db96d" binding="PreviewPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="bevel-lowered" title="Preview panel"/>
<children>
<component id="98c7d" class="javax.swing.JButton" binding="ButtonAdd">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Add"/>
</properties>
</component>
<component id="af43b" class="javax.swing.JButton" binding="ButtonCancel">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Cancel"/>
</properties>
</component>
<grid id="f7965" binding="PictureBox" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="bevel-lowered" title="GasolineTanker">
<title-color color="-4473925"/>
</border>
<children/>
</grid>
<component id="e10c4" class="javax.swing.JLabel" binding="BodyColorLabel">
<constraints>
<grid row="0" 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="Body color label"/>
</properties>
</component>
<component id="fee47" class="javax.swing.JLabel" binding="DopColorLabel">
<constraints>
<grid row="0" column="1" 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="Dop color label"/>
</properties>
</component>
</children>
</grid>
<grid id="cfb8f" binding="GroupBoxConfig" layout-manager="GridLayoutManager" row-count="6" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="bevel-lowered" title="Setting"/>
<children>
<grid id="1aae6" binding="ColorPanel" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="3" row-span="5" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="bevel-lowered" title="Color"/>
<children>
<grid id="494da" binding="RedPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-65536"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="cd417" binding="OrangePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-35072"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="f8d12" binding="YellowPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-256"/>
<enabled value="false"/>
<foreground color="-256"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="6a27a" binding="PinkPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-65336"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="d6e6e" binding="GreenPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-16711936"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="2a24b" binding="BluePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-16776991"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="42ead" binding="CianPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-16711681"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="7bdaf" binding="GrayPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-8355712"/>
</properties>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<component id="543d0" class="javax.swing.JLabel" binding="BaseGasolineTankerLabel">
<constraints>
<grid row="5" column="3" 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="Base GT"/>
</properties>
</component>
<component id="f0188" class="javax.swing.JLabel" binding="ImprovedGasolineTankerLabel">
<constraints>
<grid row="5" column="4" 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="Improved GT"/>
</properties>
</component>
<component id="66d4f" class="javax.swing.JLabel" binding="SpeedLabel">
<constraints>
<grid row="0" 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="Speed:"/>
</properties>
</component>
<component id="99004" class="javax.swing.JLabel" binding="WeightLabel">
<constraints>
<grid row="1" 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="Weight:"/>
</properties>
</component>
<component id="2ceae" class="javax.swing.JSpinner" binding="SpinnerSpeed">
<constraints>
<grid row="0" column="2" 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>
<component id="a01ac" class="javax.swing.JCheckBox" binding="CheckBoxAntenna">
<constraints>
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Bulb"/>
</properties>
</component>
<component id="93301" class="javax.swing.JCheckBox" binding="checkBoxBodyKit">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Barrel"/>
</properties>
</component>
<component id="bda53" class="javax.swing.JSpinner" binding="SpinnerWeight">
<constraints>
<grid row="1" column="2" 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>
<grid id="e549b" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="bevel-lowered" title="Wheels"/>
<children>
<component id="db027" class="javax.swing.JLabel" binding="CountWheelsLabel">
<constraints>
<grid row="0" 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="Count wheels"/>
</properties>
</component>
<component id="96436" class="javax.swing.JSpinner" binding="SpinnerWheels">
<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>
<properties/>
</component>
<grid id="2dbf5" binding="TypeWheels" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="bevel-lowered" title="Type wheels"/>
<children>
<component id="3e6d9" class="javax.swing.JLabel" binding="WheelsLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="68" height="16"/>
</grid>
</constraints>
<properties>
<text value="Not ornament"/>
</properties>
</component>
<component id="32f00" class="javax.swing.JLabel" binding="WheelsFirstLabel">
<constraints>
<grid row="0" column="1" 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="First ornament"/>
</properties>
</component>
<component id="75188" class="javax.swing.JLabel" binding="WheelsSecondLabel">
<constraints>
<grid row="0" column="2" 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="Second ornament"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -0,0 +1,153 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.util.function.Consumer;
public class FormGasolineTankerConfig extends JFrame{
private final Action<DrawingGasolineTanker> event = new Action<>();
private DrawingGasolineTanker gasolineTanker;
CountWheels wheels;
private IDrawningObjectWheels _wheel=null;
private JPanel MainPanel;
private JPanel PreviewPanel;
private JButton ButtonAdd;
private JButton ButtonCancel;
private JLabel BodyColorLabel;
private JLabel DopColorLabel;
private JPanel PictureBox;
private JPanel GroupBoxConfig;
private JSpinner SpinnerWheels;
private JLabel CountWheelsLabel;
private JPanel TypeWheels;
private JLabel WheelsLabel;
private JLabel WheelsFirstLabel;
private JLabel WheelsSecondLabel;
private JPanel ColorPanel;
private JSpinner SpinnerSpeed;
private JCheckBox CheckBoxAntenna;
private JCheckBox checkBoxBodyKit;
private JSpinner SpinnerWeight;
private JPanel RedPanel;
private JPanel OrangePanel;
private JPanel YellowPanel;
private JPanel CianPanel;
private JPanel PinkPanel;
private JPanel GreenPanel;
private JPanel BluePanel;
private JPanel GrayPanel;
private JLabel BaseGasolineTankerLabel;
private JLabel ImprovedGasolineTankerLabel;
private JLabel SpeedLabel;
private JLabel WeightLabel;
public FormGasolineTankerConfig(){
this.setTitle("Create object");
this.setSize(900,500);
this.setContentPane(MainPanel);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
WheelsLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
WheelsFirstLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
WheelsFirstLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
BodyColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
DopColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
BaseGasolineTankerLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
ImprovedGasolineTankerLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
SpinnerWheels.setModel(new SpinnerNumberModel(2, 2, 4, 1));
SpinnerWeight.setModel(new SpinnerNumberModel(100, 100, 1000, 10));
SpinnerSpeed.setModel(new SpinnerNumberModel(10000, 10000, 20000, 100));
var dragAdapter = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
super.mouseReleased(e);
setCursor(new Cursor(Cursor.HAND_CURSOR));
}
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
dispatchDrop((JComponent) e.getSource());
}
};
RedPanel.addMouseListener(dragAdapter);
GreenPanel.addMouseListener(dragAdapter);
BluePanel.addMouseListener(dragAdapter);
YellowPanel.addMouseListener(dragAdapter);
OrangePanel.addMouseListener(dragAdapter);
GrayPanel.addMouseListener(dragAdapter);
CianPanel.addMouseListener(dragAdapter);
PinkPanel.addMouseListener(dragAdapter);
BaseGasolineTankerLabel.addMouseListener(dragAdapter);
ImprovedGasolineTankerLabel.addMouseListener(dragAdapter);
WheelsLabel.addMouseListener(dragAdapter);
WheelsFirstLabel.addMouseListener(dragAdapter);
WheelsSecondLabel.addMouseListener(dragAdapter);
ButtonAdd.addActionListener(e -> {
event.emit(gasolineTanker);
dispose();
});
ButtonCancel.addActionListener(e -> dispose());
}
public void addListener(Consumer<DrawingGasolineTanker> listener) {
event.addListener(listener);
}
public void dispatchDrop(JComponent droppedComponent) {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if (droppedComponent == null) {
return;
}
if (droppedComponent instanceof JPanel panel) {
if (BodyColorLabel.getMousePosition() != null) {
gasolineTanker.SetBodyColor(panel.getBackground());
}
if (DopColorLabel.getMousePosition() != null && gasolineTanker instanceof DrawingImprovedGasolineTanker advanced) {
advanced.SetDopColor(panel.getBackground());
}
}
if (droppedComponent instanceof JLabel label && PictureBox.getMousePosition() != null) {
int speed = (Integer) SpinnerSpeed.getValue();
int weight = (Integer) SpinnerWeight.getValue();
int countWheels = (Integer) SpinnerWheels.getValue();
boolean antenna = CheckBoxAntenna.isSelected();
boolean bodyKit = checkBoxBodyKit.isSelected();
if (label == BaseGasolineTankerLabel) {
gasolineTanker = new DrawingGasolineTanker(speed, weight, countWheels,Color.WHITE);
} else if (label == ImprovedGasolineTankerLabel) {
gasolineTanker = new DrawingImprovedGasolineTanker(speed, weight,countWheels, Color.WHITE, Color.WHITE, bodyKit, antenna);
} else if (gasolineTanker != null && label == WheelsLabel) {
gasolineTanker.SetWheels(new DrawingWheels(countWheels));
} else if (gasolineTanker != null && label == WheelsFirstLabel) {
gasolineTanker.SetWheels(new DrawingOrnamentWheelsFirst(countWheels));
} else if (gasolineTanker != null && label == WheelsSecondLabel) {
gasolineTanker.SetWheels(new DrawingOrnamentWheelsSecond(countWheels));
}
}
repaint();
}
@Override
public void paint(Graphics g) {
super.paint(g);
if (gasolineTanker != null) {
g = PictureBox.getGraphics();
gasolineTanker.SetPosition(10, 10, PictureBox.getWidth(), PictureBox.getHeight());
gasolineTanker.DrawTransport((Graphics2D) g);
}
}
private void createUIComponents() {
}
}

View File

@ -143,22 +143,21 @@ public class FormMapWithSetGasolineTanker extends JFrame{
{
return;
}
FormCreater dialog=new FormCreater();
dialog.setSize(1200,700);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
if (dialog.getSelectedGasolineTanker()!=null) {
DrawingObjectGasolineTanker gasolineTanker = new DrawingObjectGasolineTanker(dialog.getSelectedGasolineTanker());
FormGasolineTankerConfig dialog=new FormGasolineTankerConfig();
dialog.addListener(obj -> {
if (obj!=null) {
DrawingObjectGasolineTanker gasolineTanker = new DrawingObjectGasolineTanker(obj);
if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).plus(gasolineTanker)>=0) {
JOptionPane.showMessageDialog(this, "Object added", "Success", JOptionPane.INFORMATION_MESSAGE);
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
repaint();
} else {
JOptionPane.showMessageDialog(this, "Failed to add object", "Error",JOptionPane.INFORMATION_MESSAGE);
if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).plus(gasolineTanker) >= 0) {
JOptionPane.showMessageDialog(this, "Object added", "Success", JOptionPane.INFORMATION_MESSAGE);
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
repaint();
} else {
JOptionPane.showMessageDialog(this, "\n" + "Failed to add object", "Error", JOptionPane.INFORMATION_MESSAGE);
}
}
}
});
dialog.setVisible(true);
});
ButtonRemoveGasolineTanker.addActionListener(e -> {