revert Lab 3 Ready hard
This commit is contained in:
ekallin 2023-11-06 17:02:05 +04:00
parent dc5fb84108
commit e36d02dd75
12 changed files with 20 additions and 262 deletions

View File

@ -1,65 +0,0 @@
package ProjectElectricLocomotive;
import java.util.ArrayList;
import java.util.Random;
public class DopClassParameters<T extends EntityLocomotive, U extends IDrawingWheels> {
public T[] _entityLocomotive;
public U[] _idrawningWheels;
int _locomotivesCount;
int _idrawningWheelsCount;
private int _pictureWidth;
private int _pictureHeight;
public DopClassParameters(int count, int width, int height) {
_entityLocomotive = (T[]) new EntityLocomotive[count];
_idrawningWheels = (U[]) new IDrawingWheels[count];
_pictureWidth = width;
_pictureHeight = height;
_locomotivesCount = 0;
_idrawningWheelsCount = 0;
}
public void Add(T entityLocoObj) {
if (_locomotivesCount < _entityLocomotive.length) {
_entityLocomotive[_locomotivesCount] = entityLocoObj;
_locomotivesCount++;
}
}
public void Add(U idrawingWheels) {
if (_idrawningWheelsCount < _idrawningWheels.length) {
_idrawningWheels[_idrawningWheelsCount] = idrawingWheels;
_idrawningWheelsCount++;
}
}
public DrawingLocomotive RandomLocomotive(int pictureWidth, int pictureHeight) {
Random rnd = new Random();
if (_entityLocomotive == null || _idrawningWheels == null) {
return null;
}
T entityLocomotive = _entityLocomotive[rnd.nextInt(_locomotivesCount)];
U idrawingWheels = _idrawningWheels[rnd.nextInt(_idrawningWheelsCount)];
DrawingLocomotive drawLocomotive;
if (entityLocomotive instanceof EntityElectricLocomotive) {
drawLocomotive = new DrawingElectricLocomotive(
(EntityElectricLocomotive) entityLocomotive,
idrawingWheels,
pictureWidth,
pictureHeight
);
} else {
drawLocomotive = new DrawingLocomotive(
entityLocomotive,
idrawingWheels,
pictureWidth,
pictureHeight
);
}
return drawLocomotive;
}
}

View File

