Пофиксил формочку

This commit is contained in:
gg12 darfren 2023-10-25 23:51:31 +04:00
parent 321ec13a27
commit d8f83dcb7d
7 changed files with 41 additions and 211 deletions

View File

@ -7,8 +7,8 @@ import java.awt.*;
public class DrawningLocomotive extends DrawningMonorail{ public class DrawningLocomotive extends DrawningMonorail{
public DrawningLocomotive(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int wheelNumb, public DrawningLocomotive(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int wheelNumb,
int width, int height, boolean secondCabine, boolean magniteRail, Color additionalColor, JPanel monorailPanel){ int width, int height, boolean secondCabine, boolean magniteRail, Color additionalColor){
super(speed, weight, bodyColor, wheelColor, tireColor, width, height, monorailPanel); super(speed, weight, bodyColor, wheelColor, tireColor, width, height);
if(EntityMonorail() != null){ if(EntityMonorail() != null){
EntityMonorail = new EntityLocomotive(speed, weight, bodyColor, wheelColor, tireColor, wheelNumb, secondCabine, EntityMonorail = new EntityLocomotive(speed, weight, bodyColor, wheelColor, tireColor, wheelNumb, secondCabine,
magniteRail, additionalColor); magniteRail, additionalColor);
@ -16,16 +16,15 @@ public class DrawningLocomotive extends DrawningMonorail{
} }
@Override @Override
public void DrawMonorail(){ public void DrawMonorail(Graphics2D g2d){
if (!(EntityMonorail instanceof EntityLocomotive)) if (!(EntityMonorail instanceof EntityLocomotive))
{ {
return; return;
} }
super.DrawMonorail(); super.DrawMonorail(g2d);
int dif = _monorailWidth / 10; int dif = _monorailWidth / 10;
_monorailWidth -= dif; _monorailWidth -= dif;
EntityLocomotive _locomotive = (EntityLocomotive) EntityMonorail; EntityLocomotive _locomotive = (EntityLocomotive) EntityMonorail;
Graphics2D g2d = (Graphics2D)MonorailPanel.getGraphics();
//вторая кабина //вторая кабина
if (_locomotive.SecondCabine()) { if (_locomotive.SecondCabine()) {
int[] pointsSecondCabineX = {_startPosX + _monorailWidth / 20 * 19, int[] pointsSecondCabineX = {_startPosX + _monorailWidth / 20 * 19,

View File

@ -11,7 +11,6 @@ import java.util.Random;
public class DrawningMonorail { public class DrawningMonorail {
protected JPanel MonorailPanel;
protected EntityMonorail EntityMonorail; protected EntityMonorail EntityMonorail;
private int _pictureWidth; private int _pictureWidth;
private int _pictureHeight; private int _pictureHeight;
@ -26,40 +25,34 @@ public class DrawningMonorail {
return EntityMonorail; return EntityMonorail;
} }
public DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, public DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor,
int width, int height, JPanel monorailPanel){ int width, int height){
if(width <= _monorailWidth || height <= _monorailHeight) if(width <= _monorailWidth || height <= _monorailHeight)
return; return;
_startPosY=0; _startPosY=0;
_startPosX = 0; _startPosX = 0;
monorailPanel.setSize(width, height);
MonorailPanel = monorailPanel;
monorailPanel.paint(MonorailPanel.getGraphics());
wheelSz = _monorailHeight - _monorailHeight * 7 / 10; wheelSz = _monorailHeight - _monorailHeight * 7 / 10;
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
EntityMonorail = new EntityMonorail(speed, weight, bodyColor, wheelColor, tireColor); EntityMonorail = new EntityMonorail(speed, weight, bodyColor, wheelColor, tireColor);
int dif = _monorailWidth / 10; int dif = _monorailWidth / 10;
DrawningWheels = new DrawningWheelsCart(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor,monorailPanel); DrawningWheels = new DrawningWheelsCart(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor);
Random rand = new Random(); Random rand = new Random();
int variant = rand.nextInt(0, 3); int variant = rand.nextInt(0, 3);
if(variant == 0) if(variant == 0)
DrawningWheels = new DrawningWheels(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor,monorailPanel); DrawningWheels = new DrawningWheels(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor);
else if(variant == 1) else if(variant == 1)
DrawningWheels = new DrawningWheelsCart(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor,monorailPanel); DrawningWheels = new DrawningWheelsCart(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor);
else else
DrawningWheels = new DrawningWheelsOrn(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor,monorailPanel); DrawningWheels = new DrawningWheelsOrn(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor);
DrawningWheels.ChangeWheelsNumb(rand.nextInt(1, 6)); DrawningWheels.ChangeWheelsNumb(rand.nextInt(1, 6));
} }
protected DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, protected DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor,
int width, int height, int monorailWidth, int monorailHeight, JPanel monorailPanel){ int width, int height, int monorailWidth, int monorailHeight){
if(width <= _monorailWidth || height <= _monorailHeight) if(width <= _monorailWidth || height <= _monorailHeight)
return; return;
_startPosY=0; _startPosY=0;
_startPosX = 0; _startPosX = 0;
monorailPanel.setSize(width, height);
MonorailPanel = monorailPanel;
monorailPanel.paint(MonorailPanel.getGraphics());
wheelSz = _monorailHeight - _monorailHeight * 7 / 10; wheelSz = _monorailHeight - _monorailHeight * 7 / 10;
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
@ -70,11 +63,11 @@ public class DrawningMonorail {
Random rand = new Random(); Random rand = new Random();
int variant = rand.nextInt(0, 3); int variant = rand.nextInt(0, 3);
if(variant == 0) if(variant == 0)
DrawningWheels = new DrawningWheels(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor,monorailPanel); DrawningWheels = new DrawningWheels(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor);
else if(variant == 1) else if(variant == 1)
DrawningWheels = new DrawningWheelsCart(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor,monorailPanel); DrawningWheels = new DrawningWheelsCart(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor);
else else
DrawningWheels = new DrawningWheelsOrn(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor,monorailPanel); DrawningWheels = new DrawningWheelsOrn(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor);
DrawningWheels.ChangeWheelsNumb(rand.nextInt(1, 6)); DrawningWheels.ChangeWheelsNumb(rand.nextInt(1, 6));
@ -123,7 +116,6 @@ public class DrawningMonorail {
public void MoveTransport(DirectionType direction){ public void MoveTransport(DirectionType direction){
if (!CanMove(direction) || EntityMonorail == null) if (!CanMove(direction) || EntityMonorail == null)
return; return;
MonorailPanel.paint(MonorailPanel.getGraphics());
switch (direction) switch (direction)
{ {
case Left: case Left:
@ -147,8 +139,7 @@ public class DrawningMonorail {
DrawningWheels.ChangeY(_startPosY); DrawningWheels.ChangeY(_startPosY);
} }
public void DrawMonorail(){ public void DrawMonorail(Graphics2D g2d){
Graphics2D g2d = (Graphics2D)MonorailPanel.getGraphics();
if (EntityMonorail == null) if (EntityMonorail == null)
return; return;
int dif = _monorailWidth / 10; int dif = _monorailWidth / 10;
@ -231,7 +222,7 @@ public class DrawningMonorail {
g2d.setColor(Color.BLUE); g2d.setColor(Color.BLUE);
g2d.drawRect(rightRect.x, rightRect.y, rightRect.width, rightRect.height); g2d.drawRect(rightRect.x, rightRect.y, rightRect.width, rightRect.height);
//колеса //колеса
DrawningWheels.DrawWheels(); DrawningWheels.DrawWheels(g2d);
_monorailWidth += dif; _monorailWidth += dif;
} }
} }

View File

@ -7,7 +7,6 @@ import java.awt.*;
public class DrawningWheels implements IDraw{ public class DrawningWheels implements IDraw{
private int WheelSz; private int WheelSz;
JPanel MonorailPanel;
private NumberType WheelsNumb; private NumberType WheelsNumb;
private Color WheelColor, TireColor; private Color WheelColor, TireColor;
private int Width, Height; private int Width, Height;
@ -16,7 +15,7 @@ public class DrawningWheels implements IDraw{
return WheelSz; return WheelSz;
} }
public DrawningWheels(int width, int height, int curX, int curY, Color wheelColor, Color tireColor, JPanel monorailPanel){ public DrawningWheels(int width, int height, int curX, int curY, Color wheelColor, Color tireColor){
Width = width; Width = width;
Height = height; Height = height;
CurX = curX; CurX = curX;
@ -24,7 +23,6 @@ public class DrawningWheels implements IDraw{
WheelColor = wheelColor; WheelColor = wheelColor;
TireColor = tireColor; TireColor = tireColor;
WheelSz = Height - Height * 7 / 10; WheelSz = Height - Height * 7 / 10;
MonorailPanel = monorailPanel;
} }
public void ChangeX(int x){ public void ChangeX(int x){
CurX = x; CurX = x;
@ -45,16 +43,14 @@ public class DrawningWheels implements IDraw{
return WheelsNumb; return WheelsNumb;
} }
public void DrawWheel(int x, int y){ public void DrawWheel(Graphics2D g2d, int x, int y){
Graphics2D g2d = (Graphics2D)MonorailPanel.getGraphics();
g2d.setColor(WheelColor); g2d.setColor(WheelColor);
g2d.fillOval( x, y , WheelSz, WheelSz); g2d.fillOval( x, y , WheelSz, WheelSz);
g2d.setColor(TireColor); g2d.setColor(TireColor);
g2d.drawOval(x, y, WheelSz, WheelSz); g2d.drawOval(x, y, WheelSz, WheelSz);
} }
public void DrawWheels(){ public void DrawWheels(Graphics2D g2d){
Graphics2D g2d = (Graphics2D)MonorailPanel.getGraphics();
//передняя часть тележки //передняя часть тележки
int[] xPointsArrFrontCart = { CurX + Width / 10 * 4, CurX + Width / 10 * 2, int[] xPointsArrFrontCart = { CurX + Width / 10 * 4, CurX + Width / 10 * 2,
CurX, CurX + Width / 10 * 4, CurX, CurX + Width / 10 * 4,
@ -73,15 +69,15 @@ public class DrawningWheels implements IDraw{
g2d.fillPolygon(xPointsArrBackCart, yPointsArrBackCart, xPointsArrBackCart.length); g2d.fillPolygon(xPointsArrBackCart, yPointsArrBackCart, xPointsArrBackCart.length);
DrawWheel(CurX + Width / 10, CurY + Height / 10 * 7); DrawWheel(g2d, CurX + Width / 10, CurY + Height / 10 * 7);
DrawWheel(CurX + Width / 10 * 8, CurY + Height / 10 * 7); DrawWheel(g2d, CurX + Width / 10 * 8, CurY + Height / 10 * 7);
//3 колеса //3 колеса
if (WheelsNumb == NumberType.Three || WheelsNumb == NumberType.Four) if (WheelsNumb == NumberType.Three || WheelsNumb == NumberType.Four)
DrawWheel(CurX + Width / 10 * 6, CurY + Height / 10 * 7); DrawWheel(g2d,CurX + Width / 10 * 6, CurY + Height / 10 * 7);
//4 колеса //4 колеса
if (WheelsNumb == NumberType.Four) if (WheelsNumb == NumberType.Four)
DrawWheel(CurX + Width / 10 * 3, CurY + Height / 10 * 7); DrawWheel(g2d, CurX + Width / 10 * 3, CurY + Height / 10 * 7);
} }

View File

@ -7,7 +7,6 @@ import java.awt.*;
public class DrawningWheelsCart implements IDraw{ public class DrawningWheelsCart implements IDraw{
private int WheelSz; private int WheelSz;
JPanel MonorailPanel;
private NumberType WheelsNumb; private NumberType WheelsNumb;
private Color WheelColor, TireColor; private Color WheelColor, TireColor;
private int Width, Height; private int Width, Height;
@ -16,7 +15,7 @@ public class DrawningWheelsCart implements IDraw{
return WheelSz; return WheelSz;
} }
public DrawningWheelsCart(int width, int height, int curX, int curY, Color wheelColor, Color tireColor, JPanel monorailPanel){ public DrawningWheelsCart(int width, int height, int curX, int curY, Color wheelColor, Color tireColor){
Width = width; Width = width;
Height = height; Height = height;
CurX = curX; CurX = curX;
@ -24,7 +23,6 @@ public class DrawningWheelsCart implements IDraw{
WheelColor = wheelColor; WheelColor = wheelColor;
TireColor = tireColor; TireColor = tireColor;
WheelSz = Height - Height * 7 / 10; WheelSz = Height - Height * 7 / 10;
MonorailPanel = monorailPanel;
} }
public void ChangeWheelsNumb(int x){ public void ChangeWheelsNumb(int x){
@ -46,16 +44,14 @@ public class DrawningWheelsCart implements IDraw{
public void ChangeY(int y){ public void ChangeY(int y){
CurY = y; CurY = y;
} }
public void DrawWheel(int x, int y){ public void DrawWheel(Graphics2D g2d, int x, int y){
Graphics2D g2d = (Graphics2D)MonorailPanel.getGraphics();
g2d.setColor(WheelColor); g2d.setColor(WheelColor);
g2d.fillOval( x, y , WheelSz, WheelSz); g2d.fillOval( x, y , WheelSz, WheelSz);
g2d.setColor(TireColor); g2d.setColor(TireColor);
g2d.drawOval(x, y, WheelSz, WheelSz); g2d.drawOval(x, y, WheelSz, WheelSz);
} }
public void DrawWheels(){ public void DrawWheels(Graphics2D g2d){
Graphics2D g2d = (Graphics2D)MonorailPanel.getGraphics();
//передняя часть тележки //передняя часть тележки
int[] xPointsArrFrontCart = { CurX + Width / 10 * 4, CurX + Width / 10 * 2, int[] xPointsArrFrontCart = { CurX + Width / 10 * 4, CurX + Width / 10 * 2,
CurX, CurX + Width / 10 * 4, CurX, CurX + Width / 10 * 4,
@ -80,14 +76,14 @@ public class DrawningWheelsCart implements IDraw{
g2d.drawLine(CurX + Width / 10 * 6, CurY + Height / 10 * 7,CurX + Width / 10 * 9, CurY + Height / 10 * 9); g2d.drawLine(CurX + Width / 10 * 6, CurY + Height / 10 * 7,CurX + Width / 10 * 9, CurY + Height / 10 * 9);
g2d.drawLine(CurX + Width / 10 * 9, CurY + Height / 10 * 7,CurX + Width / 10 * 6, CurY + Height / 10 * 9); g2d.drawLine(CurX + Width / 10 * 9, CurY + Height / 10 * 7,CurX + Width / 10 * 6, CurY + Height / 10 * 9);
DrawWheel(CurX + Width / 10, CurY + Height / 10 * 7); DrawWheel(g2d, CurX + Width / 10, CurY + Height / 10 * 7);
DrawWheel(CurX + Width / 10 * 8, CurY + Height / 10 * 7); DrawWheel(g2d, CurX + Width / 10 * 8, CurY + Height / 10 * 7);
//3 колеса //3 колеса
if (WheelsNumb == NumberType.Three || WheelsNumb == NumberType.Four) if (WheelsNumb == NumberType.Three || WheelsNumb == NumberType.Four)
DrawWheel(CurX + Width / 10 * 6, CurY + Height / 10 * 7); DrawWheel(g2d, CurX + Width / 10 * 6, CurY + Height / 10 * 7);
//4 колеса //4 колеса
if (WheelsNumb == NumberType.Four) if (WheelsNumb == NumberType.Four)
DrawWheel(CurX + Width / 10 * 3, CurY + Height / 10 * 7); DrawWheel(g2d, CurX + Width / 10 * 3, CurY + Height / 10 * 7);
} }
} }

View File

@ -7,7 +7,6 @@ import java.awt.*;
public class DrawningWheelsOrn implements IDraw{ public class DrawningWheelsOrn implements IDraw{
private int WheelSz; private int WheelSz;
JPanel MonorailPanel;
private NumberType WheelsNumb; private NumberType WheelsNumb;
private Color WheelColor, TireColor; private Color WheelColor, TireColor;
private int Width, Height; private int Width, Height;
@ -16,7 +15,7 @@ public class DrawningWheelsOrn implements IDraw{
return WheelSz; return WheelSz;
} }
public DrawningWheelsOrn(int width, int height, int curX, int curY, Color wheelColor, Color tireColor, JPanel monorailPanel){ public DrawningWheelsOrn(int width, int height, int curX, int curY, Color wheelColor, Color tireColor){
Width = width; Width = width;
Height = height; Height = height;
CurX = curX; CurX = curX;
@ -24,7 +23,6 @@ public class DrawningWheelsOrn implements IDraw{
WheelColor = wheelColor; WheelColor = wheelColor;
TireColor = tireColor; TireColor = tireColor;
WheelSz = Height - Height * 7 / 10; WheelSz = Height - Height * 7 / 10;
MonorailPanel = monorailPanel;
} }
public void ChangeWheelsNumb(int x){ public void ChangeWheelsNumb(int x){
@ -46,8 +44,7 @@ public class DrawningWheelsOrn implements IDraw{
public void ChangeY(int y){ public void ChangeY(int y){
CurY = y; CurY = y;
} }
public void DrawWheel(int x, int y){ public void DrawWheel(Graphics2D g2d, int x, int y){
Graphics2D g2d = (Graphics2D)MonorailPanel.getGraphics();
g2d.setColor(WheelColor); g2d.setColor(WheelColor);
g2d.fillOval( x, y , WheelSz, WheelSz); g2d.fillOval( x, y , WheelSz, WheelSz);
g2d.setColor(TireColor); g2d.setColor(TireColor);
@ -56,8 +53,7 @@ public class DrawningWheelsOrn implements IDraw{
g2d.drawLine(x + WheelSz / 2, y, x + WheelSz / 2, y + WheelSz); g2d.drawLine(x + WheelSz / 2, y, x + WheelSz / 2, y + WheelSz);
} }
public void DrawWheels(){ public void DrawWheels(Graphics2D g2d){
Graphics2D g2d = (Graphics2D)MonorailPanel.getGraphics();
//передняя часть тележки //передняя часть тележки
int[] xPointsArrFrontCart = { CurX + Width / 10 * 4, CurX + Width / 10 * 2, int[] xPointsArrFrontCart = { CurX + Width / 10 * 4, CurX + Width / 10 * 2,
CurX, CurX + Width / 10 * 4, CurX, CurX + Width / 10 * 4,
@ -76,14 +72,14 @@ public class DrawningWheelsOrn implements IDraw{
g2d.fillPolygon(xPointsArrBackCart, yPointsArrBackCart, xPointsArrBackCart.length); g2d.fillPolygon(xPointsArrBackCart, yPointsArrBackCart, xPointsArrBackCart.length);
DrawWheel(CurX + Width / 10, CurY + Height / 10 * 7); DrawWheel(g2d, CurX + Width / 10, CurY + Height / 10 * 7);
DrawWheel(CurX + Width / 10 * 8, CurY + Height / 10 * 7); DrawWheel(g2d,CurX + Width / 10 * 8, CurY + Height / 10 * 7);
//3 колеса //3 колеса
if (WheelsNumb == NumberType.Three || WheelsNumb == NumberType.Four) if (WheelsNumb == NumberType.Three || WheelsNumb == NumberType.Four)
DrawWheel(CurX + Width / 10 * 6, CurY + Height / 10 * 7); DrawWheel(g2d,CurX + Width / 10 * 6, CurY + Height / 10 * 7);
//4 колеса //4 колеса
if (WheelsNumb == NumberType.Four) if (WheelsNumb == NumberType.Four)
DrawWheel(CurX + Width / 10 * 3, CurY + Height / 10 * 7); DrawWheel(g2d,CurX + Width / 10 * 3, CurY + Height / 10 * 7);
} }
} }

View File

@ -2,11 +2,13 @@ package MonorailHard.DrawningObjects;
import MonorailHard.NumberType; import MonorailHard.NumberType;
import java.awt.*;
public interface IDraw { public interface IDraw {
public void ChangeWheelsNumb(int x); public void ChangeWheelsNumb(int x);
public NumberType WheelsNumb(); public NumberType WheelsNumb();
public void DrawWheels(); public void DrawWheels(Graphics2D g2d);
public void DrawWheel(int x, int y); public void DrawWheel(Graphics2D g2d, int x, int y);
public void ChangeX(int x); public void ChangeX(int x);
public void ChangeY(int y); public void ChangeY(int y);
} }

View File

@ -14,157 +14,7 @@ import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
public class Main { public class Main {
static DrawningMonorail DrawningMonorail;
static AbstractStrategy _abstractStrategy;
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
String[] items = {"Довести до центра", "Довести до края"}; FormMonorail form = new FormMonorail();
JComboBox comboBoxStrategy = new JComboBox(items);
comboBoxStrategy.setBounds(562,12,151,28);
JFrame MonorailFrame = new JFrame();
MonorailFrame.setResizable(false);
JPanel MonorailPanel = new JPanel();
MonorailFrame.setLayout(new BorderLayout());
MonorailFrame.setSize(743, 576);
MonorailFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MonorailFrame.setLayout(new BorderLayout(1,1));
MonorailPanel.setLayout(null);
BufferedImage RightIcon = ImageIO.read(new File("RightButton.png"));
BufferedImage LeftIcon = ImageIO.read(new File("LeftButton.png"));
BufferedImage UpIcon = ImageIO.read(new File("UpButton.png"));
BufferedImage DownIcon = ImageIO.read(new File("DownButton.png"));
JButton RightButton = new JButton(new ImageIcon(RightIcon));
JButton LeftButton = new JButton(new ImageIcon(LeftIcon));
JButton UpButton = new JButton(new ImageIcon(UpIcon));
JButton DownButton = new JButton(new ImageIcon(DownIcon));
JButton CreateButton = new JButton();
JButton CreateLocomotiveButton = new JButton();
JButton buttonStep = new JButton();
CreateLocomotiveButton.setBounds(198,477,180, 40);
CreateLocomotiveButton.setText("Создать локомотив");
CreateButton.setText("Создать");
buttonStep.setBounds(619, 46, 94, 29);
buttonStep.setText("шаг");
CreateButton.setBounds(12, 477, 180, 40);
RightButton.setBounds(683,487,30,30);
LeftButton.setBounds(611,487,30,30);
UpButton.setBounds(647,451,30,30);
DownButton.setBounds(647,487,30,30);
MonorailPanel.add(CreateButton);
MonorailPanel.add(CreateLocomotiveButton);
MonorailPanel.add(RightButton);
MonorailPanel.add(LeftButton);
MonorailPanel.add(UpButton);
MonorailPanel.add(DownButton);
MonorailPanel.add(comboBoxStrategy);
MonorailPanel.add(buttonStep);
comboBoxStrategy.setSelectedIndex(-1);
MonorailFrame.add(MonorailPanel, BorderLayout.CENTER);
Random random = new Random();
CreateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DrawningMonorail = new DrawningMonorail(random.nextInt(100, 300), random.nextDouble(1000, 3000),
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
MonorailPanel.getWidth(), MonorailPanel.getHeight(), MonorailPanel);
DrawningMonorail.DrawMonorail();
comboBoxStrategy.enable(true);
}
});
CreateLocomotiveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DrawningMonorail = new DrawningLocomotive(random.nextInt(100, 300), random.nextDouble(1000, 3000),
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
random.nextInt(1, 6),
MonorailPanel.getWidth(), MonorailPanel.getHeight(), random.nextBoolean(), random.nextBoolean(),
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
MonorailPanel);
DrawningMonorail.DrawMonorail();
comboBoxStrategy.enable(true);
}
});
buttonStep.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningMonorail == null)
return;
if(comboBoxStrategy.isEnabled()){
if(comboBoxStrategy.getSelectedIndex() == 0)
_abstractStrategy = new MoveToCenter();
else if(comboBoxStrategy.getSelectedIndex() == 1)
_abstractStrategy = new MoveToBorder();
else
_abstractStrategy = null;
if(_abstractStrategy == null)
return;
_abstractStrategy.SetData(new DrawningObjectMonorail(DrawningMonorail), MonorailPanel.getWidth(),
MonorailPanel.getHeight());
comboBoxStrategy.enable(false);
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
DrawningMonorail.DrawMonorail();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.enable(true);
_abstractStrategy = null;
}
}
});
RightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningMonorail.EntityMonorail() == null) {
return;
}
DrawningMonorail.MoveTransport(DirectionType.Right);
DrawningMonorail.DrawMonorail();
}
});
LeftButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningMonorail.EntityMonorail() == null)
return;
DrawningMonorail.MoveTransport(DirectionType.Left);
DrawningMonorail.DrawMonorail();
}
});
UpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningMonorail.EntityMonorail() == null)
return;
DrawningMonorail.MoveTransport(DirectionType.Up);
DrawningMonorail.DrawMonorail();
}
});
DownButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningMonorail.EntityMonorail() == null)
return;
DrawningMonorail.MoveTransport(DirectionType.Down);
DrawningMonorail.DrawMonorail();
}
});
MonorailFrame.setVisible(true);
} }
} }