Лабораторная работа №3 (часть 2)

This commit is contained in:
DjonniStorm 2024-05-06 01:12:23 +04:00
parent 654d2e36e0
commit 88daf53b25
12 changed files with 255 additions and 83 deletions

View File

@ -14,24 +14,21 @@ public abstract class AbstractCompany {
protected int _pictureHeight; protected int _pictureHeight;
public ICollectionGenericObjects<DrawningTruck> _collection = null; public ICollectionGenericObjects<DrawningTruck> _collection = null;
private int GetMaxCount() { private int GetMaxCount() {
return _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); return _pictureWidth / _placeSizeWidth * (_pictureHeight / _placeSizeHeight / 2) - 1;
}; };
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTruck> collection) { public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTruck> collection) {
_pictureWidth = picWidth; _pictureWidth = picWidth;
_pictureHeight = picHeight; _pictureHeight = picHeight;
_collection = collection; _collection = collection;
_collection.SetMaxCount(GetMaxCount()); _collection.SetMaxCount(GetMaxCount(), (Class) DrawningTruck.class);
} }
public DrawningTruck GetRandomObject() { public DrawningTruck GetRandomObject() {
Random rnd = new Random(); Random rnd = new Random();
return _collection.Get(rnd.nextInt(GetMaxCount())); return _collection.Get(rnd.nextInt(GetMaxCount()));
} }
public JPanel Show(JPanel panel) { public void Show(Graphics g) {
BufferedImage bitmap = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = bitmap.createGraphics();
panel.paint(g);
DrawBackground(g); DrawBackground(g);
SetObjectsPosition(); SetObjectsPosition();
for (int i = 0; i < _collection.Count(); i++) { for (int i = 0; i < _collection.Count(); i++) {
@ -40,7 +37,6 @@ public abstract class AbstractCompany {
obj.DrawTransport(g); obj.DrawTransport(g);
} }
} }
return panel;
} }
protected abstract void DrawBackground(Graphics g); protected abstract void DrawBackground(Graphics g);

View File

@ -0,0 +1,63 @@
package CollectionGenericObjects;
import Drawnings.CountWheels;
import Drawnings.DrawningCleaningCar;
import Drawnings.DrawningTruck;
import Drawnings.IDrawningWheels;
import Entities.EntityCleaningCar;
import Entities.EntityTruck;
import java.lang.reflect.Array;
import java.util.Random;
public class AdditionalCollection <T extends EntityTruck, U extends IDrawningWheels>{
private T[] _collectionEntity;
private U[] _collectionWheels;
public AdditionalCollection(int value, Class<T> type1, Class<T> type2) {
_collectionEntity = (T[]) Array.newInstance(type1, value);
_collectionWheels = (U[]) Array.newInstance(type2, value);
}
public int GetCountEntities() {
return _collectionEntity.length;
}
public int GetCountWheels() {
return _collectionWheels.length;
}
public int Insert(T entity) {
for (int i = 0; i < GetCountEntities(); i++)
{
if (_collectionEntity[i] == null)
{
_collectionEntity[i] = entity;
return i;
}
}
return -1;
}
public int Insert(U decks) {
for (int i = 0; i < GetCountWheels(); i++)
{
if (_collectionWheels[i] == null)
{
_collectionWheels[i] = decks;
return i;
}
}
return -1;
}
public DrawningTruck CreateFromAdditionalCollection() {
Random random = new Random();
if (_collectionEntity == null || _collectionWheels == null) return null;
T entity = _collectionEntity[random.nextInt(GetCountEntities())];
U wheels = _collectionWheels[random.nextInt(GetCountWheels())];
DrawningTruck drawingTruck = null;
if (entity instanceof EntityCleaningCar) {
drawingTruck = new DrawningCleaningCar((EntityCleaningCar) entity, wheels);
}
else {
drawingTruck = new DrawningTruck(entity, wheels);
}
return drawingTruck;
}
}

View File

