Mochalov D.V. Hard LabWork02 #2

Merged
eegov merged 14 commits from LabWork02 into LabWork01 2022-10-21 10:06:17 +04:00
4 changed files with 8 additions and 11 deletions
Showing only changes of commit e9053085ef - Show all commits

View File

@ -1,4 +1,5 @@
import java.awt.*;
import java.util.Random;
class DrawningLocomotive {
public EntityLocomotive Locomotive;
@ -16,12 +17,11 @@ class DrawningLocomotive {
/// Высота отрисовки локомотива
private final int _locomotiveHeight = 50;
/// Инициализация свойств
public void Init(int speed, float weight, Color bodyColor, int wheelsNum, EntityLocomotive entity)
private final Random random = new Random();
public DrawningLocomotive(int speed, float weight, Color bodyColor)
{
Locomotive = entity;
extraWheelsDraw = new ExtraWheelsDraw();
extraWheelsDraw.Init(wheelsNum, bodyColor);
Locomotive.Init(speed, weight, bodyColor);
extraWheelsDraw = new ExtraWheelsDraw(random.nextInt(3), bodyColor);
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
}
/// Установка позиции локомотива
Review

Нет вызова метода/свойства передачи параметра в объект класса

Нет вызова метода/свойства передачи параметра в объект класса
public void SetPosition(int x, int y, int width, int height)

View File

@ -19,7 +19,7 @@ public class EntityLocomotive {
return Speed * 100 / Weight;
}
public void Init(int speed, float weight, Color bodyColor)
public EntityLocomotive(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
if (speed <= 0) {

View File

@ -18,7 +18,7 @@ public class ExtraWheelsDraw {
}
private Color color;
public void Init(int num, Color color) {
public ExtraWheelsDraw(int num, Color color) {
setWheelsNum(num);
this.color = color;
}

View File

@ -5,7 +5,6 @@ import java.util.Random;
public class FormLocomotive extends JComponent{
private DrawningLocomotive _locomotive;
private EntityLocomotive _entity;
public FormLocomotive() {
JFrame formFrame = new JFrame("Locomotive");
formFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -40,9 +39,7 @@ public class FormLocomotive extends JComponent{
JButton createButton = new JButton("Create");
createButton.addActionListener(e -> {
Random rnd = new Random();
_locomotive = new DrawningLocomotive();
_entity = new EntityLocomotive();
_locomotive.Init(100 + rnd.nextInt(200), 1000 + rnd.nextInt(1000), Color.getHSBColor(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(3), _entity);
_locomotive = new DrawningLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
_locomotive.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), formFrame.getWidth(), formFrame.getHeight() - 75);
speedLabel.setText("Speed: " + _locomotive.Locomotive.getSpeed());
weightLabel.setText("Weight: " + (int)_locomotive.Locomotive.getWeight());