Compare commits
No commits in common. "lab1" and "main" have entirely different histories.
@ -3,7 +3,6 @@
|
|||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/Resources" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 415 B |
Binary file not shown.
Before Width: | Height: | Size: 411 B |
Binary file not shown.
Before Width: | Height: | Size: 352 B |
Binary file not shown.
Before Width: | Height: | Size: 412 B |
6
src/Main.java
Normal file
6
src/Main.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,11 +0,0 @@
|
|||||||
package projectMonorail;
|
|
||||||
|
|
||||||
public enum DirectionType {
|
|
||||||
Up,
|
|
||||||
|
|
||||||
Down,
|
|
||||||
|
|
||||||
Left,
|
|
||||||
|
|
||||||
Right
|
|
||||||
}
|
|
@ -1,230 +0,0 @@
|
|||||||
package projectMonorail;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingMonorail {
|
|
||||||
|
|
||||||
private EntityMonorail entityMonorail;
|
|
||||||
|
|
||||||
public EntityMonorail getEntityMonorail() {
|
|
||||||
return entityMonorail;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DrawingWheels drawingWheels;
|
|
||||||
|
|
||||||
private int pictureWidth;
|
|
||||||
|
|
||||||
private int pictureHeight;
|
|
||||||
|
|
||||||
private int startPosX;
|
|
||||||
|
|
||||||
private int startPosY;
|
|
||||||
|
|
||||||
private int monorailWidth = 117;
|
|
||||||
|
|
||||||
private int monorailHeight = 56;
|
|
||||||
|
|
||||||
public boolean Init(int speed, double weight, Color mainColor, Color additionalColor, boolean magneticRail,
|
|
||||||
boolean extraCabin, int width, int height, int wheelNumber) {
|
|
||||||
if (extraCabin) {
|
|
||||||
monorailWidth = 183;
|
|
||||||
}
|
|
||||||
if (magneticRail) {
|
|
||||||
monorailWidth = 186;
|
|
||||||
monorailHeight = 92;
|
|
||||||
}
|
|
||||||
if (width < monorailWidth || height < monorailHeight) { return false; }
|
|
||||||
pictureWidth = width;
|
|
||||||
pictureHeight = height;
|
|
||||||
entityMonorail = new EntityMonorail();
|
|
||||||
entityMonorail.Init(speed, weight, mainColor, additionalColor,
|
|
||||||
magneticRail, extraCabin);
|
|
||||||
drawingWheels = new DrawingWheels();
|
|
||||||
drawingWheels.setWheelNumber(wheelNumber);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetPosition(int x, int y) {
|
|
||||||
if (x < 0 || x + monorailWidth > pictureWidth) { x = 0; }
|
|
||||||
if (y < 0 || y + monorailHeight > pictureHeight) { y = 0; }
|
|
||||||
|
|
||||||
startPosX = x;
|
|
||||||
startPosY = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MoveTransport(DirectionType direction) {
|
|
||||||
if (entityMonorail == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (direction) {
|
|
||||||
//влево
|
|
||||||
case Left:
|
|
||||||
if (startPosX - entityMonorail.getStep() > 0)
|
|
||||||
{
|
|
||||||
startPosX -= (int)entityMonorail.getStep();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вверх
|
|
||||||
case Up:
|
|
||||||
if (startPosY - entityMonorail.getStep() > 0)
|
|
||||||
{
|
|
||||||
startPosY -= (int)entityMonorail.getStep();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вправо
|
|
||||||
case Right:
|
|
||||||
if (startPosX + monorailWidth + entityMonorail.getStep() < pictureWidth)
|
|
||||||
{
|
|
||||||
startPosX += (int)entityMonorail.getStep();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вниз
|
|
||||||
case Down:
|
|
||||||
if (startPosY + monorailHeight + entityMonorail.getStep() < pictureHeight)
|
|
||||||
{
|
|
||||||
startPosY += (int)entityMonorail.getStep();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawTransport(Graphics2D g2d)
|
|
||||||
{
|
|
||||||
if (entityMonorail == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color mainColor = entityMonorail.getMainColor();
|
|
||||||
Color additionalColor = entityMonorail.getAdditionalColor();
|
|
||||||
BasicStroke standardWidth = new BasicStroke(1);
|
|
||||||
BasicStroke largerWidth = new BasicStroke(2);
|
|
||||||
|
|
||||||
//надстройка
|
|
||||||
g2d.setStroke(largerWidth);
|
|
||||||
g2d.setColor(mainColor);
|
|
||||||
g2d.fillRect( startPosX + 55, startPosY , 25, 15);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect(startPosX + 55, startPosY , 25, 15);
|
|
||||||
|
|
||||||
//корпус локомотива
|
|
||||||
Polygon locoPolygon = new Polygon();
|
|
||||||
locoPolygon.addPoint(startPosX + 29, startPosY + 15);
|
|
||||||
locoPolygon.addPoint(startPosX + 112, startPosY + 15);
|
|
||||||
locoPolygon.addPoint(startPosX + 112, startPosY + 46);
|
|
||||||
locoPolygon.addPoint(startPosX + 25, startPosY + 46);
|
|
||||||
locoPolygon.addPoint(startPosX + 25, startPosY + 31);
|
|
||||||
|
|
||||||
g2d.setColor(mainColor);
|
|
||||||
g2d.fillPolygon(locoPolygon);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawPolygon(locoPolygon);
|
|
||||||
|
|
||||||
g2d.setStroke(standardWidth);
|
|
||||||
g2d.setColor(Color.BLUE);
|
|
||||||
g2d.drawLine( startPosX + 25, startPosY + 31, startPosX + 112, startPosY + 31);
|
|
||||||
|
|
||||||
//дверь локомотива
|
|
||||||
g2d.setColor(Color.GRAY);
|
|
||||||
g2d.fillRect( startPosX + 54, startPosY + 21, 7, 20);
|
|
||||||
|
|
||||||
g2d.setStroke(largerWidth);
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect(startPosX + 54, startPosY + 21, 7, 20);
|
|
||||||
|
|
||||||
//окна локомотива
|
|
||||||
g2d.setColor(Color.BLUE);
|
|
||||||
|
|
||||||
g2d.fillRect( startPosX + 32, startPosY + 18, 6, 9);
|
|
||||||
g2d.fillRect( startPosX + 44, startPosY + 18, 6, 9);
|
|
||||||
g2d.fillRect( startPosX + 103, startPosY + 18, 6, 9);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
|
|
||||||
g2d.drawRect( startPosX + 32, startPosY + 18, 6, 9);
|
|
||||||
g2d.drawRect( startPosX + 44, startPosY + 18, 6, 9);
|
|
||||||
g2d.drawRect( startPosX + 103, startPosY + 18, 6, 9);
|
|
||||||
|
|
||||||
//колеса и тележка локомотива
|
|
||||||
g2d.fillRect( startPosX + 23, startPosY + 47, 33, 6);
|
|
||||||
g2d.fillRect( startPosX + 76, startPosY + 47, 30, 6);
|
|
||||||
g2d.drawRect( startPosX + 23, startPosY + 47, 33, 6);
|
|
||||||
g2d.drawRect( startPosX + 76, startPosY + 47, 30, 6);
|
|
||||||
|
|
||||||
drawingWheels.drawWheels(g2d, Color.WHITE, startPosX, startPosY);
|
|
||||||
|
|
||||||
Polygon bogiePolygon = new Polygon();
|
|
||||||
bogiePolygon.addPoint(startPosX + 26, startPosY + 46);
|
|
||||||
bogiePolygon.addPoint(startPosX + 24, startPosY + 54);
|
|
||||||
bogiePolygon.addPoint(startPosX + 12, startPosY + 54);
|
|
||||||
bogiePolygon.addPoint(startPosX + 8, startPosY + 51);
|
|
||||||
bogiePolygon.addPoint(startPosX + 12, startPosY + 48);
|
|
||||||
bogiePolygon.addPoint(startPosX + 18, startPosY + 46);
|
|
||||||
|
|
||||||
g2d.fillPolygon(bogiePolygon);
|
|
||||||
|
|
||||||
//соединение между кабинами
|
|
||||||
g2d.drawRect( startPosX + 112, startPosY + 18, 5, 28);
|
|
||||||
g2d.fillRect( startPosX + 112, startPosY + 18, 5, 28);
|
|
||||||
|
|
||||||
//магнитная рельса
|
|
||||||
if (entityMonorail.getMagneticRail()) {
|
|
||||||
g2d.drawRect( startPosX + 2, startPosY + 58, 184, 18);
|
|
||||||
g2d.setColor(Color.GRAY);
|
|
||||||
g2d.fillRect( startPosX + 2, startPosY + 58, 184, 18);
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect( startPosX + 35 + 35 * i, startPosY + 77, 8, 15);
|
|
||||||
g2d.setColor(Color.GRAY);
|
|
||||||
g2d.fillRect( startPosX + 35 + 35 * i, startPosY + 77, 8, 15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//дополнительная кабина
|
|
||||||
if (entityMonorail.getExtraCabin()) {
|
|
||||||
//корпус дополнительной кабины
|
|
||||||
g2d.setColor(mainColor);
|
|
||||||
g2d.fillRect( startPosX + 118, startPosY + 15, 65, 31);
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect( startPosX + 118, startPosY + 15, 65, 31);
|
|
||||||
|
|
||||||
g2d.setStroke(standardWidth);
|
|
||||||
g2d.setColor(Color.BLUE);
|
|
||||||
g2d.drawLine( startPosX + 118, startPosY + 31, startPosX + 183, startPosY + 31);
|
|
||||||
|
|
||||||
//дверь дополнительной кабины
|
|
||||||
g2d.setColor(additionalColor);
|
|
||||||
g2d.fillRect( startPosX + 146, startPosY + 21, 7, 20);
|
|
||||||
|
|
||||||
g2d.setStroke(largerWidth);
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect(startPosX + 146, startPosY + 21, 7, 20);
|
|
||||||
|
|
||||||
//окна дополнительной кабины
|
|
||||||
g2d.setColor(Color.BLUE);
|
|
||||||
g2d.fillRect( startPosX + 130, startPosY + 18, 6, 9);
|
|
||||||
g2d.fillRect( startPosX + 169, startPosY + 18, 6, 9);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawRect( startPosX + 130, startPosY + 18, 6, 9);
|
|
||||||
g2d.drawRect( startPosX + 169, startPosY + 18, 6, 9);
|
|
||||||
|
|
||||||
//колеса и тележка дополнительной кабины
|
|
||||||
g2d.fillRect( startPosX + 126, startPosY + 47, 15, 6);
|
|
||||||
g2d.fillRect( startPosX + 159, startPosY + 47, 15, 6);
|
|
||||||
g2d.drawRect( startPosX + 126, startPosY + 47, 15, 6);
|
|
||||||
g2d.drawRect( startPosX + 159, startPosY + 47, 15, 6);
|
|
||||||
|
|
||||||
g2d.setColor(Color.WHITE);
|
|
||||||
g2d.fillOval( startPosX + 128, startPosY + 47, 10, 9);
|
|
||||||
g2d.fillOval( startPosX + 161, startPosY + 47, 10, 9);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawOval( startPosX + 128, startPosY + 47, 10, 9);
|
|
||||||
g2d.drawOval( startPosX + 161, startPosY + 47, 10, 9);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
package projectMonorail;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingWheels {
|
|
||||||
|
|
||||||
private WheelNumber wheelNumber;
|
|
||||||
|
|
||||||
public void setWheelNumber(int number) {
|
|
||||||
switch (number) {
|
|
||||||
case 2:
|
|
||||||
wheelNumber = wheelNumber.Two;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
wheelNumber = wheelNumber.Three;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
wheelNumber = wheelNumber.Four;
|
|
||||||
break;
|
|
||||||
default: wheelNumber = wheelNumber.Two;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawWheels(Graphics2D g2d, Color color, int startPosX, int startPosY) {
|
|
||||||
switch (wheelNumber) {
|
|
||||||
case Two:
|
|
||||||
drawTwoWheels(g2d, color, startPosX, startPosY);
|
|
||||||
break;
|
|
||||||
case Three:
|
|
||||||
drawThreeWheels(g2d, color, startPosX, startPosY);
|
|
||||||
break;
|
|
||||||
case Four:
|
|
||||||
drawFourWheels(g2d, color, startPosX, startPosY);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void drawTwoWheels(Graphics2D g2d, Color color, int startPosX, int startPosY) {
|
|
||||||
g2d.setColor(color);
|
|
||||||
|
|
||||||
g2d.fillOval( startPosX + 25, startPosY + 47, 10, 9);
|
|
||||||
g2d.fillOval( startPosX + 45, startPosY + 47, 10, 9);
|
|
||||||
g2d.fillOval( startPosX + 75, startPosY + 47, 10, 9);
|
|
||||||
g2d.fillOval( startPosX + 95, startPosY + 47, 10, 9);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
|
|
||||||
g2d.drawOval( startPosX + 25, startPosY + 47, 10, 9);
|
|
||||||
g2d.drawOval( startPosX + 45, startPosY + 47, 10, 9);
|
|
||||||
g2d.drawOval( startPosX + 75, startPosY + 47, 10, 9);
|
|
||||||
g2d.drawOval( startPosX + 95, startPosY + 47, 10, 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void drawThreeWheels(Graphics2D g2d, Color color, int startPosX, int startPosY) {
|
|
||||||
g2d.setColor(color);
|
|
||||||
|
|
||||||
g2d.fillOval( startPosX + 25, startPosY + 47, 8, 9);
|
|
||||||
g2d.fillOval( startPosX + 36, startPosY + 47, 8, 9);
|
|
||||||
g2d.fillOval( startPosX + 47, startPosY + 47, 8, 9);
|
|
||||||
g2d.fillOval( startPosX + 76, startPosY + 47, 8, 9);
|
|
||||||
g2d.fillOval( startPosX + 87, startPosY + 47, 8, 9);
|
|
||||||
g2d.fillOval( startPosX + 98, startPosY + 47, 8, 9);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
|
|
||||||
g2d.drawOval( startPosX + 25, startPosY + 47, 8, 9);
|
|
||||||
g2d.drawOval( startPosX + 36, startPosY + 47, 8, 9);
|
|
||||||
g2d.drawOval( startPosX + 47, startPosY + 47, 8, 9);
|
|
||||||
g2d.drawOval( startPosX + 76, startPosY + 47, 8, 9);
|
|
||||||
g2d.drawOval( startPosX + 87, startPosY + 47, 8, 9);
|
|
||||||
g2d.drawOval( startPosX + 98, startPosY + 47, 8, 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void drawFourWheels(Graphics2D g2d, Color color, int startPosX, int startPosY) {
|
|
||||||
g2d.setColor(color);
|
|
||||||
|
|
||||||
g2d.fillOval( startPosX + 25, startPosY + 47, 6, 9);
|
|
||||||
g2d.fillOval( startPosX + 33, startPosY + 47, 6, 9);
|
|
||||||
g2d.fillOval( startPosX + 41, startPosY + 47, 6, 9);
|
|
||||||
g2d.fillOval( startPosX + 49, startPosY + 47, 6, 9);
|
|
||||||
g2d.fillOval( startPosX + 75, startPosY + 47, 6, 9);
|
|
||||||
g2d.fillOval( startPosX + 83, startPosY + 47, 6, 9);
|
|
||||||
g2d.fillOval( startPosX + 91, startPosY + 47, 6, 9);
|
|
||||||
g2d.fillOval( startPosX + 99, startPosY + 47, 6, 9);
|
|
||||||
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
|
|
||||||
g2d.drawOval( startPosX + 25, startPosY + 47, 6, 9);
|
|
||||||
g2d.drawOval( startPosX + 33, startPosY + 47, 6, 9);
|
|
||||||
g2d.drawOval( startPosX + 41, startPosY + 47, 6, 9);
|
|
||||||
g2d.drawOval( startPosX + 49, startPosY + 47, 6, 9);
|
|
||||||
g2d.drawOval( startPosX + 76, startPosY + 47, 6, 9);
|
|
||||||
g2d.drawOval( startPosX + 84, startPosY + 47, 6, 9);
|
|
||||||
g2d.drawOval( startPosX + 92, startPosY + 47, 6, 9);
|
|
||||||
g2d.drawOval( startPosX + 100, startPosY + 47, 6, 9);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
package projectMonorail;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class EntityMonorail {
|
|
||||||
|
|
||||||
private int speed;
|
|
||||||
|
|
||||||
public int getSpeed() {
|
|
||||||
return speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
private double weight;
|
|
||||||
|
|
||||||
public double getWeight() {
|
|
||||||
return weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Color mainColor;
|
|
||||||
|
|
||||||
public Color getMainColor() {
|
|
||||||
return mainColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Color additionalColor;
|
|
||||||
|
|
||||||
public Color getAdditionalColor() {
|
|
||||||
return additionalColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean magneticRail;
|
|
||||||
|
|
||||||
public boolean getMagneticRail() {
|
|
||||||
return magneticRail;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean extraCabin;
|
|
||||||
|
|
||||||
public boolean getExtraCabin() {
|
|
||||||
return extraCabin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getStep() {
|
|
||||||
return (double)speed * 100 / weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color mainColor , Color additionalColor , boolean magneticRail, boolean extraCabin) {
|
|
||||||
this.speed = speed;
|
|
||||||
this.weight = weight;
|
|
||||||
this.mainColor = mainColor;
|
|
||||||
this.additionalColor = additionalColor;
|
|
||||||
this.magneticRail = magneticRail;
|
|
||||||
this.extraCabin = extraCabin;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package projectMonorail;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
public class FrameMonorail extends JFrame {
|
|
||||||
|
|
||||||
private PictureBox pictureBox;
|
|
||||||
|
|
||||||
public FrameMonorail() {
|
|
||||||
super("Monorail");
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
|
|
||||||
pictureBox = new PictureBox();
|
|
||||||
add(pictureBox);
|
|
||||||
|
|
||||||
pack();
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package projectMonorail;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
FrameMonorail frameMonorail = new FrameMonorail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,170 +0,0 @@
|
|||||||
package projectMonorail;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class PictureBox extends JPanel {
|
|
||||||
|
|
||||||
private DrawingMonorail drawingMonorail;
|
|
||||||
|
|
||||||
private JButton buttonLeft;
|
|
||||||
|
|
||||||
private JButton buttonUp;
|
|
||||||
|
|
||||||
private JButton buttonRight;
|
|
||||||
|
|
||||||
private JButton buttonDown;
|
|
||||||
|
|
||||||
private JButton buttonCreateMonorail;
|
|
||||||
|
|
||||||
private JPanel buttonsPanel;
|
|
||||||
|
|
||||||
private JPanel buttonsMovePanel;
|
|
||||||
|
|
||||||
private JPanel paddingPanel;
|
|
||||||
|
|
||||||
public PictureBox() {
|
|
||||||
setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
buttonsPanel = new JPanel();
|
|
||||||
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
|
|
||||||
buttonsPanel.setOpaque(false);
|
|
||||||
|
|
||||||
buttonCreateMonorail = new JButton("Create");
|
|
||||||
buttonCreateMonorail.setFocusable(false);
|
|
||||||
buttonCreateMonorail.setFont(new Font("Segoe UI", Font.PLAIN, 12));
|
|
||||||
buttonCreateMonorail.setBackground(Color.LIGHT_GRAY);
|
|
||||||
buttonCreateMonorail.setPreferredSize(new Dimension(75, 23));
|
|
||||||
|
|
||||||
buttonCreateMonorail.addActionListener (e -> {
|
|
||||||
Random random = new Random();
|
|
||||||
drawingMonorail = new DrawingMonorail();
|
|
||||||
drawingMonorail.Init(random.nextInt(200, 300),
|
|
||||||
random.nextInt(1000, 3000),
|
|
||||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256),
|
|
||||||
random.nextInt(0, 256)),
|
|
||||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256),
|
|
||||||
random.nextInt(0, 256)),
|
|
||||||
random.nextBoolean(), random.nextBoolean(), this.getWidth(), this.getHeight(), random.nextInt(2, 5));
|
|
||||||
drawingMonorail.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
ActionListener buttonMoveListener = e -> {
|
|
||||||
if (drawingMonorail == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String buttonName = ((JButton) e.getSource()).getName();
|
|
||||||
|
|
||||||
switch (buttonName) {
|
|
||||||
case ("buttonUp"):
|
|
||||||
drawingMonorail.MoveTransport(DirectionType.Up);
|
|
||||||
break;
|
|
||||||
case ("buttonDown"):
|
|
||||||
drawingMonorail.MoveTransport(DirectionType.Down);
|
|
||||||
break;
|
|
||||||
case ("buttonLeft"):
|
|
||||||
drawingMonorail.MoveTransport(DirectionType.Left);
|
|
||||||
break;
|
|
||||||
case ("buttonRight"):
|
|
||||||
drawingMonorail.MoveTransport(DirectionType.Right);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
repaint();
|
|
||||||
};
|
|
||||||
|
|
||||||
buttonLeft = new JButton();
|
|
||||||
buttonLeft.setName("buttonLeft");
|
|
||||||
buttonLeft.setFocusable(false);
|
|
||||||
buttonLeft.setPreferredSize(new Dimension(30, 30));
|
|
||||||
buttonLeft.setIcon(new ImageIcon("Resources/arrowLeft.png"));
|
|
||||||
buttonLeft.addActionListener(buttonMoveListener);
|
|
||||||
|
|
||||||
buttonRight = new JButton();
|
|
||||||
buttonRight.setName("buttonRight");
|
|
||||||
buttonRight.setFocusable(false);
|
|
||||||
buttonRight.setPreferredSize(new Dimension(30, 30));
|
|
||||||
buttonRight.setIcon(new ImageIcon("Resources/arrowRight.png"));
|
|
||||||
buttonRight.addActionListener(buttonMoveListener);
|
|
||||||
|
|
||||||
buttonDown = new JButton();
|
|
||||||
buttonDown.setName("buttonDown");
|
|
||||||
buttonDown.setFocusable(false);
|
|
||||||
buttonDown.setPreferredSize(new Dimension(30, 30));
|
|
||||||
buttonDown.setIcon(new ImageIcon("Resources/arrowDown.png"));
|
|
||||||
buttonDown.addActionListener(buttonMoveListener);
|
|
||||||
|
|
||||||
buttonUp = new JButton();
|
|
||||||
buttonUp.setName("buttonUp");
|
|
||||||
buttonUp.setFocusable(false);
|
|
||||||
buttonUp.setPreferredSize(new Dimension(30, 30));
|
|
||||||
buttonUp.setIcon(new ImageIcon("Resources/arrowUp.png"));
|
|
||||||
buttonUp.addActionListener(buttonMoveListener);
|
|
||||||
|
|
||||||
buttonsMovePanel = new JPanel();
|
|
||||||
buttonsMovePanel.setLayout(new GridBagLayout());
|
|
||||||
buttonsMovePanel.setOpaque(false);
|
|
||||||
|
|
||||||
GridBagConstraints constrains = new GridBagConstraints();
|
|
||||||
constrains.insets = new Insets(5,5,5,5);
|
|
||||||
constrains.gridx = 0;
|
|
||||||
constrains.gridy = 0;
|
|
||||||
|
|
||||||
buttonsMovePanel.add(Box.createHorizontalStrut(30), constrains);
|
|
||||||
|
|
||||||
constrains.gridx = 1;
|
|
||||||
constrains.gridy = 0;
|
|
||||||
|
|
||||||
buttonsMovePanel.add(buttonUp, constrains);
|
|
||||||
|
|
||||||
constrains.gridx = 2;
|
|
||||||
constrains.gridy = 0;
|
|
||||||
|
|
||||||
buttonsMovePanel.add(Box.createHorizontalStrut(30), constrains);
|
|
||||||
|
|
||||||
constrains.gridx = 0;
|
|
||||||
constrains.gridy = 1;
|
|
||||||
|
|
||||||
buttonsMovePanel.add(buttonLeft, constrains);
|
|
||||||
|
|
||||||
constrains.gridx = 1;
|
|
||||||
constrains.gridy = 1;
|
|
||||||
|
|
||||||
buttonsMovePanel.add(buttonDown, constrains);
|
|
||||||
|
|
||||||
constrains.gridx = 2;
|
|
||||||
constrains.gridy = 1;
|
|
||||||
|
|
||||||
buttonsMovePanel.add(buttonRight, constrains);
|
|
||||||
|
|
||||||
paddingPanel = new JPanel();
|
|
||||||
paddingPanel.setLayout(new BoxLayout(paddingPanel, BoxLayout.Y_AXIS));
|
|
||||||
paddingPanel.setOpaque(false);
|
|
||||||
|
|
||||||
paddingPanel.add(buttonsMovePanel);
|
|
||||||
paddingPanel.add(Box.createVerticalStrut(15));
|
|
||||||
|
|
||||||
buttonsPanel.add(Box.createHorizontalStrut(20));
|
|
||||||
buttonsPanel.add(buttonCreateMonorail);
|
|
||||||
buttonsPanel.add(Box.createHorizontalStrut(650));
|
|
||||||
buttonsPanel.add(paddingPanel);
|
|
||||||
|
|
||||||
add(buttonsPanel, BorderLayout.SOUTH);
|
|
||||||
setPreferredSize(new Dimension(900, 500));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void paintComponent(Graphics g) {
|
|
||||||
if (drawingMonorail == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
super.paintComponent(g);
|
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
|
||||||
drawingMonorail.DrawTransport(g2d);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package projectMonorail;
|
|
||||||
|
|
||||||
public enum WheelNumber {
|
|
||||||
Two,
|
|
||||||
|
|
||||||
Three,
|
|
||||||
|
|
||||||
Four
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user