done+
This commit is contained in:
parent
69f50aabc3
commit
e40b4d1a35
@ -1,14 +1,14 @@
|
||||
package DoubleDeckerBus;
|
||||
|
||||
import DoubleDeckerBus.DrawningObjects.DrawningBus;
|
||||
import DoubleDeckerBus.Generics.BusGenericCollection;
|
||||
import DoubleDeckerBus.Generics.TheBusesGenericCollection;
|
||||
import DoubleDeckerBus.MovementStrategy.DrawningObjectBus;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class CollectionCanvas extends JComponent {
|
||||
public BusGenericCollection<DrawningBus, DrawningObjectBus> _bus;
|
||||
public TheBusesGenericCollection<DrawningBus, DrawningObjectBus> _bus;
|
||||
|
||||
@Override
|
||||
public void paintComponent (Graphics g){
|
||||
|
@ -1,7 +1,7 @@
|
||||
package DoubleDeckerBus;
|
||||
|
||||
import DoubleDeckerBus.DrawningObjects.DrawningBus;
|
||||
import DoubleDeckerBus.Generics.BusGenericCollection;
|
||||
import DoubleDeckerBus.Generics.TheBusesGenericCollection;
|
||||
import DoubleDeckerBus.MovementStrategy.DrawningObjectBus;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -9,7 +9,7 @@ import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class FormBusCollection {
|
||||
private final BusGenericCollection<DrawningBus, DrawningObjectBus> _bus;
|
||||
private final TheBusesGenericCollection<DrawningBus, DrawningObjectBus> _bus;
|
||||
private int pictureBoxWidth = 605;
|
||||
private int pictureBoxHeight = 426;
|
||||
|
||||
@ -23,7 +23,7 @@ public class FormBusCollection {
|
||||
}
|
||||
|
||||
public FormBusCollection() {
|
||||
_bus = new BusGenericCollection<>(pictureBoxWidth, pictureBoxHeight);
|
||||
_bus = new TheBusesGenericCollection<>(pictureBoxWidth, pictureBoxHeight);
|
||||
canvas = new CollectionCanvas();
|
||||
JPanel toolBox = new JPanel();
|
||||
JFrame collectionFrame = new JFrame();
|
||||
|
@ -7,57 +7,56 @@ import DoubleDeckerBus.Entities.EntityBus;
|
||||
import java.util.Random;
|
||||
|
||||
public class HardGeneric <T extends EntityBus,U extends IDraw> {
|
||||
T[] arrFirst;
|
||||
U[] arrSecond;
|
||||
T[] busArray;
|
||||
U[] doorArray;
|
||||
|
||||
private int curSz;
|
||||
private int CountFirst;
|
||||
private int CountSecond;
|
||||
private int currentSize;
|
||||
private int MaxCountBuses;
|
||||
private int MaxCountDoors;
|
||||
|
||||
private int pictureBoxWidth;
|
||||
|
||||
private int pictureBoxHeight;
|
||||
|
||||
public HardGeneric(int countFirst, int countSecond, int width, int height){
|
||||
curSz = 0;
|
||||
CountFirst = countFirst;
|
||||
CountSecond = countSecond;
|
||||
arrFirst = (T[]) new EntityBus[CountFirst];
|
||||
arrSecond = (U[]) new IDraw[CountSecond];
|
||||
public HardGeneric(int maxCountBuses, int countSecond, int width, int height) {
|
||||
currentSize = 0;
|
||||
MaxCountBuses = maxCountBuses;
|
||||
MaxCountDoors = countSecond;
|
||||
busArray = (T[]) new EntityBus[MaxCountBuses];
|
||||
doorArray = (U[]) new IDraw[MaxCountDoors];
|
||||
pictureBoxHeight = height;
|
||||
pictureBoxWidth = width;
|
||||
}
|
||||
|
||||
public int InsertFirst(T entityBus) {
|
||||
if (arrFirst[CountFirst-1] != null) {
|
||||
public int insertBus(T entityBus) {
|
||||
if (busArray[MaxCountBuses - 1] != null) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = curSz - 1; i >= 0; i--) {
|
||||
arrFirst[i + 1] = arrFirst[i];
|
||||
arrSecond[i + 1] = arrSecond[i];
|
||||
for (int i = currentSize - 1; i >= 0; i--) {
|
||||
busArray[i + 1] = busArray[i];
|
||||
doorArray[i + 1] = doorArray[i];
|
||||
}
|
||||
curSz++;
|
||||
arrFirst[0] = entityBus;
|
||||
currentSize++;
|
||||
busArray[0] = entityBus;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int InsertSecond(U inter) {
|
||||
if (arrSecond[CountSecond-1] != null) {
|
||||
public int insertDoor(U inter) {
|
||||
if (doorArray[MaxCountBuses - 1] != null) {
|
||||
return -1;
|
||||
}
|
||||
arrSecond[0] = inter;
|
||||
doorArray[0] = inter;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public DrawningBus MakeObject() {
|
||||
Random rand = new Random();
|
||||
int indFirst = rand.nextInt(0, curSz);
|
||||
int indSecond = rand.nextInt(0,curSz);
|
||||
EntityBus entity = arrFirst[indFirst];
|
||||
IDraw inter = arrSecond[indSecond];
|
||||
DrawningBus bus = new DrawningBus(entity.Speed(), entity.Weight(), entity.BodyColor(),
|
||||
int indBus = rand.nextInt(0, currentSize);
|
||||
int indDoors = rand.nextInt(0,currentSize);
|
||||
EntityBus entity = busArray[indBus];
|
||||
IDraw inter = doorArray[indDoors];
|
||||
return new DrawningBus(entity.Speed(), entity.Weight(), entity.BodyColor(),
|
||||
pictureBoxWidth, pictureBoxHeight);
|
||||
return bus;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import DoubleDeckerBus.MovementStrategy.IMoveableObject;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class BusGenericCollection<T extends DrawningBus, U extends IMoveableObject> {
|
||||
public class TheBusesGenericCollection<T extends DrawningBus, U extends IMoveableObject> {
|
||||
private final int _pictureWidth;
|
||||
|
||||
private final int _pictureHeight;
|
||||
@ -17,7 +17,7 @@ public class BusGenericCollection<T extends DrawningBus, U extends IMoveableObje
|
||||
|
||||
private final SetGeneric<T> _collection;
|
||||
|
||||
public BusGenericCollection(int picWidth, int picHeight){
|
||||
public TheBusesGenericCollection(int picWidth, int picHeight){
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
@ -2,6 +2,7 @@ package DoubleDeckerBus;
|
||||
|
||||
import DoubleDeckerBus.DrawningObjects.DrawningBus;
|
||||
import DoubleDeckerBus.DrawningObjects.DrawningDoor;
|
||||
import DoubleDeckerBus.DrawningObjects.DrawningDoorTriangle;
|
||||
import DoubleDeckerBus.DrawningObjects.IDraw;
|
||||
import DoubleDeckerBus.Entities.EntityBus;
|
||||
import DoubleDeckerBus.Generics.HardGeneric;
|
||||
@ -18,55 +19,61 @@ public class HardForm {
|
||||
private int pictureBoxWidth;
|
||||
private int pictureBoxHeight;
|
||||
|
||||
private EntityBus makeEntity(){
|
||||
private EntityBus createRandomEntityBus() {
|
||||
Random rand = new Random();
|
||||
return new EntityBus(rand.nextInt(100, 300), rand.nextDouble(1000,3000),
|
||||
Color.getHSBColor(rand.nextInt(0, 301), rand.nextInt(0, 301), rand.nextInt(0, 301)));
|
||||
return new EntityBus(
|
||||
rand.nextInt(100, 300),
|
||||
rand.nextDouble(1000, 3000),
|
||||
Color.getHSBColor(
|
||||
rand.nextInt(0, 301),
|
||||
rand.nextInt(0, 301),
|
||||
rand.nextInt(0, 301)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void Draw(){
|
||||
void redrawCanvas() {
|
||||
if (canvas == null) {
|
||||
return;
|
||||
}
|
||||
canvas.repaint();
|
||||
}
|
||||
|
||||
private IDraw makeIDraw(){
|
||||
Random rand = new Random();
|
||||
private IDraw createDrawningDoor(){
|
||||
return new DrawningDoor(pictureBoxWidth, pictureBoxHeight, 0, 0);
|
||||
}
|
||||
|
||||
public HardForm(){
|
||||
public HardForm() {
|
||||
Random rand = new Random();
|
||||
int sz = rand.nextInt(1, 10);
|
||||
int size = rand.nextInt(1, 10);
|
||||
|
||||
JFrame HardFrame = new JFrame();
|
||||
HardFrame.setSize(700, 400);
|
||||
HardFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
canvas = new Canvas();
|
||||
canvas.setBounds(0,0,pictureBoxWidth,pictureBoxHeight);
|
||||
JButton makeObject = new JButton("Создать");
|
||||
makeObject.setBounds(0, 0, 100, 40);
|
||||
canvas.add(makeObject);
|
||||
JButton createObjectButton = new JButton("Создать");
|
||||
createObjectButton.setBounds(0, 0, 100, 40);
|
||||
canvas.add(createObjectButton);
|
||||
HardFrame.setContentPane(canvas);
|
||||
HardFrame.setVisible(true);
|
||||
pictureBoxHeight = canvas.getHeight();
|
||||
pictureBoxWidth = canvas.getWidth();
|
||||
HardGeneric<EntityBus, IDraw> toDraw = new HardGeneric<>(sz, sz, pictureBoxWidth, pictureBoxHeight);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
EntityBus ent = makeEntity();
|
||||
toDraw.InsertFirst(ent);
|
||||
toDraw.InsertSecond(makeIDraw());
|
||||
HardGeneric<EntityBus, IDraw> objectGenerator = new HardGeneric<>(size, size, pictureBoxWidth, pictureBoxHeight);
|
||||
for (int i = 0; i < size; i++) {
|
||||
EntityBus ent = createRandomEntityBus();
|
||||
objectGenerator.insertBus(ent);
|
||||
objectGenerator.insertDoor(createDrawningDoor());
|
||||
}
|
||||
makeObject.addActionListener(
|
||||
createObjectButton.addActionListener(
|
||||
new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
DrawningBus DrawningBus = toDraw.MakeObject();
|
||||
DrawningBus DrawningBus = objectGenerator.MakeObject();
|
||||
DrawningBus.SetPosition(pictureBoxWidth / 2 - DrawningBus.GetWidth()/2,
|
||||
pictureBoxHeight / 2 - DrawningBus.GetHeight()/2);
|
||||
canvas.DrawningBus = DrawningBus;
|
||||
Draw();
|
||||
redrawCanvas();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -4,7 +4,7 @@ import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException {
|
||||
//FormDoubleDeckerBus form = new FormDoubleDeckerBus();
|
||||
//new FormBusCollection();
|
||||
new HardForm();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user