Compare commits
2 Commits
9262f67b28
...
7e8bac26f3
Author | SHA1 | Date | |
---|---|---|---|
7e8bac26f3 | |||
6e69f8b100 |
@ -18,9 +18,9 @@ public class DrawningLocomotive {
|
|||||||
private int _locomotiveHeight = 50;
|
private int _locomotiveHeight = 50;
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
public DrawningLocomotive(int speed, float weight, Color bodyColor)
|
public DrawningLocomotive(int speed, float weight, Color bodyColor, int wheelsCount)
|
||||||
{
|
{
|
||||||
int randExtra = random.nextInt(2);
|
/*int randExtra = random.nextInt(2);
|
||||||
switch (random.nextInt(3)){
|
switch (random.nextInt(3)){
|
||||||
case 0:
|
case 0:
|
||||||
drawningExtra = new ExtraStarWheelDraw(randExtra, bodyColor);
|
drawningExtra = new ExtraStarWheelDraw(randExtra, bodyColor);
|
||||||
@ -31,7 +31,8 @@ public class DrawningLocomotive {
|
|||||||
case 2:
|
case 2:
|
||||||
drawningExtra = new ExtraWheelsDraw(randExtra, bodyColor);
|
drawningExtra = new ExtraWheelsDraw(randExtra, bodyColor);
|
||||||
break;
|
break;
|
||||||
}
|
}*/
|
||||||
|
drawningExtra = new ExtraWheelsDraw(wheelsCount, bodyColor);
|
||||||
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,13 +42,17 @@ public class DrawningLocomotive {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Новый конструктор
|
// Новый конструктор
|
||||||
protected DrawningLocomotive (int speed, float weight, Color bodyColor, int locomotiveWidth, int locomotiveHeight)
|
protected DrawningLocomotive (int speed, float weight, Color bodyColor, int wheelsCount, int locomotiveWidth, int locomotiveHeight)
|
||||||
{
|
{
|
||||||
this(speed, weight, bodyColor);
|
this(speed, weight, bodyColor, wheelsCount);
|
||||||
_locomotiveWidth = locomotiveWidth;
|
_locomotiveWidth = locomotiveWidth;
|
||||||
_locomotiveHeight = locomotiveHeight;
|
_locomotiveHeight = locomotiveHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetColor(Color color) {
|
||||||
|
Locomotive.SetColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
/// Установка позиции локомотива
|
/// Установка позиции локомотива
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
public class DrawningWarmlyLocomotive extends DrawningLocomotive{
|
public class DrawningWarmlyLocomotive extends DrawningLocomotive{
|
||||||
public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, Color extraColor, boolean pipe, boolean storage)
|
public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, int wheelsCount, Color extraColor, boolean pipe, boolean storage)
|
||||||
{
|
{
|
||||||
super(speed, weight, bodyColor, 140, 70);
|
super(speed, weight, bodyColor,wheelsCount, 140, 70);
|
||||||
Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage);
|
Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10,6 +10,13 @@ public class DrawningWarmlyLocomotive extends DrawningLocomotive{
|
|||||||
super(locomotive, extra);
|
super(locomotive, extra);
|
||||||
Locomotive = locomotive;
|
Locomotive = locomotive;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void SetColor(Color color) {
|
||||||
|
((EntityWarmlyLocomotive) Locomotive).SetColor(color);
|
||||||
|
}
|
||||||
|
public void SetExtraColor(Color color) {
|
||||||
|
((EntityWarmlyLocomotive) Locomotive).SetExtraColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void DrawTransport(Graphics2D g)
|
public void DrawTransport(Graphics2D g)
|
||||||
|
@ -14,6 +14,9 @@ public class EntityLocomotive {
|
|||||||
public Color getBodyColor() {
|
public Color getBodyColor() {
|
||||||
return BodyColor;
|
return BodyColor;
|
||||||
}
|
}
|
||||||
|
public void SetColor(Color color) {
|
||||||
|
BodyColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
public float Step () {
|
public float Step () {
|
||||||
return Speed * 100 / Weight;
|
return Speed * 100 / Weight;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class EntityWarmlyLocomotive extends EntityLocomotive{
|
public class EntityWarmlyLocomotive extends EntityLocomotive{
|
||||||
public final Color ExtraColor;
|
public Color ExtraColor;
|
||||||
public final boolean Pipe;
|
public final boolean Pipe;
|
||||||
public final boolean FuelStorage;
|
public final boolean FuelStorage;
|
||||||
public EntityWarmlyLocomotive (int speed, float weight, Color bodyColor, Color extraColor, boolean pipe, boolean fuelStorage)
|
public EntityWarmlyLocomotive (int speed, float weight, Color bodyColor, Color extraColor, boolean pipe, boolean fuelStorage)
|
||||||
@ -12,4 +12,8 @@ public class EntityWarmlyLocomotive extends EntityLocomotive{
|
|||||||
FuelStorage = fuelStorage;
|
FuelStorage = fuelStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetExtraColor(Color color) {
|
||||||
|
ExtraColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
15
EventListener.java
Normal file
15
EventListener.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class EventListener<T> {
|
||||||
|
private ArrayList<Consumer<T>> listeners = new ArrayList<>();
|
||||||
|
public void Add(Consumer<T> listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Emit(T artillery) {
|
||||||
|
for (var listener : listeners) {
|
||||||
|
listener.accept(artillery);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ import java.awt.*;
|
|||||||
public class ExtraRoundWheelDraw implements IDrawningExtra{
|
public class ExtraRoundWheelDraw implements IDrawningExtra{
|
||||||
private WheelsCount wheelsCount = WheelsCount.Two;
|
private WheelsCount wheelsCount = WheelsCount.Two;
|
||||||
private ExtraWheelsDraw extraWheelsDraw;
|
private ExtraWheelsDraw extraWheelsDraw;
|
||||||
|
private Color color;
|
||||||
public void setExtraNum(int num) {
|
public void setExtraNum(int num) {
|
||||||
switch (num) {
|
switch (num) {
|
||||||
case 0: {
|
case 0: {
|
||||||
@ -23,9 +24,13 @@ public class ExtraRoundWheelDraw implements IDrawningExtra{
|
|||||||
extraWheelsDraw = new ExtraWheelsDraw(num, bodyColor);
|
extraWheelsDraw = new ExtraWheelsDraw(num, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetColor(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawExtra(int startPosX, int startPosY, Graphics2D g) {
|
public void DrawExtra(int startPosX, int startPosY, Graphics2D g) {
|
||||||
extraWheelsDraw.DrawExtra(startPosX, startPosY, g);
|
extraWheelsDraw.DrawExtra(startPosX, startPosY, g);
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(color);
|
||||||
g.fillOval(startPosX + 5, startPosY + 35, 10, 10);
|
g.fillOval(startPosX + 5, startPosY + 35, 10, 10);
|
||||||
g.fillOval(startPosX + 95, startPosY + 35, 10, 10);
|
g.fillOval(startPosX + 95, startPosY + 35, 10, 10);
|
||||||
switch (wheelsCount) {
|
switch (wheelsCount) {
|
||||||
|
@ -3,6 +3,7 @@ import java.awt.*;
|
|||||||
public class ExtraStarWheelDraw implements IDrawningExtra{
|
public class ExtraStarWheelDraw implements IDrawningExtra{
|
||||||
private WheelsCount wheelsCount = WheelsCount.Two;
|
private WheelsCount wheelsCount = WheelsCount.Two;
|
||||||
private ExtraWheelsDraw extraWheelsDraw;
|
private ExtraWheelsDraw extraWheelsDraw;
|
||||||
|
private Color color;
|
||||||
public void setExtraNum(int num) {
|
public void setExtraNum(int num) {
|
||||||
switch (num) {
|
switch (num) {
|
||||||
case 0: {
|
case 0: {
|
||||||
@ -23,6 +24,10 @@ public class ExtraStarWheelDraw implements IDrawningExtra{
|
|||||||
extraWheelsDraw = new ExtraWheelsDraw(num, bodyColor);
|
extraWheelsDraw = new ExtraWheelsDraw(num, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetColor(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawExtra(int startPosX, int startPosY, Graphics2D g) {
|
public void DrawExtra(int startPosX, int startPosY, Graphics2D g) {
|
||||||
extraWheelsDraw.DrawExtra(startPosX, startPosY, g);
|
extraWheelsDraw.DrawExtra(startPosX, startPosY, g);
|
||||||
DrawStarOnWheel(startPosX, startPosY + 30, g);
|
DrawStarOnWheel(startPosX, startPosY + 30, g);
|
||||||
@ -41,6 +46,7 @@ public class ExtraStarWheelDraw implements IDrawningExtra{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void DrawStarOnWheel(int startPosX, int startPosY, Graphics2D g) {
|
private void DrawStarOnWheel(int startPosX, int startPosY, Graphics2D g) {
|
||||||
|
g.setColor(color);
|
||||||
g.drawLine(startPosX + 10, startPosY, startPosX + 15, startPosY + 17);
|
g.drawLine(startPosX + 10, startPosY, startPosX + 15, startPosY + 17);
|
||||||
g.drawLine(startPosX + 10, startPosY, startPosX + 5, startPosY + 17);
|
g.drawLine(startPosX + 10, startPosY, startPosX + 5, startPosY + 17);
|
||||||
g.drawLine(startPosX + 15, startPosY + 17, startPosX + 2, startPosY + 8);
|
g.drawLine(startPosX + 15, startPosY + 17, startPosX + 2, startPosY + 8);
|
||||||
|
@ -4,11 +4,11 @@ public class ExtraWheelsDraw implements IDrawningExtra{
|
|||||||
private WheelsCount wheelsCount = WheelsCount.Two;
|
private WheelsCount wheelsCount = WheelsCount.Two;
|
||||||
public void setExtraNum(int num) {
|
public void setExtraNum(int num) {
|
||||||
switch (num) {
|
switch (num) {
|
||||||
case 0: {
|
case 3: {
|
||||||
wheelsCount = WheelsCount.Three;
|
wheelsCount = WheelsCount.Three;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 4: {
|
||||||
wheelsCount = WheelsCount.Four;
|
wheelsCount = WheelsCount.Four;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -17,6 +17,9 @@ public class ExtraWheelsDraw implements IDrawningExtra{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private Color color;
|
private Color color;
|
||||||
|
public void SetColor(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
public ExtraWheelsDraw(int num, Color color) {
|
public ExtraWheelsDraw(int num, Color color) {
|
||||||
setExtraNum(num);
|
setExtraNum(num);
|
||||||
@ -27,19 +30,19 @@ public class ExtraWheelsDraw implements IDrawningExtra{
|
|||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawOval(startPosX, startPosY + 30, 20, 20);
|
g.drawOval(startPosX, startPosY + 30, 20, 20);
|
||||||
g.drawOval(startPosX + 90, startPosY + 30, 20, 20);
|
g.drawOval(startPosX + 90, startPosY + 30, 20, 20);
|
||||||
g.setColor(color);
|
g.setColor(Color.BLACK);
|
||||||
g.fillOval(startPosX, startPosY + 30, 20, 20);
|
g.fillOval(startPosX, startPosY + 30, 20, 20);
|
||||||
g.fillOval(startPosX + 90, startPosY + 30, 20, 20);
|
g.fillOval(startPosX + 90, startPosY + 30, 20, 20);
|
||||||
switch (wheelsCount) {
|
switch (wheelsCount) {
|
||||||
case Four: {
|
case Four: {
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawOval(startPosX + 70, startPosY + 30, 20, 20);
|
|
||||||
g.setColor(color);
|
g.setColor(color);
|
||||||
|
g.drawOval(startPosX + 70, startPosY + 30, 20, 20);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
g.fillOval(startPosX + 70, startPosY + 30, 20, 20);
|
g.fillOval(startPosX + 70, startPosY + 30, 20, 20);
|
||||||
}
|
}
|
||||||
case Three: {
|
case Three: {
|
||||||
g.fillOval(startPosX + 20, startPosY + 30, 20, 20);
|
g.fillOval(startPosX + 20, startPosY + 30, 20, 20);
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(color);
|
||||||
g.drawOval(startPosX + 20, startPosY + 30, 20, 20);
|
g.drawOval(startPosX + 20, startPosY + 30, 20, 20);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class FormLocomotive extends JComponent{
|
|||||||
|
|
||||||
Color colorFirst = JColorChooser.showDialog(null, "Цвет", new Color(rnd.nextInt(256), rnd.nextInt(256),rnd.nextInt(256)));
|
Color colorFirst = JColorChooser.showDialog(null, "Цвет", new Color(rnd.nextInt(256), rnd.nextInt(256),rnd.nextInt(256)));
|
||||||
|
|
||||||
_locomotive = new DrawningLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, colorFirst);
|
_locomotive = new DrawningLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, colorFirst, rnd.nextInt(2) + 2);
|
||||||
_locomotive.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), 800, 500-75);
|
_locomotive.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), 800, 500-75);
|
||||||
speedLabel.setText("Speed: " + _locomotive.Locomotive.getSpeed());
|
speedLabel.setText("Speed: " + _locomotive.Locomotive.getSpeed());
|
||||||
weightLabel.setText("Weight: " + (int)_locomotive.Locomotive.getWeight());
|
weightLabel.setText("Weight: " + (int)_locomotive.Locomotive.getWeight());
|
||||||
@ -47,6 +47,7 @@ public class FormLocomotive extends JComponent{
|
|||||||
|
|
||||||
_locomotive = new DrawningWarmlyLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
_locomotive = new DrawningWarmlyLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
||||||
colorFirst,
|
colorFirst,
|
||||||
|
rnd.nextInt(2) + 2,
|
||||||
colorSecond,
|
colorSecond,
|
||||||
rnd.nextBoolean(),
|
rnd.nextBoolean(),
|
||||||
rnd.nextBoolean());
|
rnd.nextBoolean());
|
||||||
@ -107,6 +108,7 @@ public class FormLocomotive extends JComponent{
|
|||||||
super.repaint();
|
super.repaint();
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
new FormMapWithSetLocomotives();
|
new FormMapWithSetLocomotives();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
337
FormLocomotiveConfig.form
Normal file
337
FormLocomotiveConfig.form
Normal file
@ -0,0 +1,337 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormLocomotiveConfig">
|
||||||
|
<grid id="27dc6" binding="FormPanel" layout-manager="GridLayoutManager" row-count="1" 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="688" height="485"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="1add4" binding="ParametersPanel" layout-manager="GridLayoutManager" row-count="1" 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="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="none" title="Parameters"/>
|
||||||
|
<children>
|
||||||
|
<grid id="ac7f6" binding="ColorPanel" layout-manager="GridLayoutManager" row-count="3" 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="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/>
|
||||||
|
<border type="none" title="Color Pick"/>
|
||||||
|
<children>
|
||||||
|
<grid id="56efb" binding="RedColorPanel" 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">
|
||||||
|
<minimum-size width="50" height="50"/>
|
||||||
|
<maximum-size width="50" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-65536"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="49a9d" binding="GreenColorPanel" 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">
|
||||||
|
<minimum-size width="50" height="50"/>
|
||||||
|
<maximum-size width="50" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-16711936"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="94ada" binding="BlueColorPanel" 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">
|
||||||
|
<minimum-size width="50" height="50"/>
|
||||||
|
<maximum-size width="50" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-16776961"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="39e91" binding="YellowColorPanel" 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">
|
||||||
|
<minimum-size width="50" height="50"/>
|
||||||
|
<maximum-size width="50" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-256"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="20acf" binding="WhiteColorPanel" 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">
|
||||||
|
<minimum-size width="50" height="50"/>
|
||||||
|
<maximum-size width="50" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-1"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="5cd7b" binding="BlackColorPanel" 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">
|
||||||
|
<minimum-size width="50" height="50"/>
|
||||||
|
<maximum-size width="50" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-16777216"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="54ec4" binding="AquaColorPanel" 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">
|
||||||
|
<minimum-size width="50" height="50"/>
|
||||||
|
<maximum-size width="50" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-16711681"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="5bf58" binding="PurpleColorPanel" 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">
|
||||||
|
<minimum-size width="50" height="50"/>
|
||||||
|
<maximum-size width="50" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-65281"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<vspacer id="47a2">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="4" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="97483" binding="StatsPanel" layout-manager="GridLayoutManager" row-count="10" 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="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="none" title="Stats"/>
|
||||||
|
<children>
|
||||||
|
<component id="a2b73" 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="63e1f" class="javax.swing.JSpinner" binding="SpeedSpinner">
|
||||||
|
<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>
|
||||||
|
<component id="4677d" 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="dd3cf" class="javax.swing.JSpinner" binding="WeightSpinner">
|
||||||
|
<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>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="d60f6" class="javax.swing.JCheckBox" binding="PipeCheckBox">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Add Pipe"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="91766" class="javax.swing.JCheckBox" binding="FuelCheckBox">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Add Fuel Storage"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="cb567" class="javax.swing.JLabel" binding="SimpleObjectLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="100" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<text value="Simple "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="8c3ff" class="javax.swing.JLabel" binding="AdvancedObjectLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="100" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<text value="Advanced"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="d7166" class="javax.swing.JLabel" binding="SimpleWheelsLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="100" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<text value="SimpleWheels"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b76f1" class="javax.swing.JLabel" binding="StarWheelsLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="7" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="100" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<text value="StarWheels"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="a09d0" class="javax.swing.JLabel" binding="RoundWheelsLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="100" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<text value="RoundWheels"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="55da5" class="javax.swing.JSpinner" binding="WheelsCountSpinner">
|
||||||
|
<constraints>
|
||||||
|
<grid row="9" 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>
|
||||||
|
<component id="5c650" class="javax.swing.JLabel" binding="WheelsCountLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="9" 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="WheelsCount"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="ddc6e" binding="CreatePanel" 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="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none" title="Create"/>
|
||||||
|
<children>
|
||||||
|
<component id="81e87" class="javax.swing.JLabel" binding="MainColorLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="100" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<text value="BaseColor"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b3269" class="javax.swing.JLabel" binding="ExtraColorLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="100" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<text value="ExtraColor"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<grid id="4dc4a" binding="ObjectViewPanel" 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="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<component id="c9686" class="javax.swing.JButton" binding="AddButton">
|
||||||
|
<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="ff438" class="javax.swing.JButton" binding="CancelButton">
|
||||||
|
<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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
158
FormLocomotiveConfig.java
Normal file
158
FormLocomotiveConfig.java
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class FormLocomotiveConfig extends JFrame{
|
||||||
|
// Рабочие поля
|
||||||
|
private DrawningLocomotive locomotive;
|
||||||
|
private EventListener<DrawningLocomotive> eventListener = new EventListener<>();
|
||||||
|
|
||||||
|
//Элементы формы
|
||||||
|
private JPanel FormPanel;
|
||||||
|
private JPanel ParametersPanel;
|
||||||
|
private JPanel CreatePanel;
|
||||||
|
private JPanel ColorPanel;
|
||||||
|
private JPanel StatsPanel;
|
||||||
|
private JLabel SpeedLabel;
|
||||||
|
private JSpinner SpeedSpinner;
|
||||||
|
private JLabel WeightLabel;
|
||||||
|
private JSpinner WeightSpinner;
|
||||||
|
private JCheckBox PipeCheckBox;
|
||||||
|
private JCheckBox FuelCheckBox;
|
||||||
|
private JLabel SimpleObjectLabel;
|
||||||
|
private JLabel AdvancedObjectLabel;
|
||||||
|
private JLabel SimpleWheelsLabel;
|
||||||
|
private JLabel StarWheelsLabel;
|
||||||
|
private JLabel RoundWheelsLabel;
|
||||||
|
private JSpinner WheelsCountSpinner;
|
||||||
|
private JLabel WheelsCountLabel;
|
||||||
|
private JPanel RedColorPanel;
|
||||||
|
private JPanel GreenColorPanel;
|
||||||
|
private JPanel BlueColorPanel;
|
||||||
|
private JPanel YellowColorPanel;
|
||||||
|
private JPanel WhiteColorPanel;
|
||||||
|
private JPanel BlackColorPanel;
|
||||||
|
private JPanel AquaColorPanel;
|
||||||
|
private JPanel PurpleColorPanel;
|
||||||
|
private JLabel MainColorLabel;
|
||||||
|
private JLabel ExtraColorLabel;
|
||||||
|
private JPanel ObjectViewPanel;
|
||||||
|
private JButton AddButton;
|
||||||
|
private JButton CancelButton;
|
||||||
|
|
||||||
|
public FormLocomotiveConfig() {
|
||||||
|
|
||||||
|
// Добавили цветные границы
|
||||||
|
SimpleObjectLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
AdvancedObjectLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
SimpleWheelsLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
RoundWheelsLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
StarWheelsLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
MainColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
ExtraColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
|
||||||
|
// Модели для намериков
|
||||||
|
SpeedSpinner.setModel(new SpinnerNumberModel(100, 50, 1000, 10));
|
||||||
|
WeightSpinner.setModel(new SpinnerNumberModel(1000, 1000, 5000, 10));
|
||||||
|
WheelsCountSpinner.setModel(new SpinnerNumberModel(2, 2, 4, 1));
|
||||||
|
|
||||||
|
//Обработчик d&d
|
||||||
|
var DragDropAdapter = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
super.mouseReleased(e);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
super.mouseReleased(e);
|
||||||
|
Drop((JComponent) e.getSource());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SimpleObjectLabel.addMouseListener(DragDropAdapter);
|
||||||
|
AdvancedObjectLabel.addMouseListener(DragDropAdapter);
|
||||||
|
StarWheelsLabel.addMouseListener(DragDropAdapter);
|
||||||
|
RoundWheelsLabel.addMouseListener(DragDropAdapter);
|
||||||
|
StarWheelsLabel.addMouseListener(DragDropAdapter);
|
||||||
|
RedColorPanel.addMouseListener(DragDropAdapter);
|
||||||
|
GreenColorPanel.addMouseListener(DragDropAdapter);
|
||||||
|
BlueColorPanel.addMouseListener(DragDropAdapter);
|
||||||
|
YellowColorPanel.addMouseListener(DragDropAdapter);
|
||||||
|
WhiteColorPanel.addMouseListener(DragDropAdapter);
|
||||||
|
BlackColorPanel.addMouseListener(DragDropAdapter);
|
||||||
|
AquaColorPanel.addMouseListener(DragDropAdapter);
|
||||||
|
PurpleColorPanel.addMouseListener(DragDropAdapter);
|
||||||
|
|
||||||
|
AddButton.addActionListener(e -> {
|
||||||
|
eventListener.Emit(locomotive);
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
CancelButton.addActionListener(e -> dispose());
|
||||||
|
|
||||||
|
// Параметры фрейма
|
||||||
|
setContentPane(FormPanel);
|
||||||
|
setSize(800, 500);
|
||||||
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop обработка
|
||||||
|
public void Drop (JComponent component) {
|
||||||
|
if (component == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (component instanceof JPanel panel) {
|
||||||
|
if (MainColorLabel.getMousePosition() != null) {
|
||||||
|
locomotive.SetColor(panel.getBackground());
|
||||||
|
locomotive.drawningExtra.SetColor(panel.getBackground());
|
||||||
|
}
|
||||||
|
if (ExtraColorLabel.getMousePosition() != null && locomotive instanceof DrawningWarmlyLocomotive warmlyLocomotive) {
|
||||||
|
warmlyLocomotive.SetExtraColor(panel.getBackground());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (component instanceof JLabel label && ObjectViewPanel.getMousePosition() != null) {
|
||||||
|
int speed = (Integer) SpeedSpinner.getValue();
|
||||||
|
int weight = (Integer) WeightSpinner.getValue();
|
||||||
|
int wheelsCount = (Integer) WheelsCountSpinner.getValue();
|
||||||
|
boolean pipe = PipeCheckBox.isSelected();
|
||||||
|
boolean fuel = FuelCheckBox.isSelected();
|
||||||
|
|
||||||
|
if (label == SimpleObjectLabel) {
|
||||||
|
locomotive = new DrawningLocomotive(speed, weight, Color.WHITE, wheelsCount);
|
||||||
|
} else if (label == AdvancedObjectLabel) {
|
||||||
|
locomotive = new DrawningWarmlyLocomotive(speed, weight, Color.WHITE, wheelsCount, Color.WHITE, pipe, fuel);
|
||||||
|
} else if (locomotive != null && label == SimpleWheelsLabel) {
|
||||||
|
locomotive.drawningExtra = new ExtraWheelsDraw(wheelsCount, locomotive.Locomotive.getBodyColor());
|
||||||
|
locomotive.drawningExtra.SetColor( locomotive.Locomotive.getBodyColor());
|
||||||
|
} else if (locomotive != null && label == StarWheelsLabel) {
|
||||||
|
locomotive.drawningExtra = new ExtraStarWheelDraw(wheelsCount, locomotive.Locomotive.getBodyColor());
|
||||||
|
locomotive.drawningExtra.SetColor( locomotive.Locomotive.getBodyColor());
|
||||||
|
} else if (locomotive != null && label == RoundWheelsLabel) {
|
||||||
|
locomotive.drawningExtra = new ExtraRoundWheelDraw(wheelsCount, locomotive.Locomotive.getBodyColor());
|
||||||
|
locomotive.drawningExtra.SetColor( locomotive.Locomotive.getBodyColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddListener(Consumer<DrawningLocomotive> listener) {
|
||||||
|
eventListener.Add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
if (locomotive != null) {
|
||||||
|
g = ObjectViewPanel.getGraphics();
|
||||||
|
locomotive.SetPosition(20, 20, ObjectViewPanel.getWidth(), ObjectViewPanel.getHeight());
|
||||||
|
locomotive.DrawTransport((Graphics2D) g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -56,7 +56,7 @@ public class FormMap extends JComponent {
|
|||||||
JButton createButton = new JButton("Create");
|
JButton createButton = new JButton("Create");
|
||||||
createButton.addActionListener(e -> {
|
createButton.addActionListener(e -> {
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
var locomotive = new DrawningLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
var locomotive = new DrawningLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(2) + 2);
|
||||||
speedLabel.setText("Speed: " + locomotive.Locomotive.getSpeed());
|
speedLabel.setText("Speed: " + locomotive.Locomotive.getSpeed());
|
||||||
weightLabel.setText("Weight: " + (int)locomotive.Locomotive.getWeight());
|
weightLabel.setText("Weight: " + (int)locomotive.Locomotive.getWeight());
|
||||||
colorLabel.setText("Color: " + locomotive.Locomotive.getBodyColor().getRed() + " " + locomotive.Locomotive.getBodyColor().getGreen() + " " + locomotive.Locomotive.getBodyColor().getBlue());
|
colorLabel.setText("Color: " + locomotive.Locomotive.getBodyColor().getRed() + " " + locomotive.Locomotive.getBodyColor().getGreen() + " " + locomotive.Locomotive.getBodyColor().getBlue());
|
||||||
@ -69,6 +69,7 @@ public class FormMap extends JComponent {
|
|||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
var locomotive = new DrawningWarmlyLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
var locomotive = new DrawningWarmlyLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
||||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||||
|
rnd.nextInt(2) + 2,
|
||||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||||
rnd.nextBoolean(),
|
rnd.nextBoolean(),
|
||||||
rnd.nextBoolean());
|
rnd.nextBoolean());
|
||||||
|
@ -113,7 +113,7 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
// Кнопка добавления локомотива
|
// Кнопка добавления локомотива
|
||||||
JButton addLocomotiveButton = new JButton("Add Locomotive");
|
JButton addLocomotiveButton = new JButton("Add Locomotive");
|
||||||
addLocomotiveButton.addActionListener(e -> {
|
addLocomotiveButton.addActionListener(e -> {
|
||||||
// логика добавления
|
/*// логика добавления
|
||||||
if (listBoxMaps.getSelectedIndex() == -1)
|
if (listBoxMaps.getSelectedIndex() == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -132,7 +132,26 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JOptionPane.showMessageDialog(formFrame, "Object cannot be added", "Error", JOptionPane.OK_CANCEL_OPTION);
|
JOptionPane.showMessageDialog(formFrame, "Object cannot be added", "Error", JOptionPane.OK_CANCEL_OPTION);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
FormLocomotiveConfig formLocomotiveConfig = new FormLocomotiveConfig();
|
||||||
|
formLocomotiveConfig.setVisible(true);
|
||||||
|
formLocomotiveConfig.AddListener(locomotive -> {
|
||||||
|
if (listBoxMaps.getSelectedIndex() == -1) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if (locomotive!=null) {
|
||||||
|
DrawningObjectLocomotive objectLocomotive = new DrawningObjectLocomotive(locomotive);
|
||||||
|
if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Plus(objectLocomotive)!= -1){
|
||||||
|
JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION);
|
||||||
|
bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(formFrame, "Object cannot be added", "Error", JOptionPane.OK_CANCEL_OPTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
statusPanel.add(addLocomotiveButton);
|
statusPanel.add(addLocomotiveButton);
|
||||||
|
|
||||||
|
@ -3,4 +3,5 @@ import java.awt.*;
|
|||||||
public interface IDrawningExtra {
|
public interface IDrawningExtra {
|
||||||
void setExtraNum(int num);
|
void setExtraNum(int num);
|
||||||
void DrawExtra(int startPosX, int startPosY, Graphics2D g);
|
void DrawExtra(int startPosX, int startPosY, Graphics2D g);
|
||||||
|
void SetColor(Color color);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user