Lab3 Done done
This commit is contained in:
parent
8cc4261ccb
commit
f7be8b6d55
10
.idea/inspectionProfiles/Project_Default.xml
Normal file
10
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<Languages>
|
||||
<language minSize="53" name="Java" />
|
||||
</Languages>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -5,7 +5,6 @@ public class BusesGenericCollection<T extends DrawingBus, U extends IMoveableObj
|
||||
private final int _placeSizeWidth = 210;
|
||||
private final int _placeSizeHeight = 135;
|
||||
private SetGeneric<T> _collection;
|
||||
|
||||
public BusesGenericCollection(int picWidth, int picHeight) {
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
@ -33,7 +32,7 @@ public class BusesGenericCollection<T extends DrawingBus, U extends IMoveableObj
|
||||
public U GetU(int pos) {
|
||||
if(_collection.Get(pos) == null)
|
||||
return null;
|
||||
return (U)_collection.Get(pos).GetMoveableObject;
|
||||
return (U)_collection.Get(pos).GetMoveableObject();
|
||||
}
|
||||
private void drawBackground(Graphics2D g) {
|
||||
BasicStroke pen = new BasicStroke(3);
|
||||
@ -55,7 +54,6 @@ public class BusesGenericCollection<T extends DrawingBus, U extends IMoveableObj
|
||||
if (bus != null) {
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
bus.setPosition(_placeSizeWidth * (inRow - 1) - (i % inRow * _placeSizeWidth), i / inRow * _placeSizeHeight);
|
||||
//bus.setPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth)-8, i / inRow * _placeSizeHeight + 20);
|
||||
bus.drawTransport(g);
|
||||
}
|
||||
}
|
||||
|
@ -134,5 +134,5 @@ public class DrawingBus {
|
||||
graphics2D.setPaint(Color.BLACK);
|
||||
graphics2D.drawRect(_startPosX + 196, _startPosY + 91, 10, 20);
|
||||
}
|
||||
public IMoveableObject GetMoveableObject = new DrawingObjectBus(this);
|
||||
public IMoveableObject GetMoveableObject() { return new DrawingObjectBus(this);}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ public class FrameBusCollection extends JFrame {
|
||||
private BusesGenericCollection<DrawingBus, DrawingObjectBus> buses;
|
||||
JComponent pictureBoxCollection;
|
||||
TextField textFieldNumber;
|
||||
public FrameBusCollection() throws IOException{
|
||||
public FrameBusCollection(){
|
||||
super("Набор автобусов");
|
||||
setSize(new Dimension(900,500));
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
@ -4,14 +4,14 @@ import java.util.Random;
|
||||
public class FrameHard extends JFrame{
|
||||
HardGeneric<EntityBus, IDrawDoors> generic;
|
||||
DrawingBus drawing;
|
||||
private JComponent pictureBox;
|
||||
private JComponent pictureBoxHard;
|
||||
private int pictureBoxWidth = 210;
|
||||
private int pictureBoxHeight = 165;
|
||||
public FrameHard(){
|
||||
setSize(300, 300);
|
||||
setLocationRelativeTo(null);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
pictureBox = new JComponent(){
|
||||
pictureBoxHard = new JComponent(){
|
||||
public void paintComponent(Graphics graphics){
|
||||
super.paintComponent(graphics);
|
||||
Graphics2D graphics2D = (Graphics2D) graphics;
|
||||
@ -19,7 +19,7 @@ public class FrameHard extends JFrame{
|
||||
super.repaint();
|
||||
}
|
||||
};
|
||||
pictureBox.setSize(pictureBoxWidth,pictureBoxHeight);
|
||||
pictureBoxHard.setSize(pictureBoxWidth,pictureBoxHeight);
|
||||
JButton buttonMakeObject = new JButton("Создать объект");
|
||||
Random rand = new Random();
|
||||
int size = rand.nextInt(1, 10);
|
||||
@ -33,13 +33,11 @@ public class FrameHard extends JFrame{
|
||||
drawingBus.setPosition(pictureBoxWidth / 2 - drawingBus.getWidth()/2,
|
||||
pictureBoxHeight / 2 - drawingBus.getHeight()/2);
|
||||
drawing = drawingBus;
|
||||
draw();
|
||||
pictureBoxHard.repaint();
|
||||
});
|
||||
setLayout(new BorderLayout());
|
||||
add(pictureBox, BorderLayout.CENTER);
|
||||
add(pictureBoxHard, BorderLayout.CENTER);
|
||||
add(buttonMakeObject, BorderLayout.SOUTH);
|
||||
setVisible(true);
|
||||
}
|
||||
void draw(){
|
||||
pictureBox.repaint();}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
public class FrameTrolleybus extends JFrame {
|
||||
private DrawingBus drawingBus;
|
||||
private AbstractStrategy abstractStrategy;
|
||||
@ -101,7 +100,7 @@ public class FrameTrolleybus extends JFrame {
|
||||
private void buttonCreateTrolleybusClick() {
|
||||
Random random = new Random();
|
||||
Color bodyColor = JColorChooser.showDialog(null,"Основной цвет", null);
|
||||
Color additColor = JColorChooser.showDialog(null,"Основной цвет", null);
|
||||
Color additColor = JColorChooser.showDialog(null,"Дополнительный цвет", null);
|
||||
pictureBoxTrolleybus.setBounds(0,0,getContentPane().getWidth(),getContentPane().getHeight());
|
||||
drawingBus = new DrawingTrolleybus(random.nextInt(200) + 100, random.nextInt(2000) + 1000,
|
||||
bodyColor, additColor, random.nextBoolean(), random.nextBoolean(), pictureBoxTrolleybus.getWidth(), pictureBoxTrolleybus.getHeight(),
|
||||
|
@ -3,55 +3,53 @@ import java.util.Random;
|
||||
public class HardGeneric <T extends EntityBus,U extends IDrawDoors> {
|
||||
T[] buses;
|
||||
U[] doors;
|
||||
private int count;
|
||||
private int busesCount;
|
||||
private int doorsCount;
|
||||
private int busesNumber;
|
||||
private int doorsNumber;
|
||||
private int pictureBoxWidth;
|
||||
private int pictureBoxHeight;
|
||||
public HardGeneric(int busesCount, int doorsCount, int width, int height) {
|
||||
count = 0;
|
||||
this.busesCount = busesCount;
|
||||
this.doorsCount = doorsCount;
|
||||
buses = (T[]) new EntityBus[this.busesCount];
|
||||
doors = (U[]) new IDrawDoors[this.doorsCount];
|
||||
busesNumber = 0;
|
||||
doorsNumber = 0;
|
||||
buses = (T[]) new EntityBus[busesCount];
|
||||
doors = (U[]) new IDrawDoors[doorsCount];
|
||||
pictureBoxHeight = height;
|
||||
pictureBoxWidth = width;
|
||||
}
|
||||
|
||||
public int insertBuses(T entityBus) {
|
||||
if (buses[busesCount - 1] != null)
|
||||
if (buses[buses.length - 1] != null)
|
||||
return -1;
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
for (int i = busesNumber - 1; i >= 0; i--) {
|
||||
buses[i + 1] = buses[i];
|
||||
doors[i + 1] = doors[i];
|
||||
}
|
||||
count++;
|
||||
busesNumber++;
|
||||
buses[0] = entityBus;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int insertDoors(U door) {
|
||||
if (doors[doorsCount - 1] != null)
|
||||
if (doors[doors.length - 1] != null)
|
||||
return -1;
|
||||
for (int i = doorsNumber - 1; i >= 0; i--) {
|
||||
doors[i + 1] = doors[i];
|
||||
}
|
||||
doorsNumber++;
|
||||
doors[0] = door;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public DrawingBus makeObject() {
|
||||
Random rand = new Random();
|
||||
int indBuses = rand.nextInt(0, count);
|
||||
int indDoors = rand.nextInt(0, count);
|
||||
EntityBus entity = buses[indBuses];
|
||||
IDrawDoors doors = this.doors[indDoors];
|
||||
EntityBus entity = buses[rand.nextInt(0, busesNumber)];
|
||||
IDrawDoors door = doors[rand.nextInt(0, doorsNumber)];
|
||||
if (entity instanceof EntityTrolleybus) {
|
||||
return new DrawingTrolleybus(entity.getSpeed(), entity.getWeight(), entity.getBodyColor(),
|
||||
((EntityTrolleybus) entity).getAdditionalColor(), ((EntityTrolleybus) entity).getRoga(),
|
||||
((EntityTrolleybus) entity).getBattery(), pictureBoxWidth, pictureBoxHeight, doors.getNumber(), doors.getType());
|
||||
((EntityTrolleybus) entity).getBattery(), pictureBoxWidth, pictureBoxHeight, door.getNumber(), door.getType());
|
||||
|
||||
}
|
||||
return new DrawingBus(entity.getSpeed(), entity.getWeight(), entity.getBodyColor(),
|
||||
pictureBoxWidth, pictureBoxHeight, doors.getNumber(), doors.getType());
|
||||
pictureBoxWidth, pictureBoxHeight, door.getNumber(), door.getType());
|
||||
}
|
||||
public EntityBus makeRandomBus() {
|
||||
Random random = new Random();
|
||||
|
@ -6,10 +6,10 @@ public class SetGeneric<T extends Object>{
|
||||
public SetGeneric(int count, Class<T> type){
|
||||
places = (T[]) Array.newInstance(type, count);
|
||||
}
|
||||
public boolean insert(T ship){
|
||||
return insert(ship, 0);
|
||||
public boolean insert(T bus){
|
||||
return insert(bus, 0);
|
||||
}
|
||||
public boolean insert(T ship, int position){
|
||||
public boolean insert(T bus, int position){
|
||||
if (!(position >= 0 && position < places.length))
|
||||
return false;
|
||||
if (places[position] != null)
|
||||
@ -22,7 +22,7 @@ public class SetGeneric<T extends Object>{
|
||||
for (int i = ind - 1; i >= position; i--)
|
||||
places[i + 1] = places[i];
|
||||
}
|
||||
places[position] = ship;
|
||||
places[position] = bus;
|
||||
return true;
|
||||
}
|
||||
public boolean remove(int position){
|
||||
|
Loading…
Reference in New Issue
Block a user