PIbd-12 Ulybin A.A. Monorail Hard Lab01 #1
10
ProjectMonorail/.idea/libraries/lib.xml
generated
10
ProjectMonorail/.idea/libraries/lib.xml
generated
@ -1,10 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib">
|
||||
<CLASSES>
|
||||
<root url="file://$JAVAFX_PATH$" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$JAVAFX_PATH$" recursive="false" />
|
||||
</library>
|
||||
</component>
|
5
ProjectMonorail/.idea/misc.xml
generated
5
ProjectMonorail/.idea/misc.xml
generated
@ -1,5 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<writeAnnotations>
|
||||
<writeAnnotation name="javafx.fxml.FXML" />
|
||||
</writeAnnotations>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
|
124
ProjectMonorail/.idea/uiDesigner.xml
generated
Normal file
124
ProjectMonorail/.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
@ -7,6 +7,5 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="lib" level="project" />
|
||||
</component>
|
||||
</module>
|
6
ProjectMonorail/src/DirectionType.java
Normal file
6
ProjectMonorail/src/DirectionType.java
Normal file
@ -0,0 +1,6 @@
|
||||
public enum DirectionType {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
192
ProjectMonorail/src/DrawingMonorail.java
Normal file
192
ProjectMonorail/src/DrawingMonorail.java
Normal file
@ -0,0 +1,192 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingMonorail {
|
||||
private EntityMonorail entityMonorail;
|
||||
public EntityMonorail getEntityMonorail(){return entityMonorail;}
|
||||
private DrawingMonorailWheels drawingMonorailWheels;
|
||||
|
||||
private Integer _pictureWidth;
|
||||
|
||||
private Integer _pictureHeight;
|
||||
|
||||
private Integer _startPosX;
|
||||
|
||||
private Integer _startPosY;
|
||||
|
||||
private final int _drawingTrainWidth = 150;
|
||||
|
||||
private final int _drawingTrainHeight = 40;
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean rail, boolean secondCarriage){
|
||||
entityMonorail = new EntityMonorail();
|
||||
entityMonorail.Init(speed, weight, bodyColor, additionalColor, rail, secondCarriage);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
drawingMonorailWheels = new DrawingMonorailWheels();
|
||||
Random rand = new Random();
|
||||
int wheelsCount = rand.nextInt(2, 5);
|
||||
drawingMonorailWheels.setEnumNumber(wheelsCount);
|
||||
}
|
||||
|
||||
public boolean SetPictureSize(int width, int height){
|
||||
if (_drawingTrainWidth <= width && _drawingTrainHeight <= height){
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX != null && _startPosY != null){
|
||||
if (_startPosX + _drawingTrainWidth > _pictureWidth) {
|
||||
_startPosX = _pictureWidth - _drawingTrainWidth;
|
||||
}
|
||||
if (_startPosY + _drawingTrainHeight > _pictureHeight) {
|
||||
_startPosY = _pictureHeight - _drawingTrainHeight;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (_pictureHeight == null || _pictureWidth == null) {
|
||||
return;
|
||||
}
|
||||
if (x + _drawingTrainWidth > _pictureWidth || x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
if (y + _drawingTrainHeight > _pictureHeight || y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public boolean MoveTransport(DirectionType direction){
|
||||
if (entityMonorail == null || _startPosX == null || _startPosY == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction){
|
||||
case Up:
|
||||
if (_startPosY - entityMonorail.Step() > 0){
|
||||
_startPosY -= (int) entityMonorail.Step();
|
||||
}
|
||||
return true;
|
||||
case Down:
|
||||
if (_startPosY + entityMonorail.Step() + _drawingTrainHeight < _pictureHeight){
|
||||
_startPosY += (int) entityMonorail.Step();
|
||||
}
|
||||
return true;
|
||||
case Left:
|
||||
if (_startPosX - entityMonorail.Step() > 0){
|
||||
_startPosX -= (int) entityMonorail.Step();
|
||||
}
|
||||
return true;
|
||||
case Right:
|
||||
if (_startPosX + entityMonorail.Step() + _drawingTrainWidth < _pictureWidth){
|
||||
_startPosX += (int) entityMonorail.Step();
|
||||
}
|
||||
return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawMonorail(Graphics g) {
|
||||
if (entityMonorail == null || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawingMonorailWheels.drawMonorailWheels(g, entityMonorail.getAdditionalColor(), _startPosX, _startPosY);
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
Point[] monorailBorders = new Point[] {
|
||||
new Point(_startPosX + 10, _startPosY),
|
||||
new Point(_startPosX + 85, _startPosY),
|
||||
new Point(_startPosX + 85, _startPosY + 30),
|
||||
new Point(_startPosX + 5, _startPosY + 30),
|
||||
new Point(_startPosX + 5, _startPosY + 15)
|
||||
};
|
||||
|
||||
Polygon monorailPolygon = new Polygon();
|
||||
for (Point point : monorailBorders)
|
||||
monorailPolygon.addPoint(point.x, point.y);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.draw(monorailPolygon);
|
||||
g2d.setColor(entityMonorail.getBodyColor());
|
||||
g2d.fill(monorailPolygon);
|
||||
|
||||
Point[][] carts = new Point[][] {
|
||||
{new Point(_startPosX, _startPosY + 35),
|
||||
new Point(_startPosX + 15, _startPosY + 35),
|
||||
new Point(_startPosX + 15, _startPosY + 30),
|
||||
new Point(_startPosX + 5, _startPosY + 30)},
|
||||
{new Point(_startPosX + 20, _startPosY + 30),
|
||||
new Point(_startPosX + 25, _startPosY + 35),
|
||||
new Point(_startPosX + 30, _startPosY + 35),
|
||||
new Point(_startPosX + 35, _startPosY + 30)},
|
||||
{new Point(_startPosX + 55, _startPosY + 30),
|
||||
new Point(_startPosX + 60, _startPosY + 35),
|
||||
new Point(_startPosX + 65, _startPosY + 35),
|
||||
new Point(_startPosX + 70, _startPosY + 30)},
|
||||
{new Point(_startPosX + 70, _startPosY + 30),
|
||||
new Point(_startPosX + 75, _startPosY + 35),
|
||||
new Point(_startPosX + 90, _startPosY + 35),
|
||||
new Point(_startPosX + 85, _startPosY + 30)}
|
||||
};
|
||||
|
||||
|
||||
g2d.setColor(Color.BLACK);
|
||||
for (int i = 0; i < 4; i++){
|
||||
Polygon cartPolygon = new Polygon();
|
||||
for (Point point : carts[i])
|
||||
cartPolygon.addPoint(point.x, point.y);
|
||||
g2d.fill(cartPolygon);
|
||||
}
|
||||
|
||||
g2d.drawRect(_startPosX + 17, _startPosY + 5, 17, 7);
|
||||
g2d.drawRect(_startPosX + 55, _startPosY + 5, 27, 7);
|
||||
g2d.drawRect(_startPosX + 40, _startPosY + 7, 10, 21);
|
||||
|
||||
g2d.setColor(Color.CYAN);
|
||||
g2d.fillRect(_startPosX + 18, _startPosY + 6, 16, 6);
|
||||
g2d.fillRect(_startPosX + 56, _startPosY + 6, 26, 6);
|
||||
g2d.setColor(Color.WHITE);
|
||||
g2d.fillRect(_startPosX + 41, _startPosY + 8, 9, 20);
|
||||
|
||||
|
||||
if (entityMonorail.getRail()) {
|
||||
g2d.setColor(entityMonorail.getAdditionalColor());
|
||||
if (entityMonorail.getSecondCarriage()){
|
||||
g2d.fillRect(_startPosX, _startPosY + 40, 150, 3);
|
||||
}
|
||||
else{
|
||||
g2d.fillRect(_startPosX, _startPosY + 40, 90, 3);
|
||||
}
|
||||
}
|
||||
if (entityMonorail.getSecondCarriage()) {
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(_startPosX + 95, _startPosY, 55, 30);
|
||||
g2d.setColor(entityMonorail.getAdditionalColor());
|
||||
g2d.fillRect(_startPosX + 96, _startPosY + 1, 54, 29);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.fillRect(_startPosX + 85, _startPosY + 5, 10, 23);
|
||||
g2d.drawRect(_startPosX + 105, _startPosY + 5, 35, 10);
|
||||
g2d.setColor(Color.CYAN);
|
||||
g2d.fillRect(_startPosX + 106, _startPosY + 6, 34, 9);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(_startPosX + 105, _startPosY + 5, 10, 23);
|
||||
g2d.setColor(Color.WHITE);
|
||||
g2d.fillRect(_startPosX + 106, _startPosY + 16, 9, 12);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(_startPosX + 100, _startPosY + 30, 10, 10);
|
||||
g2d.drawOval(_startPosX + 110, _startPosY + 30, 10, 10);
|
||||
g2d.drawOval(_startPosX + 130, _startPosY + 30, 10, 10);
|
||||
g2d.drawOval(_startPosX + 140, _startPosY + 30, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
44
ProjectMonorail/src/DrawingMonorailWheels.java
Normal file
44
ProjectMonorail/src/DrawingMonorailWheels.java
Normal file
@ -0,0 +1,44 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingMonorailWheels {
|
||||
private WheelsCount _wheelsCount;
|
||||
|
||||
public void setEnumNumber(int wheelsCount){
|
||||
for (WheelsCount value : WheelsCount.values()){
|
||||
if (value.getEnumNumber() == wheelsCount){
|
||||
_wheelsCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawWheels(Graphics2D g2d, Color color, int x, int y){
|
||||
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(x, y + 30, 10, 10);
|
||||
g2d.setColor(color);
|
||||
g2d.fillOval(x, y + 30, 10, 10);
|
||||
}
|
||||
|
||||
public void drawMonorailWheels(Graphics g, Color color, int startPosX, int startPosY){
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
switch (_wheelsCount){
|
||||
case Two:
|
||||
drawWheels(g2d, Color.WHITE, startPosX + 15, startPosY);
|
||||
drawWheels(g2d, Color.WHITE, startPosX + 65, startPosY);
|
||||
break;
|
||||
case Three:
|
||||
drawWheels(g2d, Color.WHITE, startPosX + 15, startPosY);
|
||||
eegov
commented
Имеется дублирующийся код Имеется дублирующийся код
|
||||
drawWheels(g2d, Color.WHITE, startPosX + 65, startPosY);
|
||||
drawWheels(g2d, color, startPosX + 30, startPosY);
|
||||
break;
|
||||
case Four:
|
||||
drawWheels(g2d, Color.WHITE, startPosX + 15, startPosY);
|
||||
drawWheels(g2d, Color.WHITE, startPosX + 65, startPosY);
|
||||
drawWheels(g2d, color, startPosX + 30, startPosY);
|
||||
drawWheels(g2d, color, startPosX + 50, startPosY);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
32
ProjectMonorail/src/EntityMonorail.java
Normal file
32
ProjectMonorail/src/EntityMonorail.java
Normal file
@ -0,0 +1,32 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityMonorail {
|
||||
private int Speed;
|
||||
public int getSpeed(){return Speed;}
|
||||
|
||||
private double Weight;
|
||||
public double getWeight(){return Weight;}
|
||||
|
||||
private Color BodyColor;
|
||||
public Color getBodyColor(){return BodyColor;};
|
||||
|
||||
private Color AdditionalColor;
|
||||
public Color getAdditionalColor(){return AdditionalColor;};
|
||||
|
||||
private boolean Rail;
|
||||
public boolean getRail(){return Rail;}
|
||||
|
||||
private boolean SecondCarriage;
|
||||
public boolean getSecondCarriage(){return SecondCarriage;}
|
||||
|
||||
public double Step(){return Speed*100/Weight;}
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean rail, boolean secondCarriage){
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Rail = rail;
|
||||
SecondCarriage = secondCarriage;
|
||||
}
|
||||
}
|
91
ProjectMonorail/src/FormMonorail.form
Normal file
91
ProjectMonorail/src/FormMonorail.form
Normal file
@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMonorail">
|
||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" 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>
|
||||
<xy x="20" y="20" width="1222" height="655"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<maximumSize width="1222" height="655"/>
|
||||
<minimumSize width="1222" height="655"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="22152" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<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>
|
||||
<doubleBuffered value="false"/>
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="15f80">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="dacaf" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="→"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7c40b" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<actionCommand value=""/>
|
||||
<text value="↓"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c146d" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<actionCommand value=""/>
|
||||
<text value="←"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="209bb" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<actionCommand value=""/>
|
||||
<text value="↑"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="98210">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="e878d">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
114
ProjectMonorail/src/FormMonorail.java
Normal file
114
ProjectMonorail/src/FormMonorail.java
Normal file
@ -0,0 +1,114 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
import java.util.List;
|
||||
|
||||
public class FormMonorail extends JFrame {
|
||||
protected DrawingMonorail _drawingMonorail = new DrawingMonorail();
|
||||
JPanel PictureBox;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonUp;
|
||||
|
||||
private List<JComponent> controls;
|
||||
|
||||
public FormMonorail() {
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
InitializeControlsRepaintList();
|
||||
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_drawingMonorail = new DrawingMonorail();
|
||||
Random random = new Random();
|
||||
|
||||
_drawingMonorail.Init(random.nextInt(30, 100),
|
||||
random.nextInt(100, 500),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
random.nextBoolean(), random.nextBoolean());
|
||||
_drawingMonorail.SetPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
||||
_drawingMonorail.SetPosition(random.nextInt(25, 100),
|
||||
random.nextInt(25, 100));
|
||||
|
||||
Draw();
|
||||
|
||||
}
|
||||
});
|
||||
ActionListener buttonMoveClickedListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
boolean result = false;
|
||||
|
||||
switch (buttonName) {
|
||||
case "buttonUp": {
|
||||
result = _drawingMonorail.MoveTransport(DirectionType.Up);
|
||||
}
|
||||
break;
|
||||
case "buttonDown": {
|
||||
result = _drawingMonorail.MoveTransport(DirectionType.Down);
|
||||
}
|
||||
break;
|
||||
case "buttonLeft": {
|
||||
result = _drawingMonorail.MoveTransport(DirectionType.Left);
|
||||
}
|
||||
break;
|
||||
case "buttonRight": {
|
||||
result = _drawingMonorail.MoveTransport(DirectionType.Right);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
if (result)
|
||||
Draw();
|
||||
|
||||
}
|
||||
};
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
|
||||
}
|
||||
|
||||
private void Draw() {
|
||||
if (_drawingMonorail.getEntityMonorail() == null)
|
||||
return;
|
||||
if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
|
||||
return;
|
||||
}
|
||||
Graphics g = PictureBox.getGraphics();
|
||||
g.setColor(PictureBox.getBackground());
|
||||
g.fillRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
_drawingMonorail.DrawMonorail(g);
|
||||
|
||||
RepaintControls();
|
||||
|
||||
}
|
||||
|
||||
private void RepaintControls() {
|
||||
for (JComponent control : controls) {
|
||||
control.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void InitializeControlsRepaintList() {
|
||||
controls = new LinkedList<>();
|
||||
controls.add(buttonCreate);
|
||||
controls.add(buttonUp);
|
||||
controls.add(buttonDown);
|
||||
controls.add(buttonLeft);
|
||||
controls.add(buttonRight);
|
||||
}
|
||||
}
|
@ -1,5 +1,15 @@
|
||||
import javax.swing.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||
JFrame frame = new JFrame("Монорельс");
|
||||
frame.setContentPane(new FormMonorail().PictureBox);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(500, 200);
|
||||
frame.pack();
|
||||
frame.setSize(700, 500);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
14
ProjectMonorail/src/WheelsCount.java
Normal file
14
ProjectMonorail/src/WheelsCount.java
Normal file
@ -0,0 +1,14 @@
|
||||
public enum WheelsCount {
|
||||
Two(2),
|
||||
Three(3),
|
||||
Four(4);
|
||||
|
||||
final private int EnumNumber;
|
||||
WheelsCount(int enumNumber){
|
||||
EnumNumber = enumNumber;
|
||||
}
|
||||
|
||||
public int getEnumNumber(){
|
||||
return EnumNumber;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user
private