Polevoy S.V Lab_work5 #5

Closed
ChipsEater wants to merge 4 commits from LabWork05 into LabWork04
10 changed files with 567 additions and 22 deletions

View File

@ -29,4 +29,15 @@ public class DrawingAdvancedArtillery extends DrawingArtillery {
}
super.drawTransport(g);
}
@Override
public void setColor(Color color) {
var art = (EntityAdvancedArtillery) artillery;
artillery = new EntityAdvancedArtillery(art.getSpeed(), art.getWeight(), color, art.getDopColor(), art.getWeapon(), art.getSalvoBattery());
}
public void setDopColor(Color color) {
var art = (EntityAdvancedArtillery) artillery;
artillery = new EntityAdvancedArtillery(art.getSpeed(), art.getWeight(), art.getBodyColor(), color, art.getWeapon(), art.getSalvoBattery());
}
}

View File

@ -14,6 +14,10 @@ public class DrawingArtillery {
return artillery;
}
public IDrawingRollers getRollers() {
return drawingRollers;
}
public DrawingArtillery(int speed, float weight, Color bodyColor, int rollersCount) {
artillery = new EntityArtillery(speed, weight, bodyColor);
drawingRollers = RollersType.random(rollersCount, bodyColor);
@ -123,4 +127,12 @@ public class DrawingArtillery {
public float[] getCurrentPosition() {
return new float[] { _startPosX, _startPosX + _artilleryWidth - 1, _startPosY, _startPosY + _artilleryHeight -1 };
}
public void setColor(Color color) {
artillery = new EntityArtillery(artillery.getSpeed(), artillery.getWeight(), color);
}
public void setRollers(IDrawingRollers rollers) {
drawingRollers = rollers;
}
}

View File

@ -79,4 +79,8 @@ public class DrawingCrossRollers implements IDrawingRollers {
}
}
}
public void setColor(Color color) {
this.color = color;
}
}

View File

@ -36,4 +36,8 @@ public class DrawingRollers implements IDrawingRollers {
}
}
}
public void setColor(Color color) {
this.color = color;
}
}

View File

@ -104,4 +104,8 @@ public class DrawingSquaredRollers implements IDrawingRollers {
}
}
}
public void setColor(Color color) {
this.color = color;
}
}

16
EventListener.java Normal file
View File

@ -0,0 +1,16 @@
import java.util.ArrayList;
import java.util.function.Consumer;
public class EventListener<T> {
private final ArrayList<Consumer<T>> listeners = new ArrayList<>();
public void addListener(Consumer<T> listener) {
listeners.add(listener);
}
public void emit(T artillery) {
for (var listener : listeners) {
listener.accept(artillery);
}
}
}

341
FormArtilleryConfig.form Normal file
View File