@ -10,16 +10,17 @@ public class AutoParkService extends AbstractCompany {
} }
@Override @Override
protected void DrawBackground(Graphics g) { protected void DrawBackground(Graphics g) {
// Pen pen = new Pen(Color.Black, 4f);
g.setColor(Color.black); g.setColor(Color.black);
((Graphics2D) g).setStroke(new BasicStroke(4));
for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++) for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++)
{ {
g.drawLine(0, i * _placeSizeHeight * 2, _pictureWidth / _placeSizeWidth * _placeSizeWidth, i * _placeSizeHeight * 2); g.drawLine(0, i * _placeSizeHeight * 2, _pictureWidth / _placeSizeWidth * _placeSizeWidth, i * _placeSizeHeight * 2);
for (int j = 0; j < _pictureWidth / _placeSizeWidth + 1; ++j) for (int j = 0; j < _pictureWidth / _placeSizeWidth + 1; ++j)
{ {
g.drawLine(j * _placeSizeWidth, i * _placeSizeHeight * 2, j * _placeSizeWidth, i * _placeSizeHeight * 2 + _placeSizeHeight); g.drawLine(j * _placeSizeWidth, i * _placeSizeHeight * 2, j * _placeSizeWidth, i * _placeSizeHeight * 2 + _placeSizeHeight + 20);
} }
} }
((Graphics2D) g).setStroke(new BasicStroke(1));
} }
@Override @Override

View File