@ -1,7 +1,6 @@
package ProjectElectricLocomotive;
import java.awt.*;
public class DrawingElectricLocomotive extends DrawingLocomotive {
public DrawingElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor,
boolean horns, boolean seifBatteries, int width, int height)
{
@ -11,22 +10,16 @@ public class DrawingElectricLocomotive extends DrawingLocomotive {
EntityLocomotive = new EntityElectricLocomotive(speed, width, bodyColor, additionalColor, horns, seifBatteries);
}
}
public DrawingElectricLocomotive(EntityElectricLocomotive entityElectricLocomotive, IDrawingWheels iDrawingWheels,
int width, int height)
{
super(entityElectricLocomotive,iDrawingWheels, width, height, 150, 50);
}
@Override
public void DrawTransport(Graphics g)
{
if (EntityLocomotive instanceof EntityElectricLocomotive electricLocomotive) ///////// WARNING INSTANCEOF
{
Color addColor = electricLocomotive.AdditionalColor;
Color colorBlack = Color.BLACK;
if (electricLocomotive.Horns) {
//horns
g.setColor(addColor);
g.setColor(colorBlack);
g.fillRect(_startPosX + 30, _startPosY + 15, 20, 5);
g.drawLine(_startPosX + 40, _startPosY + 15, _startPosX + 50, _startPosY + 10);
g.drawLine(_startPosX + 50, _startPosY + 10, _startPosX + 45, _startPosY);
@ -35,7 +28,7 @@ public class DrawingElectricLocomotive extends DrawingLocomotive {
}
if (electricLocomotive.SeifBatteries) {
g.setColor(addColor);
g.setColor(colorBlack);
g.fillRect(_startPosX + 80, _startPosY + 30, 5, 10);
}
super.DrawTransport(g);

View File

@ -26,14 +26,14 @@ public class DrawingLocomotive {
return _locoHeight;
}
public DrawingLocomotive(int speed, double weight, Color bodyColor, int width, int height)
public DrawingLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
{
if (width < _locoWidth || height < _locoHeight)
if (width < _locoWidth || heigth < _locoHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_pictureHeight = heigth;
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
Random rnd = new Random();
@ -58,21 +58,6 @@ public class DrawingLocomotive {
_locoHeight = locoHeight;
}
protected DrawingLocomotive(EntityLocomotive entityLocomotive, IDrawingWheels iDrawingWheels,
int width, int height){
EntityLocomotive = entityLocomotive;
_drawingWheels = iDrawingWheels;
_pictureWidth = width;
_pictureHeight = height;
}
protected DrawingLocomotive(EntityLocomotive entityLocomotive, IDrawingWheels iDrawingWheels,
int width, int height, int locoWidth, int locoHeight){
this(entityLocomotive, iDrawingWheels, width, height);
_locoWidth = locoWidth;
_locoHeight = locoHeight;
}
public void SetWheelsCount(int wheelsCount){
_drawingWheels.SetWheelsCount(wheelsCount);
}

View File

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectElectricLocomotive.FormDopClassParameters">
<grid id="27dc6" binding="pictureBoxGenerated" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="0">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="758" height="552"/>
</constraints>
<properties>
<enabled value="true"/>
<maximumSize width="600" height="400"/>
<minimumSize width="600" height="400"/>
<opaque value="true"/>
<preferredSize width="600" height="400"/>
<requestFocusEnabled value="false"/>
</properties>
<border type="none"/>
<children>
<component id="1ee3" class="javax.swing.JButton" binding="ButtonGenerationRandomLocomotive">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Генерировать локомотив"/>
</properties>
</component>
<hspacer id="b7e9d">
<constraints>
<grid row="0" column="0" 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="d0ce8">
<constraints>
<grid row="1" column="0" 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>

View File

@ -1,86 +0,0 @@
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<EntityLocomotive, IDrawingWheels> _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);
}
}

View File

@ -68,6 +68,7 @@ public class FormElectricLocomotive {
ButtonSelectLocomotive.addActionListener(e->{
SelectedLocomotive = _drawingLocomotive;
IsSelect = true;
// DialogResult = DialogResult.OK;
});
buttonStep.addActionListener(new ActionListener() {

View File

@ -21,7 +21,7 @@
<border type="line"/>
<children/>
</grid>
<grid id="40d5" binding="Instruments" layout-manager="GridLayoutManager" row-count="7" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="40d5" binding="Instruments" layout-manager="GridLayoutManager" row-count="6" column-count="2" 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="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true">
@ -39,7 +39,7 @@
<children>
<vspacer id="1eee0">
<constraints>
<grid row="1" column="1" row-span="6" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="1" column="1" row-span="5" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="138d" class="javax.swing.JButton" binding="ButtonAddLocomotive">
@ -76,14 +76,6 @@
<text value="Обновить "/>
</properties>
</component>
<component id="1b1c" class="javax.swing.JButton" binding="ButtonCreateRandomLoco">
<constraints>
<grid row="5" 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>
<text value="Создать рандомный локо "/>
</properties>
</component>
</children>
</grid>
</children>

View File

@ -4,7 +4,6 @@ import javax.swing.*;
import java.awt.*;
public class FormLocomotiveCollections {
FrameDopClassParameters frameDopClassParameters;
private JPanel MainPanel;
private JPanel pictureBoxCollections;
private JPanel Instruments;
@ -12,9 +11,9 @@ public class FormLocomotiveCollections {
private JTextField textFieldNumber;
private JButton ButtonRefreshCollection;
private JButton ButtonRemoveLocomotive;
private JButton ButtonCreateRandomLoco;
public DrawingLocomotive loco;
LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
FormElectricLocomotive _formElectricLocomotive;
private final LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
public JPanel getPictureBoxCollections() {
return MainPanel;
@ -42,13 +41,7 @@ public class FormLocomotiveCollections {
});
});
ButtonCreateRandomLoco.addActionListener(e->{
if(frameDopClassParameters!=null) frameDopClassParameters.dispose();
frameDopClassParameters = new FrameDopClassParameters();
frameDopClassParameters.setVisible(true);
});
ButtonRemoveLocomotive.addActionListener(e -> {
ButtonRemoveLocomotive.addActionListener(e->{
try {
int pos = Integer.parseInt(textFieldNumber.getText());
if (_locomotives.SubOverload(pos) != null) {
@ -71,12 +64,10 @@ public class FormLocomotiveCollections {
}
});
ButtonRefreshCollection.addActionListener(e -> {
ButtonRefreshCollection.addActionListener(e->{
Refresh();
});
}
public void Refresh() {
Graphics g = pictureBoxCollections.getGraphics();
pictureBoxCollections.paint(g);

View File

@ -1,19 +0,0 @@
package ProjectElectricLocomotive;
import javax.swing.*;
public class FrameDopClassParameters extends JFrame {
public FormDopClassParameters _formDopClassParameters;
public FrameDopClassParameters(){
super();
setTitle("Рандомный локомотив");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
_formDopClassParameters = new FormDopClassParameters();
setContentPane(_formDopClassParameters.getPictureBoxGenerated());
setDefaultLookAndFeelDecorated(false);
setLocation(500, 200);
pack();
setVisible(true);
}
}

View File

@ -6,8 +6,8 @@ public class FrameElectricLocomotive extends JFrame {
public FormElectricLocomotive _formLocomotiveCollection;
public FrameElectricLocomotive() {
super();
setTitle("Электролокомотив");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle("ElectroLoco");
setDefaultCloseOperation(EXIT_ON_CLOSE);
_formLocomotiveCollection = new FormElectricLocomotive();
setContentPane(_formLocomotiveCollection.getPictureBox());
setDefaultLookAndFeelDecorated(false);

View File

@ -6,7 +6,8 @@ public class FrameLocomotiveCollection extends JFrame {
public FormLocomotiveCollections _formLocomotiveCollections;
public FrameLocomotiveCollection(){
super();
setTitle("Коллекция");setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("LocoCollection");
setDefaultCloseOperation(EXIT_ON_CLOSE);
_formLocomotiveCollections = new FormLocomotiveCollections();
setContentPane(_formLocomotiveCollections.getPictureBoxCollections());
setDefaultLookAndFeelDecorated(false);

View File

@ -10,11 +10,14 @@ public class LocomotiveGenericCollection<T extends DrawingLocomotive,U extends I
//ширина/высота занимаемого места
private final int _placeSizeWidth = 150;
private final int _placeSizeHeight = 50;
/// Набор объектов
private final SetGeneric<T> _collection;
public LocomotiveGenericCollection(int picWidth, int picHeight)
{
// немного странная логика, что-то я пока ее не особо понимаю, зачем нам ААААА дошло...
// высчитываем размер массива для setgeneric
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;