Допустим перенес все файлы

This commit is contained in:
Tonb73 2024-06-08 15:53:53 +04:00
parent 78d14ef13e
commit e3f5feadb2
5 changed files with 134 additions and 175 deletions

View File

@ -0,0 +1,39 @@
import java.awt.*;
public class EntityElectricLocomotive {
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;
}
public double Step() {
return Speed*100/Weight;
}
private boolean BatteryStorage;
public boolean getBatteryStorage() {
return BatteryStorage;
}
private boolean Pantograph;
public boolean getPantograph() {
return Pantograph;
}
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean pantograph, boolean batteryStorage) {
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Pantograph = pantograph;
BatteryStorage = batteryStorage;
}
}

View File

@ -8,89 +8,30 @@
<properties/>
<border type="none"/>
<children>
<grid id="1ff9a" binding="PictureBox" layout-manager="GridLayoutManager" row-count="6" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="1ff9a" binding="PictureBox" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<toolTipText value=""/>
</properties>
<properties/>
<border type="none"/>
<children>
<component id="a8c2" class="javax.swing.JButton" binding="buttonCreate">
<constraints>
<grid row="2" column="0" row-span="2" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<vspacer id="7b40c">
<constraints>
<grid row="2" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<preferred-size width="88" height="14"/>
</grid>
<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>
<hspacer id="e0b21">
<constraints>
<grid row="4" 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>
<component id="a8c2" class="javax.swing.JButton" binding="buttonCreateElectricLocomotive">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="150" height="30"/>
<preferred-size width="150" height="30"/>
<maximum-size width="150" height="30"/>
</grid>
</constraints>
<properties>
<text value="Создать ЭлектроЛокомотив"/>
</properties>
</component>
<component id="79b3e" class="javax.swing.JButton" binding="buttonCreateLocomotive">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="10" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="150" height="30"/>
<preferred-size width="150" height="30"/>
<maximum-size width="150" height="30"/>
</grid>
</constraints>
<properties>
<text value="Создать локомотив"/>
</properties>
</component>
<component id="fe25b" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="5" 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="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="arrowLeft.png"/>
<text value=""/>
</properties>
</component>
<component id="3eabd" class="javax.swing.JButton" binding="buttonStrategyStep">
<constraints>
<grid row="1" column="3" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Шаг"/>
</properties>
</component>
<component id="86d84" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="5" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="arrowRight.png"/>
<text value=""/>
</properties>
</component>
<component id="3dc0" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -101,9 +42,14 @@
<text value=""/>
</properties>
</component>
<hspacer id="abaeb">
<constraints>
<grid row="2" column="1" row-span="2" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="ccb2a" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -114,14 +60,30 @@
<text value=""/>
</properties>
</component>
<component id="988c8" class="javax.swing.JComboBox" binding="comboBoxStrategy">
<component id="fe25b" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="0" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<actionCommand value=""/>
<doubleBuffered value="false"/>
<toolTipText value=""/>
<icon value="arrowLeft.png"/>
<text value=""/>
</properties>
</component>
<component id="86d84" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="arrowRight.png"/>
<text value=""/>
</properties>
</component>
</children>

View File