@ -0,0 +1,341 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormArtilleryConfig">
<grid id="27dc6" binding="contentPanel" 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="878" height="437"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="fdfc8" binding="toolsPanel" layout-manager="GridLayoutManager" row-count="7" column-count="4" 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="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Параметры"/>
<children>
<component id="6962a" class="javax.swing.JLabel" binding="speedLabel">
<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"/>
</constraints>
<properties>
<labelFor value="27572"/>
<text value="Скорость:"/>
</properties>
</component>
<component id="27572" class="javax.swing.JSpinner" binding="speedSpinner">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="871d8" class="javax.swing.JLabel" binding="weightLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="8e1be"/>
<text value="Вес:"/>
</properties>
</component>
<component id="8e1be" class="javax.swing.JSpinner" binding="weightSpinner">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="39e94" class="javax.swing.JCheckBox" binding="checkBoxWeapon">
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Признак наличия орудия"/>
</properties>
</component>
<component id="9d114" class="javax.swing.JCheckBox" binding="checkBoxSalvoBattery">
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Признак наличия залповой батареи"/>
</properties>
</component>
<grid id="2044c" binding="colorsPanel" layout-manager="GridLayoutManager" row-count="2" column-count="4" 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="2" row-span="5" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Цвета"/>
<children>
<grid id="784a6" binding="redPanel" 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="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="60" height="60"/>
<maximum-size width="60" height="60"/>
</grid>
</constraints>
<properties>
<background color="-65536"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="abece" binding="greenPanel" 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="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="60" height="60"/>
<maximum-size width="60" height="60"/>
</grid>
</constraints>
<properties>
<background color="-16711936"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="b2eb9" binding="bluePanel" 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="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="60" height="60"/>
<maximum-size width="60" height="60"/>
</grid>
</constraints>
<properties>
<background color="-16776961"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="482a4" binding="yellowPanel" 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="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="60" height="60"/>
<maximum-size width="60" height="60"/>
</grid>
</constraints>
<properties>
<background color="-723926"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="1692f" binding="whitePanel" 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="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="60" height="60"/>
<maximum-size width="60" height="60"/>
</grid>
</constraints>
<properties>
<background color="-1"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="aaf16" binding="grayPanel" 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="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="60" height="60"/>
<maximum-size width="60" height="60"/>
</grid>
</constraints>
<properties>
<background color="-10527145"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="d1a3c" binding="blackPanel" 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="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="60" height="60"/>
<maximum-size width="60" height="60"/>
</grid>
</constraints>
<properties>
<background color="-16777216"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="e81e" binding="purplePanel" 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="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="60" height="60"/>
<maximum-size width="60" height="60"/>
</grid>
</constraints>
<properties>
<background color="-5173091"/>
</properties>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<grid id="f974a" binding="rollersPanel" 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>
<grid row="6" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Катки"/>
<children>
<component id="a92b0" class="javax.swing.JLabel" binding="rollersLabel">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="be4e0"/>
<text value="Количество катков:"/>
</properties>
</component>
<component id="be4e0" class="javax.swing.JSpinner" binding="rollersSpinner">
<constraints>
<grid row="0" column="1" row-span="3" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<maximum-size width="120" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="9f9ab" class="javax.swing.JLabel" binding="baseRollersLabel">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="100" height="38"/>
<maximum-size width="100" height="38"/>
</grid>
</constraints>
<properties>
<font size="16"/>
<text value="Простые"/>
</properties>
</component>
<component id="ea1ae" class="javax.swing.JLabel" binding="crossRollersLabel">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="120" height="38"/>
<maximum-size width="120" height="38"/>
</grid>
</constraints>
<properties>
<font size="16"/>
<text value="С крестиками"/>
</properties>
</component>
<component id="15683" class="javax.swing.JLabel" binding="squaredRollersLabel">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="120" height="38"/>
<maximum-size width="120" height="38"/>
</grid>
</constraints>
<properties>
<font size="16"/>
<text value="С квадратами"/>
</properties>
</component>
</children>
</grid>
<component id="9f748" class="javax.swing.JLabel" binding="baseLabel">
<constraints>
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="100" height="38"/>
<maximum-size width="100" height="38"/>
</grid>
</constraints>
<properties>
<background color="-4720538"/>
<font size="16"/>
<text value="Простой"/>
</properties>
</component>
<component id="7569d" class="javax.swing.JLabel" binding="advancedLabel">
<constraints>
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="100" height="38"/>
<maximum-size width="120" height="38"/>
</grid>
</constraints>
<properties>
<font size="16"/>
<text value="Продвинутый"/>
</properties>
</component>
</children>
</grid>
<grid id="1a87d" binding="workspacePanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" 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="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Предпоказ"/>
<children>
<component id="18903" class="javax.swing.JLabel" binding="colorLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="100" height="38"/>
<maximum-size width="100" height="38"/>
</grid>
</constraints>
<properties>
<font size="16"/>
<text value="Цвет"/>
</properties>
</component>
<component id="fc724" class="javax.swing.JLabel" binding="additionalColorLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="100" height="38"/>
<maximum-size width="100" height="38"/>
</grid>
</constraints>
<properties>
<font size="16"/>
<text value="Доп. цвет"/>
</properties>
</component>
<grid id="47b0f" binding="pictureBox" 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="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="200" height="200"/>
<maximum-size width="200" height="200"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<component id="df1e6" class="javax.swing.JButton" binding="buttonAdd">
<constraints>
<grid row="1" column="1" row-span="2" 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>
<component id="22a26" class="javax.swing.JButton" binding="buttonCancel">
<constraints>
<grid row="1" column="2" row-span="2" 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>
</grid>
</form>

155
FormArtilleryConfig.java Normal file
View File

