All done
This commit is contained in:
parent
7a9ec33ba1
commit
f3419a40e6
61
src/MonorailHard/Generics/HardGeneric.java
Normal file
61
src/MonorailHard/Generics/HardGeneric.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package MonorailHard.Generics;
|
||||||
|
|
||||||
|
import MonorailHard.DrawningObjects.DrawningMonorail;
|
||||||
|
import MonorailHard.DrawningObjects.IDraw;
|
||||||
|
import MonorailHard.Entities.EntityMonorail;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class HardGeneric <T extends EntityMonorail,U extends IDraw>{
|
||||||
|
T[] arrFirst;
|
||||||
|
U[] arrSecond;
|
||||||
|
|
||||||
|
private int curSz;
|
||||||
|
private int CountFirst;
|
||||||
|
private int CountSecond;
|
||||||
|
|
||||||
|
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 EntityMonorail[CountFirst];
|
||||||
|
arrSecond = (U[]) new IDraw[CountSecond];
|
||||||
|
pictureBoxHeight = height;
|
||||||
|
pictureBoxWidth = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int InsertFirst(T entityMonorail){
|
||||||
|
if(arrFirst[CountFirst-1] != null)
|
||||||
|
return -1;
|
||||||
|
for(int i = curSz -1; i>= 0; i--) {
|
||||||
|
arrFirst[i + 1] = arrFirst[i];
|
||||||
|
arrSecond[i + 1] = arrSecond[i];
|
||||||
|
}
|
||||||
|
curSz++;
|
||||||
|
arrFirst[0] = entityMonorail;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int InsertSecond(U inter){
|
||||||
|
if(arrSecond[CountSecond-1] != null)
|
||||||
|
return -1;
|
||||||
|
arrSecond[0] = inter;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawningMonorail MakeObject(){
|
||||||
|
Random rand = new Random();
|
||||||
|
int indFirst = rand.nextInt(0, curSz);
|
||||||
|
int indSecond = rand.nextInt(0,curSz);
|
||||||
|
EntityMonorail entity = arrFirst[indFirst];
|
||||||
|
IDraw inter = arrSecond[indSecond];
|
||||||
|
DrawningMonorail monorail = new DrawningMonorail(entity.Speed(), entity.Weight(), entity.BodyColor(),
|
||||||
|
entity.WheelColor(), entity.TireColor(), pictureBoxWidth, pictureBoxHeight);
|
||||||
|
return monorail;
|
||||||
|
}
|
||||||
|
}
|
77
src/MonorailHard/HardForm.java
Normal file
77
src/MonorailHard/HardForm.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package MonorailHard;
|
||||||
|
|
||||||
|
import MonorailHard.DrawningObjects.DrawningMonorail;
|
||||||
|
import MonorailHard.DrawningObjects.DrawningWheels;
|
||||||
|
import MonorailHard.DrawningObjects.IDraw;
|
||||||
|
import MonorailHard.Entities.EntityMonorail;
|
||||||
|
import MonorailHard.Generics.HardGeneric;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.text.html.parser.Entity;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class HardForm {
|
||||||
|
private Canvas canv;
|
||||||
|
|
||||||
|
private int pictureBoxWidth;
|
||||||
|
private int pictureBoxHeight;
|
||||||
|
|
||||||
|
private EntityMonorail makeEntity(){
|
||||||
|
Random rand = new Random();
|
||||||
|
return new EntityMonorail(rand.nextInt(100, 300), rand.nextDouble(1000,3000),
|
||||||
|
Color.getHSBColor(rand.nextInt(0, 301), rand.nextInt(0, 301), rand.nextInt(0, 301)),
|
||||||
|
Color.getHSBColor(rand.nextInt(0, 301), rand.nextInt(0, 301), rand.nextInt(0, 301)),
|
||||||
|
Color.getHSBColor(rand.nextInt(0, 301), rand.nextInt(0, 301), rand.nextInt(0, 301)));
|
||||||
|
}
|
||||||
|
void Draw(){
|
||||||
|
if(canv == null)
|
||||||
|
return;
|
||||||
|
canv.repaint();
|
||||||
|
}
|
||||||
|
private IDraw makeIDraw(EntityMonorail entity){
|
||||||
|
Random rand = new Random();
|
||||||
|
return new DrawningWheels(pictureBoxWidth, pictureBoxHeight, 0, 0, entity.WheelColor(), entity.TireColor());
|
||||||
|
}
|
||||||
|
public HardForm(){
|
||||||
|
Random rand = new Random();
|
||||||
|
int sz = rand.nextInt(1, 10);
|
||||||
|
|
||||||
|
|
||||||
|
JFrame HardFrame = new JFrame();
|
||||||
|
HardFrame.setSize(700, 400);
|
||||||
|
HardFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
canv = new Canvas();
|
||||||
|
canv.setBounds(0,0,pictureBoxWidth,pictureBoxHeight);
|
||||||
|
JButton makeObject = new JButton("Создать");
|
||||||
|
makeObject.setBounds(0, 0, 100, 40);
|
||||||
|
canv.add(makeObject);
|
||||||
|
HardFrame.setContentPane(canv);
|
||||||
|
HardFrame.setVisible(true);
|
||||||
|
pictureBoxHeight = canv.getHeight();
|
||||||
|
pictureBoxWidth = canv.getWidth();
|
||||||
|
HardGeneric<EntityMonorail, IDraw> toDraw= new HardGeneric<>(sz,
|
||||||
|
sz, pictureBoxWidth, pictureBoxHeight);
|
||||||
|
for(int i = 0; i < sz; i++){
|
||||||
|
EntityMonorail ent = makeEntity();
|
||||||
|
toDraw.InsertFirst(ent);
|
||||||
|
toDraw.InsertSecond(makeIDraw(ent));
|
||||||
|
}
|
||||||
|
makeObject.addActionListener(
|
||||||
|
new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
DrawningMonorail DrawningMonorail = toDraw.MakeObject();
|
||||||
|
DrawningMonorail.SetPosition(pictureBoxWidth / 2 - DrawningMonorail.GetWidth()/2,
|
||||||
|
pictureBoxHeight / 2 - DrawningMonorail.GetHeight()/2);
|
||||||
|
canv.DrawningMonorail = DrawningMonorail;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,6 @@ import javax.swing.*;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
FormMonorailCollection form = new FormMonorailCollection();
|
HardForm form = new HardForm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user