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