From f7be8b6d55a4d846df5d7d8d423cb10c3ff58810 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Sat, 18 Nov 2023 02:26:55 +0400 Subject: [PATCH] Lab3 Done done --- .idea/inspectionProfiles/Project_Default.xml | 10 ++++++ src/BusesGenericCollection.java | 4 +-- src/DrawingBus.java | 2 +- src/FrameBusCollection.java | 2 +- src/FrameHard.java | 12 +++---- src/FrameTrolleybus.java | 3 +- src/HardGeneric.java | 38 ++++++++++---------- src/SetGeneric.java | 8 ++--- 8 files changed, 41 insertions(+), 38 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..dfb9496 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/src/BusesGenericCollection.java b/src/BusesGenericCollection.java index 1487d8c..e6d8793 100644 --- a/src/BusesGenericCollection.java +++ b/src/BusesGenericCollection.java @@ -5,7 +5,6 @@ public class BusesGenericCollection _collection; - public BusesGenericCollection(int picWidth, int picHeight) { int width = picWidth / _placeSizeWidth; int height = picHeight / _placeSizeHeight; @@ -33,7 +32,7 @@ public class BusesGenericCollection buses; JComponent pictureBoxCollection; TextField textFieldNumber; - public FrameBusCollection() throws IOException{ + public FrameBusCollection(){ super("Набор автобусов"); setSize(new Dimension(900,500)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); diff --git a/src/FrameHard.java b/src/FrameHard.java index 9e83f7e..f5f9198 100644 --- a/src/FrameHard.java +++ b/src/FrameHard.java @@ -4,14 +4,14 @@ import java.util.Random; public class FrameHard extends JFrame{ HardGeneric 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();} } diff --git a/src/FrameTrolleybus.java b/src/FrameTrolleybus.java index 16138d0..1c39920 100644 --- a/src/FrameTrolleybus.java +++ b/src/FrameTrolleybus.java @@ -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(), diff --git a/src/HardGeneric.java b/src/HardGeneric.java index 6c27515..1620ad1 100644 --- a/src/HardGeneric.java +++ b/src/HardGeneric.java @@ -3,55 +3,53 @@ import java.util.Random; public class HardGeneric { 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(); diff --git a/src/SetGeneric.java b/src/SetGeneric.java index 593e1c5..127715a 100644 --- a/src/SetGeneric.java +++ b/src/SetGeneric.java @@ -6,10 +6,10 @@ public class SetGeneric{ public SetGeneric(int count, Class 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{ 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){