Новая форма

This commit is contained in:
prodigygirl 2022-10-25 11:46:16 +04:00
parent a88bc283c7
commit 018364f793
2 changed files with 271 additions and 0 deletions

View File

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithArmoredCars">
<grid id="27dc6" binding="mainPanel" 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>
<xy x="20" y="20" width="887" height="526"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="d36a5" binding="btnPanel" layout-manager="GridLayoutManager" row-count="8" 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="0" column="1" 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>
<component id="abbc4" class="javax.swing.JButton" binding="buttonAddArmoredCar">
<constraints>
<grid row="1" column="0" 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="ab78e" class="javax.swing.JButton" binding="buttonRemoveArmoredCar">
<constraints>
<grid row="3" column="0" 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="28eda" class="javax.swing.JButton" binding="buttonShowStorage">
<constraints>
<grid row="4" column="0" 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="633b9" class="javax.swing.JButton" binding="buttonShowOnMap">
<constraints>
<grid row="5" column="0" 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="30614" class="javax.swing.JTextField" binding="maskedTextBoxPosition">
<constraints>
<grid row="2" column="0" 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="4f2a5" class="javax.swing.JComboBox" binding="mapSelectorComboBox">
<constraints>
<grid row="0" column="0" 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="Карта 1"/>
<item value="Карта 2"/>
</model>
</properties>
</component>
<component id="bf66e" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
<hideActionText value="true"/>
<icon value="Up.png"/>
<text value=""/>
</properties>
</component>
<component id="56422" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="Down.png"/>
<text value=""/>
</properties>
</component>
<component id="f47b8" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="Right.png"/>
<text value=""/>
</properties>
</component>
<component id="a0cfb" class="javax.swing.JButton" binding="buttonLeft">
<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>
<icon value="Left.png"/>
<text value=""/>
<visible value="true"/>
</properties>
</component>
</children>
</grid>
<hspacer id="da837">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="e184c" binding="drawPanel" custom-create="true" 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>
</children>
</grid>
</form>

View File

@ -0,0 +1,143 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FormMapWithArmoredCars extends JFrame{
private JButton buttonAddArmoredCar;
private JButton buttonRemoveArmoredCar;
private JButton buttonShowStorage;
private JButton buttonShowOnMap;
private JTextField maskedTextBoxPosition;
private JComboBox mapSelectorComboBox;
private JPanel drawPanel;
private JButton buttonUp;
private JButton buttonDown;
private JButton buttonRight;
private JButton buttonLeft;
private JPanel mainPanel;
private JPanel btnPanel;
private Image img;
private MapWithSetArmoredCarsGeneric<DrawingObjectArmoredCar, AbstractMap> _mapArmoredCarsCollectionGeneric;
public FormMapWithArmoredCars() {
super("Карта с набором объектов");
setBounds(100, 100, 1000, 700);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mapSelectorComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
AbstractMap map = null;
String name = (String) mapSelectorComboBox.getSelectedItem();
switch (name)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Карта 1":
map = new MyMapWooden();
break;
case "Карта 2":
map = new MyMapLabyrinth();
break;
}
if (map != null)
{
_mapArmoredCarsCollectionGeneric = new MapWithSetArmoredCarsGeneric<DrawingObjectArmoredCar, AbstractMap>(
drawPanel.getWidth(), drawPanel.getHeight(), map);
}
else
{
_mapArmoredCarsCollectionGeneric = null;
}
}
});
buttonAddArmoredCar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_mapArmoredCarsCollectionGeneric == null)
{
return;
}
FormArmoredCar form = new FormArmoredCar();
JOptionPane.showMessageDialog(null, "Добавление - заглушка");
// if (form.ShowDialog() == DialogResult.OK)
// {
// DrawingObjectArmoredCar armoredCar = new DrawingObjectArmoredCar(form.SelectedCar);
// if (_mapArmoredCarsCollectionGeneric.add(armoredCar) > -1)
// {
// MessageBox.Show("Объект добавлен");
// img = _mapArmoredCarsCollectionGeneric.ShowSet();
// }
// else
// {
// MessageBox.Show("Не удалось добавить объект");
// }
// }
}
});
buttonRemoveArmoredCar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (maskedTextBoxPosition.getText().equals(""))
{
return;
}
JOptionPane.showMessageDialog(null, "Удаление - заглушка");
// if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
// {
// return;
// }
// int pos = Integer.parseInt(maskedTextBoxPosition.getText());
// if (_mapArmoredCarsCollectionGeneric.remove(pos) != null)
// {
// MessageBox.Show("Объект удален");
// img = _mapArmoredCarsCollectionGeneric.ShowSet();
// }
// else
// {
// MessageBox.Show("Не удалось удалить объект");
// }
}
});
buttonShowStorage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_mapArmoredCarsCollectionGeneric == null)
{
return;
}
img = _mapArmoredCarsCollectionGeneric.ShowSet();
repaint();
}
});
buttonShowOnMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_mapArmoredCarsCollectionGeneric == null)
{
return;
}
img = _mapArmoredCarsCollectionGeneric.ShowOnMap();
repaint();
}
});
setContentPane(mainPanel);
setVisible(true);
}
private void createUIComponents() {
drawPanel = new JPanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 0, 0, this);
super.repaint();
}
};
}
}