@ -2,7 +2,7 @@ package CollectionGenericObjects;
public interface ICollectionGenericObjects<T> { public interface ICollectionGenericObjects<T> {
int Count(); int Count();
void SetMaxCount(int value); void SetMaxCount(int value, Class<T> type);
int Insert(T obj); int Insert(T obj);
int Insert(T obj, int position); int Insert(T obj, int position);
T Remove(int position); T Remove(int position);

View File

@ -1,86 +1,71 @@
package CollectionGenericObjects; package CollectionGenericObjects;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.ArrayList;
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{
private ArrayList<T> _collection; private T[] _collection;
@Override
public void SetMaxCount(int value, Class<T> type) {
if (value > 0) {
_collection = (T[]) Array.newInstance(type, value);
}
}
@Override @Override
public int Count() { public int Count() {
return _collection.size(); return _collection.length;
} }
@Override
public void SetMaxCount(int value) {
if (value > 0) {
if (!_collection.isEmpty()) {
ArrayList<T> tmp = new ArrayList<>(value);
tmp.addAll(0, _collection);
_collection = tmp;
for (int i = 0; ; i++) {
_collection.add(null);
}
} else {
_collection = new ArrayList<>(value);
for (int i = 0; i < value; i++) {
_collection.add(null);
}
}
}
}
public MassiveGenericObjects() {
_collection = new ArrayList<>();
}
@Override @Override
public int Insert(T obj) { public int Insert(T obj) {
for (int i = 0; i < Count(); i++) { for (int i = 0; i < Count(); i++)
if (_collection.get(i) == null) { {
_collection.add(i, obj); if (_collection[i] == null)
{
_collection[i] = obj;
return i; return i;
} }
} }
return -1; return -1;
} }
@Override @Override
public int Insert(T obj, int position) { public int Insert(T obj, int position) {
if (position >= Count() || position < 0) return -1; if (position >= Count() || position < 0) return -1;
if (_collection.get(position) == null) { if (_collection[position] == null)
_collection.add(position, obj); {
_collection[position] = obj;
return position; return position;
} }
int tmp = position + 1; int temp = position + 1;
while (tmp < Count()) { while(temp < Count())
if (_collection.get(tmp) == null) { {
_collection.add(tmp, obj); if (_collection[temp] == null)
return tmp; {
_collection[temp] = obj;
return temp;
} }
++tmp; ++temp;
} }
tmp = position - 1; temp = position - 1;
while (tmp >= 0) { while(temp >= 0)
if (_collection.get(tmp) == null) { {
_collection.add(tmp, obj); if (_collection[temp] == null)
return tmp; {
_collection[temp] = obj;
return temp;
} }
--tmp; --temp;
} }
return -1; return -1;
} }
@Override @Override
public T Remove(int position) { public T Remove(int position) {
if (position >= Count() || position < 0) return null; if (position >= Count() || position < 0) return null;
T myObject = _collection.get(position); T myObject = (T) _collection[position];
_collection.add(position, null); _collection[position] = null;
return myObject; return myObject;
} }
@Override @Override
public T Get(int position) { public T Get(int position) {
if (position < 0 || position >= Count()) return null; if (position < 0 || position >= Count()) return null;
return _collection.get(position); return (T) _collection[position];
} }
} }

View File

@ -12,6 +12,11 @@ public class DrawningCleaningCar extends DrawningTruck {
super.SetWheelsType(); super.SetWheelsType();
} }
public DrawningCleaningCar(EntityCleaningCar cleaningCar, IDrawningWheels drawningWheels) {
EntityTruck = cleaningCar;
this.drawningWheels = drawningWheels;
}
@Override @Override
public void DrawTransport(Graphics g) { public void DrawTransport(Graphics g) {
if (EntityTruck == null || !(EntityTruck instanceof EntityCleaningCar cleaningCar) || _startPosX == null || _startPosY == null) { if (EntityTruck == null || !(EntityTruck instanceof EntityCleaningCar cleaningCar) || _startPosX == null || _startPosY == null) {

View File

@ -22,13 +22,17 @@ public class DrawningTruck {
public int GetPosY(){return _startPosY;} public int GetPosY(){return _startPosY;}
public int GetWidth(){return _drawningCarWidth;} public int GetWidth(){return _drawningCarWidth;}
public int GetHeight(){return _drawningCarHeight;} public int GetHeight(){return _drawningCarHeight;}
private DrawningTruck() { protected DrawningTruck() {
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
_startPosX = null; _startPosX = null;
_startPosY = null; _startPosY = null;
} }
public DrawningTruck(EntityTruck truck, IDrawningWheels drawningWheels) {
EntityTruck = truck;
this.drawningWheels = drawningWheels;
}
protected void SetWheelsType() { protected void SetWheelsType() {
Random random = new Random(); Random random = new Random();
switch (random.nextInt(1, 4)) { switch (random.nextInt(1, 4)) {

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormAdditionalCollection">
<grid id="27dc6" binding="defaultPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<vspacer id="6ae24">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="d0d65" class="javax.swing.JList" binding="listEntity">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
<maximum-size width="-1" height="200"/>
</grid>
</constraints>
<properties/>
</component>
<component id="3d508" class="javax.swing.JList" binding="listWheels">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
<maximum-size width="-1" height="200"/>
</grid>
</constraints>
<properties/>
</component>
<component id="6d472" class="javax.swing.JButton" binding="buttonCreate">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="100"/>
<maximum-size width="200" height="100"/>
</grid>
</constraints>
<properties>
<font name="Roboto Light" size="28" style="1"/>
<text value="Создать"/>
</properties>
</component>
<grid id="d47fe" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<vspacer id="ff720">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>

View File

@ -0,0 +1,27 @@
import CollectionGenericObjects.AdditionalCollection;
import Drawnings.IDrawningWheels;
import Entities.EntityTruck;
import javax.swing.*;
public class FormAdditionalCollection extends JFrame {
private JPanel defaultPanel;
private JButton buttonCreate;
private JList listEntity;
private JList listWheels;
private AdditionalCollection<EntityTruck, IDrawningWheels> additionalCollection;
public FormAdditionalCollection() {
setTitle("Создать форму, где использовался бы экземпляр от описанного выше " +
"параметризованного класса и выдавал сгенерированные экземпляры " +
"класса прорисовки с выводом результата на форму");
setLocation(200, 100);
pack();
setVisible(true);
add(defaultPanel);
setSize(1000, 600);
additionalCollection = new AdditionalCollection<>(3, (Class) EntityTruck.class, (Class) IDrawningWheels.class);
}
}

View File

@ -23,13 +23,24 @@ public class FormCleaningCar extends JFrame {
private List<JComponent> controls; private List<JComponent> controls;
private AbstractStrategy _strategy; private AbstractStrategy _strategy;
@Override
public void paint(Graphics g) {
super.paint(g);
if (_drawningTruck.getEntityTruck() == null ||
pictureBox.getWidth() == 0 || pictureBox.getHeight() == 0)
return;
Graphics e = pictureBox.getGraphics();
e.setColor(pictureBox.getBackground());
e.fillRect(0,0, pictureBox.getWidth(), pictureBox.getHeight());
_drawningTruck.DrawTransport(e);
RepaintControls();
}
public void SetTruck(DrawningTruck truck) { public void SetTruck(DrawningTruck truck) {
_drawningTruck = truck; _drawningTruck = truck;
_drawningTruck.SetPictureSize(pictureBox.getWidth(), pictureBox.getHeight()); _drawningTruck.SetPictureSize(pictureBox.getWidth(), pictureBox.getHeight());
comboBoxStrategy.setEnabled(true); comboBoxStrategy.setEnabled(true);
_strategy = null; _strategy = null;
Draw(); repaint(); //по-идее вызовет paint()
} }
public FormCleaningCar() { public FormCleaningCar() {
setSize(1000, 600); setSize(1000, 600);
@ -37,7 +48,6 @@ public class FormCleaningCar extends JFrame {
setTitle("Project Cleaning Car"); setTitle("Project Cleaning Car");
add(pictureBox); add(pictureBox);
setVisible(true); setVisible(true);
pictureBox.setSize(getWidth(), getHeight());
buttonUp.setName("buttonUp"); buttonUp.setName("buttonUp");
buttonDown.setName("buttonDown"); buttonDown.setName("buttonDown");
buttonLeft.setName("buttonLeft"); buttonLeft.setName("buttonLeft");

View File

@ -16,19 +16,9 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="3599f" class="javax.swing.JLabel" binding="toolsNameLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
<maximum-size width="-1" height="20"/>
</grid>
</constraints>
<properties>
<text value="Инструменты"/>
</properties>
</component>
<component id="112e" class="javax.swing.JButton" binding="buttonAddCleaningCar"> <component id="112e" class="javax.swing.JButton" binding="buttonAddCleaningCar">
<constraints> <constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<text value="Добавление уборочной машины"/> <text value="Добавление уборочной машины"/>
@ -36,7 +26,7 @@
</component> </component>
<component id="8fa47" class="javax.swing.JFormattedTextField" binding="maskedTextBox"> <component id="8fa47" class="javax.swing.JFormattedTextField" binding="maskedTextBox">
<constraints> <constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="50" height="-1"/> <preferred-size width="50" height="-1"/>
</grid> </grid>
</constraints> </constraints>
@ -44,7 +34,7 @@
</component> </component>
<component id="af87b" class="javax.swing.JButton" binding="buttonDel"> <component id="af87b" class="javax.swing.JButton" binding="buttonDel">
<constraints> <constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<text value="Удалить грузовик"/> <text value="Удалить грузовик"/>
@ -52,7 +42,7 @@
</component> </component>
<component id="5a95" class="javax.swing.JButton" binding="buttonAddTruck"> <component id="5a95" class="javax.swing.JButton" binding="buttonAddTruck">
<constraints> <constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<text value="Добавление грузовика"/> <text value="Добавление грузовика"/>
@ -60,7 +50,7 @@
</component> </component>
<component id="f051c" class="javax.swing.JComboBox" binding="comboBoxSelectorCompany"> <component id="f051c" class="javax.swing.JComboBox" binding="comboBoxSelectorCompany">
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<maximum-size width="-1" height="70"/> <maximum-size width="-1" height="70"/>
</grid> </grid>
</constraints> </constraints>
@ -70,7 +60,7 @@
</component> </component>
<component id="7c328" class="javax.swing.JButton" binding="buttonGoToCheck"> <component id="7c328" class="javax.swing.JButton" binding="buttonGoToCheck">
<constraints> <constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<text value="Передать на тесты"/> <text value="Передать на тесты"/>
@ -78,12 +68,20 @@
</component> </component>
<component id="44aef" class="javax.swing.JButton" binding="buttonRefresh"> <component id="44aef" class="javax.swing.JButton" binding="buttonRefresh">
<constraints> <constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<text value="Обновить"/> <text value="Обновить"/>
</properties> </properties>
</component> </component>
<component id="5f2f8" class="javax.swing.JButton" binding="buttonAdditionalCollection">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Что-то"/>
</properties>
</component>
</children> </children>
</grid> </grid>
<grid id="abc4c" binding="pictureBox" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="abc4c" binding="pictureBox" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">

View File

@ -9,7 +9,6 @@ import javax.swing.text.MaskFormatter;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.text.ParseException; import java.text.ParseException;
import java.util.Random; import java.util.Random;
@ -19,7 +18,6 @@ public class FormCleaningCarCollection extends JFrame{
private AbstractCompany _company = null; private AbstractCompany _company = null;
private JPanel panel; private JPanel panel;
private JPanel tools; private JPanel tools;
private JLabel toolsNameLabel;
private JComboBox comboBoxSelectorCompany; private JComboBox comboBoxSelectorCompany;
private JButton buttonAddTruck; private JButton buttonAddTruck;
private JButton buttonAddCleaningCar; private JButton buttonAddCleaningCar;
@ -28,6 +26,8 @@ public class FormCleaningCarCollection extends JFrame{
private JButton buttonDel; private JButton buttonDel;
private JButton buttonGoToCheck; private JButton buttonGoToCheck;
private JButton buttonRefresh; private JButton buttonRefresh;
private JButton buttonAdditionalCollection;
public FormCleaningCarCollection() { public FormCleaningCarCollection() {
setTitle("Коллекция уборочных машин"); setTitle("Коллекция уборочных машин");
setSize(1000, 600); setSize(1000, 600);
@ -38,6 +38,7 @@ public class FormCleaningCarCollection extends JFrame{
tools.setBackground(new Color(220, 220, 220)); tools.setBackground(new Color(220, 220, 220));
tools.setBorder(BorderFactory.createTitledBorder("Инструменты"));
comboBoxSelectorCompany.addItem(new String("")); comboBoxSelectorCompany.addItem(new String(""));
comboBoxSelectorCompany.addItem(new String("Автопарк")); comboBoxSelectorCompany.addItem(new String("Автопарк"));
//mask //mask
@ -88,13 +89,14 @@ public class FormCleaningCarCollection extends JFrame{
int pos = parseInt(maskedTextBox.getText()); int pos = parseInt(maskedTextBox.getText());
if (_company._collection.Remove(pos) != null) { if (_company._collection.Remove(pos) != null) {
JOptionPane.showMessageDialog(null, "Объект удалён"); JOptionPane.showMessageDialog(null, "Объект удалён");
repaint();
} else { } else {
JOptionPane.showMessageDialog(null, "Не удалось удалить объект"); JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
} }
break; break;
case 1: case 1:
default:
return; return;
} }
} }
@ -121,6 +123,17 @@ public class FormCleaningCarCollection extends JFrame{
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (_company == null) return; if (_company == null) return;
repaint();
}
});
buttonAdditionalCollection.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_company == null)
{
return;
}
FormAdditionalCollection formAdditionalCollection = new FormAdditionalCollection();
} }
}); });
@ -143,7 +156,6 @@ public class FormCleaningCarCollection extends JFrame{
} }
if (_company._collection.Insert(drawningTruck, 0) != -1) { if (_company._collection.Insert(drawningTruck, 0) != -1) {
JOptionPane.showMessageDialog(null, "Объект добавлен"); JOptionPane.showMessageDialog(null, "Объект добавлен");
pictureBox = _company.Show(pictureBox);
repaint(); repaint();
} else { } else {
JOptionPane.showMessageDialog(null, "Не удалось добавить объект"); JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
@ -154,4 +166,13 @@ public class FormCleaningCarCollection extends JFrame{
Color colorChooser = JColorChooser.showDialog(this, "Выберите цвет", color); Color colorChooser = JColorChooser.showDialog(this, "Выберите цвет", color);
return colorChooser; return colorChooser;
} }
@Override
public void paint(Graphics g) {
super.paint(g);
if (_company == null) return;
Graphics e = pictureBox.getGraphics();
e.setColor(pictureBox.getBackground());
e.fillRect(0,0, pictureBox.getWidth(), pictureBox.getHeight());
_company.Show(e);
}
} }