@ -0,0 +1,155 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.util.function.Consumer;
public class FormArtilleryConfig extends JFrame {
private final EventListener<DrawingArtillery> eventHandler = new EventListener<>();
private DrawingArtillery artillery;
private JPanel contentPanel;
private JPanel toolsPanel;
private JPanel workspacePanel;
private JButton buttonAdd;
private JButton buttonCancel;
private JLabel colorLabel;
private JLabel additionalColorLabel;
private JPanel pictureBox;
private JLabel speedLabel;
private JSpinner speedSpinner;
private JLabel weightLabel;
private JSpinner weightSpinner;
private JCheckBox checkBoxWeapon;
private JCheckBox checkBoxSalvoBattery;
private JPanel colorsPanel;
private JPanel redPanel;
private JPanel greenPanel;
private JPanel bluePanel;
private JPanel yellowPanel;
private JPanel whitePanel;
private JPanel grayPanel;
private JPanel blackPanel;
private JPanel purplePanel;
private JPanel rollersPanel;
private JLabel rollersLabel;
private JSpinner rollersSpinner;
private JLabel baseLabel;
private JLabel advancedLabel;
private JLabel baseRollersLabel;
private JLabel crossRollersLabel;
private JLabel squaredRollersLabel;
public FormArtilleryConfig() {
this.setTitle("Создание объекта");
this.setSize(840, 480);
this.setContentPane(contentPanel);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
// Создание границ
colorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
additionalColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
pictureBox.setBorder(BorderFactory.createDashedBorder(Color.BLACK));
baseLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
advancedLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
baseRollersLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
crossRollersLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
squaredRollersLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
// Задание ограничений
rollersSpinner.setModel(new SpinnerNumberModel(4, 4, 6, 1));
speedSpinner.setModel(new SpinnerNumberModel(100, 100, 1000, 1));
weightSpinner.setModel(new SpinnerNumberModel(100, 100, 1000, 1));
// Создание обработчиков
var dragAdapter = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
super.mouseReleased(e);
setCursor(new Cursor(Cursor.HAND_CURSOR));
}
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
dispatchDrop((JComponent) e.getSource());
}
};
// Задание обработчиков
redPanel.addMouseListener(dragAdapter);
greenPanel.addMouseListener(dragAdapter);
bluePanel.addMouseListener(dragAdapter);
yellowPanel.addMouseListener(dragAdapter);
whitePanel.addMouseListener(dragAdapter);
grayPanel.addMouseListener(dragAdapter);
blackPanel.addMouseListener(dragAdapter);
purplePanel.addMouseListener(dragAdapter);
baseLabel.addMouseListener(dragAdapter);
advancedLabel.addMouseListener(dragAdapter);
baseRollersLabel.addMouseListener(dragAdapter);
crossRollersLabel.addMouseListener(dragAdapter);
squaredRollersLabel.addMouseListener(dragAdapter);
buttonAdd.addActionListener(e -> {
eventHandler.emit(artillery);
dispose();
});
buttonCancel.addActionListener(e -> dispose());
}
public void addListener(Consumer<DrawingArtillery> listener) {
eventHandler.addListener(listener);
}
public void dispatchDrop(JComponent droppedComponent) {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if (droppedComponent == null) {
return;
}
if (droppedComponent instanceof JPanel panel) {
if (colorLabel.getMousePosition() != null) {
artillery.setColor(panel.getBackground());
artillery.getRollers().setColor(panel.getBackground());
}
if (additionalColorLabel.getMousePosition() != null && artillery instanceof DrawingAdvancedArtillery advanced) {
advanced.setDopColor(panel.getBackground());
}
}
if (droppedComponent instanceof JLabel label && pictureBox.getMousePosition() != null) {
int speed = (Integer) speedSpinner.getValue();
int weight = (Integer) weightSpinner.getValue();
int rollersCount = (Integer) rollersSpinner.getValue();
boolean weapon = checkBoxWeapon.isSelected();
boolean salvoBattery = checkBoxSalvoBattery.isSelected();
if (label == baseLabel) {
artillery = new DrawingArtillery(speed, weight, Color.WHITE, rollersCount);
} else if (label == advancedLabel) {
artillery = new DrawingAdvancedArtillery(speed, weight, Color.WHITE, rollersCount, Color.WHITE, weapon, salvoBattery);
} else if (artillery != null && label == baseRollersLabel) {
artillery.setRollers(new DrawingRollers(rollersCount, artillery.getArtillery().getBodyColor()));
} else if (artillery != null && label == crossRollersLabel) {
artillery.setRollers(new DrawingCrossRollers(rollersCount, artillery.getArtillery().getBodyColor()));
} else if (artillery != null && label == squaredRollersLabel) {
artillery.setRollers(new DrawingSquaredRollers(rollersCount, artillery.getArtillery().getBodyColor()));
}
}
repaint();
}
@Override
public void paint(Graphics g) {
super.paint(g);
if (artillery != null) {
g = pictureBox.getGraphics();
artillery.setPosition(60, 75, pictureBox.getWidth(), pictureBox.getHeight());
artillery.drawTransport((Graphics2D) g);
}
}
}

View File

@ -89,30 +89,27 @@ public class FormMapWithSetArtilleries extends JFrame {
});
buttonAddArtillery.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() == -1) {
return;
}
FormArtillery dialog = new FormArtillery();
dialog.setSize(800, 500);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
if (dialog.getSelectedArtillery() != null) {
DrawingObjectArtillery artillery = new DrawingObjectArtillery(dialog.getSelectedArtillery());
if (_mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).addArtillery(artillery) != -1)
{
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
repaint();
FormArtilleryConfig form = new FormArtilleryConfig();
form.addListener(artillery -> {
if (listBoxMaps.getSelectedIndex() == -1) {
return;
}
else
{
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Провал", JOptionPane.INFORMATION_MESSAGE);
if (artillery != null) {
DrawingObjectArtillery objectArtillery = new DrawingObjectArtillery(artillery);
if (_mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).addArtillery(objectArtillery) != -1)
{
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
repaint();
}
else
{
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Провал", JOptionPane.INFORMATION_MESSAGE);
}
}
}
});
form.setVisible(true);
});
buttonRemoveArtillery.addActionListener(e -> {

View File

@ -2,5 +2,6 @@ import java.awt.*;
public interface IDrawingRollers {
void setRollersCount(int num);
void setColor(Color color);
void draw(Graphics2D g, int x, int y, int artilleryWidth, int artilleryHeight);
}