@ -1,56 +1,22 @@
import Drawnings.DrawningElectricLocomotive;
import Drawnings.DrawningLocomotive;
import MovementStrategy.*;
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;
import java.util.Random;
public class FormElectricLocomotive extends JFrame {
protected DrawningLocomotive _drawningLocomotive;
protected DrawningElectricLocomotive _drawningElectricLocomotive = new DrawningElectricLocomotive();
JPanel PanelWrapper;
private JPanel PictureBox;
private JButton buttonCreateElectricLocomotive;
private JButton buttonCreateLocomotive;
private JButton buttonCreate;
private JButton buttonRight;
private JButton buttonDown;
private JButton buttonLeft;
private JButton buttonUp;
private JComboBox comboBoxStrategy;
private JButton buttonStrategyStep;
private AbstractStrategy _strategy;
private List<JComponent> controls;
private void createObject(String type) {
Random random = new Random();
switch (type) {
case "Drawnings.DrawningLocomotive":
_drawningLocomotive = new DrawningLocomotive(50, 100,
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3));
break;
case "Drawnings.DrawningElectricLocomotive":
_drawningLocomotive = new DrawningElectricLocomotive(50, 100,
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),random.nextInt(3),
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
random.nextBoolean(), random.nextBoolean());
break;
default:
return;
}
_drawningLocomotive.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
_drawningLocomotive.setPosition(random.nextInt(100),
random.nextInt(100));
_strategy = null;
comboBoxStrategy.setEnabled(true);
Draw();
}
public FormElectricLocomotive() {
buttonUp.setName("buttonUp");
buttonDown.setName("buttonDown");
@ -59,17 +25,23 @@ public class FormElectricLocomotive extends JFrame {
InitializeControlsRepaintList();
buttonCreateElectricLocomotive.addActionListener(new ActionListener() {
buttonCreate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createObject("Drawnings.DrawningElectricLocomotive");
_drawningElectricLocomotive = new DrawningElectricLocomotive();
Random random = new Random();
_drawningElectricLocomotive.Init(25,
200,
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() );
_drawningElectricLocomotive.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
_drawningElectricLocomotive.setPosition(random.nextInt(100),
random.nextInt(100));
Draw();
}
});
buttonCreateLocomotive.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createObject("Drawnings.DrawningLocomotive");
}
});
ActionListener buttonMoveClickedListener = new ActionListener() {
@ -80,72 +52,36 @@ public class FormElectricLocomotive extends JFrame {
switch (buttonName) {
case "buttonUp": {
result = _drawningLocomotive.moveTransport(MovementDirection.Up);
result = _drawningElectricLocomotive.moveTransport(DirectionType.Up);
}
break;
case "buttonDown": {
result = _drawningLocomotive.moveTransport(MovementDirection.Down);
result = _drawningElectricLocomotive.moveTransport(DirectionType.Down);
}
break;
case "buttonLeft": {
result = _drawningLocomotive.moveTransport(MovementDirection.Left);
result = _drawningElectricLocomotive.moveTransport(DirectionType.Left);
}
break;
case "buttonRight": {
result = _drawningLocomotive.moveTransport(MovementDirection.Right);
result = _drawningElectricLocomotive.moveTransport(DirectionType.Right);
}
break;
}
if (result)
Draw();
}
};
buttonRight.addActionListener(buttonMoveClickedListener);
buttonDown.addActionListener(buttonMoveClickedListener);
buttonLeft.addActionListener(buttonMoveClickedListener);
buttonUp.addActionListener(buttonMoveClickedListener);
comboBoxStrategy.addItem("К центру");
comboBoxStrategy.addItem("К краю");
buttonStrategyStep.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_drawningLocomotive == null)
return;
if (comboBoxStrategy.isEnabled()) {
switch (comboBoxStrategy.getSelectedIndex()) {
case 0:
_strategy = new MoveToCenter();
break;
case 1:
_strategy = new MoveToBorder();
break;
default:
_strategy = null;
break;
}
if (_strategy == null) {
return;
}
_strategy.SetData(new MoveableLocomotive(_drawningLocomotive), PictureBox.getWidth(), PictureBox.getHeight());
}
if (_strategy == null) {
return;
}
_strategy.MakeStep();
Draw();
comboBoxStrategy.setEnabled(false);
if (_strategy.GetStatus() == StrategyStatus.Finish) {
comboBoxStrategy.setEnabled(true);
_strategy = null;
}
}
});
}
private void Draw() {
if (_drawningLocomotive.getEntityLocomotive() == null)
if (_drawningElectricLocomotive.getEntityElectricLocomotive() == null)
return;
if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
return;
@ -153,9 +89,10 @@ public class FormElectricLocomotive extends JFrame {
Graphics g = PictureBox.getGraphics();
g.setColor(PictureBox.getBackground());
g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight());
_drawningLocomotive.DrawTransport(g);
_drawningElectricLocomotive.DrawTransport(g);
RepaintControls();
}
private void RepaintControls() {
for (JComponent control : controls) {
@ -163,15 +100,15 @@ public class FormElectricLocomotive extends JFrame {
}
}
private void InitializeControlsRepaintList() {
controls = new LinkedList<>();
controls.add(buttonCreateElectricLocomotive);
controls.add(buttonCreateLocomotive);
controls.add(buttonCreate);
controls.add(buttonUp);
controls.add(buttonDown);
controls.add(buttonLeft);
controls.add(buttonRight);
controls.add(comboBoxStrategy);
controls.add(buttonStrategyStep);
}
}
}

View File

@ -1,7 +1,16 @@
import javax.swing.*;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
}
}
JFrame.setDefaultLookAndFeelDecorated(false);
JFrame frame = new JFrame("Поезд");
frame.setContentPane(new FormElectricLocomotive().PanelWrapper);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(500, 200);
frame.pack();
frame.setSize(700, 500);
frame.setVisible(true);
}
}

12
OOP/src/WheelsCount.java Normal file
View File

@ -0,0 +1,12 @@
public enum WheelsCount {
Two(2),
Three(3),
Four(4);
final private int EnumNumber;
WheelsCount(int enumNumber) {
EnumNumber = enumNumber;
}
public int getEnumNumber() {
return EnumNumber;
}
}