Fixes
This commit is contained in:
parent
bea4da357c
commit
cd2b9474d4
@ -3,7 +3,7 @@ import java.awt.*;
|
|||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class FormArtillery extends JFrame {
|
public class FormArtillery extends JDialog {
|
||||||
private JPanel artilleryPane;
|
private JPanel artilleryPane;
|
||||||
private JLabel speedLabel;
|
private JLabel speedLabel;
|
||||||
private JLabel weightLabel;
|
private JLabel weightLabel;
|
||||||
@ -15,7 +15,7 @@ public class FormArtillery extends JFrame {
|
|||||||
private JButton buttonLeft;
|
private JButton buttonLeft;
|
||||||
private JButton buttonRight;
|
private JButton buttonRight;
|
||||||
private JButton createAdvancedButton;
|
private JButton createAdvancedButton;
|
||||||
private JButton buttonSelect;
|
public JButton buttonSelect;
|
||||||
|
|
||||||
private DrawingArtillery _artillery;
|
private DrawingArtillery _artillery;
|
||||||
private DrawingArtillery selectedArtillery;
|
private DrawingArtillery selectedArtillery;
|
||||||
@ -86,7 +86,7 @@ public class FormArtillery extends JFrame {
|
|||||||
});
|
});
|
||||||
buttonSelect.addActionListener(e -> {
|
buttonSelect.addActionListener(e -> {
|
||||||
selectedArtillery = _artillery;
|
selectedArtillery = _artillery;
|
||||||
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
|
dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
161
FormMapWithSetArtilleries.form
Normal file
161
FormMapWithSetArtilleries.form
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetArtilleries">
|
||||||
|
<grid id="27dc6" binding="paneArtilleries" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||||
|
<xy x="20" y="20" width="613" height="400"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="fcfe1" 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="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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="f232" binding="toolsGroup" layout-manager="GridLayoutManager" row-count="9" 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="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="d7a62" class="javax.swing.JLabel" binding="toolsLabel">
|
||||||
|
<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>
|
||||||
|
<text value="Инструменты"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="1c91f">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<vspacer id="352bc">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<component id="6a0f5" class="javax.swing.JComboBox" binding="comboBoxMapSelector">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<model>
|
||||||
|
<item value="Простая карта"/>
|
||||||
|
<item value="Лесная карта"/>
|
||||||
|
</model>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="52049" class="javax.swing.JButton" binding="buttonAddArtillery">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Добавить артиллерию"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="2f9ed" class="javax.swing.JFormattedTextField" binding="textBoxPosition">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="1dbb5" class="javax.swing.JButton" binding="buttonRemoveArtillery">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<actionCommand value=""/>
|
||||||
|
<text value="Удалить артиллерию"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="4e6ca" class="javax.swing.JButton" binding="buttonShowStorage">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Посмотреть хранилище"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="51371" class="javax.swing.JButton" binding="buttonShowOnMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Посмотреть карту"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="fb3e4" class="javax.swing.JButton" binding="buttonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="7" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<borderPainted value="true"/>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowUp.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="328f6" class="javax.swing.JButton" binding="buttonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" 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="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowDown.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="4f2dc" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" column="1" 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="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowLeft.png"/>
|
||||||
|
<label value=""/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="bac06" class="javax.swing.JButton" binding="buttonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" column="3" 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="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowRight.png"/>
|
||||||
|
<label value=""/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
150
FormMapWithSetArtilleries.java
Normal file
150
FormMapWithSetArtilleries.java
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.text.DefaultFormatterFactory;
|
||||||
|
import javax.swing.text.MaskFormatter;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
public class FormMapWithSetArtilleries extends JFrame {
|
||||||
|
private JPanel pictureBox;
|
||||||
|
private JPanel toolsGroup;
|
||||||
|
private JLabel toolsLabel;
|
||||||
|
private JComboBox comboBoxMapSelector;
|
||||||
|
private JButton buttonAddArtillery;
|
||||||
|
private JPanel paneArtilleries;
|
||||||
|
private JFormattedTextField textBoxPosition;
|
||||||
|
private JButton buttonRemoveArtillery;
|
||||||
|
private JButton buttonShowStorage;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JButton buttonShowOnMap;
|
||||||
|
|
||||||
|
private Image bufferedImage;
|
||||||
|
private MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap> _mapArtilleriesCollectionGeneric;
|
||||||
|
|
||||||
|
public FormMapWithSetArtilleries() {
|
||||||
|
this.setTitle("Artillery");
|
||||||
|
this.setContentPane(paneArtilleries);
|
||||||
|
|
||||||
|
try {
|
||||||
|
textBoxPosition.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("##")));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
comboBoxMapSelector.addActionListener(e -> {
|
||||||
|
AbstractMap map = switch (((JComboBox) e.getSource()).getSelectedItem().toString()) {
|
||||||
|
case "Простая карта" -> new SimpleMap();
|
||||||
|
case "Лесная карта" -> new ForestMap();
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (map != null) {
|
||||||
|
_mapArtilleriesCollectionGeneric = new MapWithSetArtilleriesGeneric<>(pictureBox.getWidth(), pictureBox.getHeight(), map);
|
||||||
|
} else {
|
||||||
|
_mapArtilleriesCollectionGeneric = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonAddArtillery.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric == null) {
|
||||||
|
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 car = new DrawingObjectArtillery(dialog.getSelectedArtillery());
|
||||||
|
if (_mapArtilleriesCollectionGeneric.addArtillery(car) != -1)
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.showSet();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Провал", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonRemoveArtillery.addActionListener(e -> {
|
||||||
|
String text = textBoxPosition.getText();
|
||||||
|
if (text == null || text.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (JOptionPane.showConfirmDialog(this, "Удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int position = Integer.parseInt(text);
|
||||||
|
|
||||||
|
if (_mapArtilleriesCollectionGeneric.removeArtilleryAt(position) != null) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Объект удалён", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.showSet();
|
||||||
|
repaint();
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this, "Не удалось удалить объект", "Провал", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonShowStorage.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.showSet();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonShowOnMap.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.showOnMap();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonLeft.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric != null) {
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Left);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonRight.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric != null) {
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Right);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonUp.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric != null) {
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Up);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonDown.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric != null) {
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Down);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
|
||||||
|
if (bufferedImage != null) {
|
||||||
|
pictureBox.paintComponents(bufferedImage.getGraphics());
|
||||||
|
pictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@ import javax.swing.*;
|
|||||||
|
|
||||||
public class Program {
|
public class Program {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
FormMap form = new FormMap();
|
FormMapWithSetArtilleries form = new FormMapWithSetArtilleries();
|
||||||
form.setSize(640, 480);
|
form.setSize(640, 480);
|
||||||
form.setVisible(true);
|
form.setVisible(true);
|
||||||
form.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
form.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
Loading…
Reference in New Issue
Block a user