package ProjectElectricLocomotive; import javax.swing.*; import java.awt.*; import java.util.Random; public class FormDopClassParameters { private JButton ButtonGenerationRandomLocomotive; private JPanel pictureBoxGenerated; Random rnd; DrawingLocomotive drawingLocomotive; DopClassParameters _dopClassParameters; public JPanel getPictureBoxGenerated() { return pictureBoxGenerated; } public FormDopClassParameters() { pictureBoxGenerated.setPreferredSize(new Dimension(400, 300)); _dopClassParameters = new DopClassParameters<>( 10, pictureBoxGenerated.getWidth(), pictureBoxGenerated.getHeight() ); ButtonGenerationRandomLocomotive.addActionListener(e -> { AddEntityLocomotive(); AddRandomWheels(); drawingLocomotive = _dopClassParameters.RandomLocomotive( pictureBoxGenerated.getWidth(), pictureBoxGenerated.getHeight() ); drawingLocomotive.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100)); Draw(); }); } public void AddEntityLocomotive() { rnd = new Random(); EntityLocomotive entityLocomotive; Color color = new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); if (rnd.nextBoolean()) { entityLocomotive = new EntityLocomotive( rnd.nextInt(100, 300), rnd.nextInt(1000, 3000), color ); } else { entityLocomotive = new EntityElectricLocomotive( rnd.nextInt(100, 300), rnd.nextInt(1000, 3000), color, color, rnd.nextBoolean(), rnd.nextBoolean() ); } _dopClassParameters.Add(entityLocomotive); } public void AddRandomWheels() { rnd = new Random(); IDrawingWheels iDrawingWheels; int wheelsChoice = rnd.nextInt(0, 3); if (wheelsChoice == 0) { iDrawingWheels = new DrawingWheel(); } else if (wheelsChoice == 1) { iDrawingWheels = new DrawingEmptyWheels(); } else { iDrawingWheels = new DrawingWheelsBlueCrom(); } iDrawingWheels.SetWheelsCount(rnd.nextInt(2, 5)); _dopClassParameters.Add(iDrawingWheels); } public void Draw() { if (drawingLocomotive.EntityLocomotive == null) { return; } Graphics g = pictureBoxGenerated.getGraphics(); pictureBoxGenerated.paint(g); drawingLocomotive.DrawTransport(g); } }