Изменения в формах и дополнительном задании
This commit is contained in:
parent
86539b4d23
commit
deba91e044
@ -1,7 +1,5 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
public class FormMapWithSetWarships extends JFrame{
|
public class FormMapWithSetWarships extends JFrame{
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
@ -36,7 +34,7 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
public void InitializeComponent(){
|
public void InitializeComponent(){
|
||||||
setContentPane(mainPanel);
|
setContentPane(mainPanel);
|
||||||
setTitle("Warship");
|
setTitle("Warship");
|
||||||
setSize(1000, 685);
|
setSize(1000, 693);
|
||||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
|
||||||
@ -49,32 +47,24 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
|
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
|
||||||
ButtonRight.setIcon(iconRight);
|
ButtonRight.setIcon(iconRight);
|
||||||
|
|
||||||
СomboBoxSelectorMap.addActionListener(new ActionListener() {
|
СomboBoxSelectorMap.addActionListener(e -> {
|
||||||
@Override
|
AbstractMap map = switch (СomboBoxSelectorMap.getSelectedItem().toString()) {
|
||||||
public void actionPerformed(ActionEvent e) {
|
case "Простая карта" -> new SimpleMap();
|
||||||
AbstractMap map = null;
|
case "Преграды-линии" -> new LineMap();
|
||||||
switch (СomboBoxSelectorMap.getSelectedItem().toString()){
|
default -> null;
|
||||||
case "Простая карта":
|
};
|
||||||
map = new SimpleMap();
|
if( map != null){
|
||||||
break;
|
_mapWarshipsCollectionGeneric = new MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap>(
|
||||||
case "Преграды-линии":
|
PictureBox.getWidth(), PictureBox.getHeight(), map);
|
||||||
map = new LineMap();
|
}
|
||||||
break;
|
else
|
||||||
}
|
{
|
||||||
if( map != null){
|
_mapWarshipsCollectionGeneric = null;
|
||||||
_mapWarshipsCollectionGeneric = new MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap>(
|
|
||||||
PictureBox.getWidth(), PictureBox.getHeight(), map);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_mapWarshipsCollectionGeneric = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonAddWarship.addActionListener(e -> {
|
ButtonAddWarship.addActionListener(e -> {
|
||||||
if(_mapWarshipsCollectionGeneric == null){
|
if(_mapWarshipsCollectionGeneric == null){
|
||||||
System.out.println("null");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FormWarshipCreator warshipCreator = new FormWarshipCreator();
|
FormWarshipCreator warshipCreator = new FormWarshipCreator();
|
||||||
@ -85,7 +75,7 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
if (warshipCreator.getSelectedWarship() != null) {
|
if (warshipCreator.getSelectedWarship() != null) {
|
||||||
DrawingObjectWarship warship = new DrawingObjectWarship(warshipCreator.getSelectedWarship());
|
DrawingObjectWarship warship = new DrawingObjectWarship(warshipCreator.getSelectedWarship());
|
||||||
|
|
||||||
if (_mapWarshipsCollectionGeneric.add(warship) >= 0) {
|
if (_mapWarshipsCollectionGeneric.Plus(warship) >= 0) {
|
||||||
JOptionPane.showMessageDialog(this,
|
JOptionPane.showMessageDialog(this,
|
||||||
"Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
"Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
||||||
@ -113,7 +103,7 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Integer.parseInt(text);
|
int pos = Integer.parseInt(text);
|
||||||
if (_mapWarshipsCollectionGeneric.remove(pos) != null)
|
if (_mapWarshipsCollectionGeneric.Minus(pos) != null)
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(this,
|
JOptionPane.showMessageDialog(this,
|
||||||
"Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE);
|
"Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<children>
|
||||||
<grid id="b8cad" binding="PropertiesPanel" layout-manager="GridLayoutManager" row-count="7" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="b8cad" binding="SettingsPanel" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<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"/>
|
<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"/>
|
||||||
@ -16,53 +16,22 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<opaque value="true"/>
|
<opaque value="true"/>
|
||||||
</properties>
|
</properties>
|
||||||
<border type="etched" title="Настройки"/>
|
<border type="etched" title="Settings"/>
|
||||||
<children>
|
<children>
|
||||||
<vspacer id="3ff70">
|
<grid id="41669" binding="BlocksTypePanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<constraints>
|
|
||||||
<grid row="6" 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>
|
|
||||||
<grid id="fee11" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<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"/>
|
<grid row="6" 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>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="etched" title="Тип корабля:"/>
|
<border type="etched" title="Blocks type"/>
|
||||||
<children>
|
<children>
|
||||||
<component id="387d2" class="javax.swing.JRadioButton" binding="BasicRadioButton">
|
<component id="40e8a" class="javax.swing.JRadioButton" binding="RoundRectangleFormRadioButton">
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Обычный корабль"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="dc133" class="javax.swing.JRadioButton" binding="AdvancedRadioButton">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Продвинутый корабль"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="41669" binding="CargoPanel" layout-manager="GridLayoutManager" row-count="3" 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="3" column="0" 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="etched" title="Характеристики груза:"/>
|
|
||||||
<children>
|
|
||||||
<component id="40e8a" class="javax.swing.JRadioButton" binding="TriangleFormRadioButton">
|
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Треугольные ящики"/>
|
<text value="Round Rectangle blocks"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="339d6" class="javax.swing.JRadioButton" binding="RoundFormRadioButton">
|
<component id="339d6" class="javax.swing.JRadioButton" binding="RoundFormRadioButton">
|
||||||
@ -70,8 +39,8 @@
|
|||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<label value="Круглые ящики"/>
|
<label value="Round blocks"/>
|
||||||
<text value="Круглые ящики"/>
|
<text value="Round blocks"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="ad164" class="javax.swing.JRadioButton" binding="RectangleFormRadioButton">
|
<component id="ad164" class="javax.swing.JRadioButton" binding="RectangleFormRadioButton">
|
||||||
@ -79,18 +48,51 @@
|
|||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Прямоугольные ящики"/>
|
<text value="Rectangle blocks"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
|
<grid id="15d71" layout-manager="GridLayoutManager" row-count="2" 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="8" 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>
|
||||||
|
<component id="a819c" class="javax.swing.JButton" binding="CreateButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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>
|
||||||
|
<label value="Create"/>
|
||||||
|
<text value="Create"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="821c8" class="javax.swing.JButton" binding="SelectButton">
|
||||||
|
<constraints>
|
||||||
|
<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>
|
||||||
|
<properties>
|
||||||
|
<label value="Select"/>
|
||||||
|
<text value="Select"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<vspacer id="6c05e">
|
||||||
|
<constraints>
|
||||||
|
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
<grid id="21a40" binding="CountOfBlocksPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="21a40" binding="CountOfBlocksPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="4" 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>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="etched" title="Количество ящиков:"/>
|
<border type="etched" title="Number of blocks"/>
|
||||||
<children>
|
<children>
|
||||||
<component id="e77e" class="javax.swing.JRadioButton" binding="SixRadioButton">
|
<component id="e77e" class="javax.swing.JRadioButton" binding="SixRadioButton">
|
||||||
<constraints>
|
<constraints>
|
||||||
@ -118,72 +120,75 @@
|
|||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
<grid id="15d71" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<vspacer id="f0649">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<vspacer id="18811">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<vspacer id="1084d">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<grid id="7b5d7" binding="TypePanel" 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"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<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>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="etched" title="Type"/>
|
||||||
<children>
|
<children>
|
||||||
<component id="a819c" class="javax.swing.JButton" binding="ShowWarshipButton">
|
<component id="b0d54" class="javax.swing.JComboBox" binding="comboBoxType">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" 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="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"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<label value="Показать"/>
|
<model>
|
||||||
<text value="Показать"/>
|
<item value="Warship"/>
|
||||||
</properties>
|
<item value="AircraftCarrier"/>
|
||||||
</component>
|
</model>
|
||||||
<component id="821c8" class="javax.swing.JButton" binding="ChooseButton">
|
|
||||||
<constraints>
|
|
||||||
<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>
|
|
||||||
<properties>
|
|
||||||
<label value="Выбрать"/>
|
|
||||||
<text value="Выбрать"/>
|
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
<vspacer id="6c05e">
|
<grid id="5220b" binding="ModificationPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<constraints>
|
|
||||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</vspacer>
|
|
||||||
<grid id="5220b" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="2" 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>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="etched" title="Modification"/>
|
<border type="etched" title="Modification"/>
|
||||||
<children>
|
<children>
|
||||||
<component id="c96ee" class="javax.swing.JCheckBox" binding="MissileCheckBox">
|
<component id="c96ee" class="javax.swing.JCheckBox" binding="EngineCheckBox">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<label value="Боевые ракеты"/>
|
<label value="Super engine"/>
|
||||||
<text value="Боевые ракеты"/>
|
<text value="Super engine"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="385c6" class="javax.swing.JCheckBox" binding="AntennaCheckBox">
|
<component id="385c6" class="javax.swing.JCheckBox" binding="CabinCheckBox">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<label value="Антенна"/>
|
<label value="Cabin"/>
|
||||||
<text value="Антенна"/>
|
<text value="Cabin"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="63fa9" class="javax.swing.JCheckBox" binding="HelipadCheckBox">
|
<component id="63fa9" class="javax.swing.JCheckBox" binding="AreaCheckBox">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<label value="Посадочная площадка"/>
|
<label value="Landing area"/>
|
||||||
<text value="Посадочная площадка"/>
|
<text value="Landing area"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
|
@ -4,29 +4,30 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class FormWarshipCreator extends JDialog{
|
public class FormWarshipCreator extends JDialog{
|
||||||
private JPanel PictureBox;
|
private JPanel PictureBox;
|
||||||
private JPanel PropertiesPanel;
|
private JPanel SettingsPanel;
|
||||||
private JRadioButton BasicRadioButton;
|
private JPanel BlocksTypePanel;
|
||||||
private JRadioButton AdvancedRadioButton;
|
private JPanel CountOfBlocksPanel;
|
||||||
private JTextField WeightTextField;
|
private JPanel ModificationPanel;
|
||||||
private JTextField SpeedTextField;
|
private JPanel TypePanel;
|
||||||
private JPanel CargoPanel;
|
private JRadioButton RoundRectangleFormRadioButton;
|
||||||
private JRadioButton TriangleFormRadioButton;
|
|
||||||
private JRadioButton RoundFormRadioButton;
|
private JRadioButton RoundFormRadioButton;
|
||||||
private JRadioButton RectangleFormRadioButton;
|
private JRadioButton RectangleFormRadioButton;
|
||||||
private JPanel CountOfBlocksPanel;
|
|
||||||
private JRadioButton SixRadioButton;
|
private JRadioButton SixRadioButton;
|
||||||
private JRadioButton FourRadioButton;
|
private JRadioButton FourRadioButton;
|
||||||
private JRadioButton TwoRadioButton;
|
private JRadioButton TwoRadioButton;
|
||||||
private JButton ShowWarshipButton;
|
private JButton CreateButton;
|
||||||
private JButton ChooseButton;
|
private JButton SelectButton;
|
||||||
private JCheckBox MissileCheckBox;
|
private JCheckBox EngineCheckBox;
|
||||||
private JCheckBox AntennaCheckBox;
|
private JCheckBox CabinCheckBox;
|
||||||
private JCheckBox HelipadCheckBox;
|
private JCheckBox AreaCheckBox;
|
||||||
BlockCount _block = null;
|
private JComboBox comboBoxType;
|
||||||
IDrawingObjectBlock objectBlock = null;
|
private BlockCount _block = null;
|
||||||
private final WarshipCreatorGeneric<EntityWarship,IDrawingObjectBlock> createrGeneric=new WarshipCreatorGeneric<>(40,40);
|
private IDrawingObjectBlock objectBlock = null;
|
||||||
|
private final WarshipCreatorGeneric<EntityWarship,IDrawingObjectBlock> warshipCreator =new WarshipCreatorGeneric<>(40,40);
|
||||||
private DrawingWarship _warship;
|
private DrawingWarship _warship;
|
||||||
private DrawingWarship selectedWarship;
|
private DrawingWarship selectedWarship;
|
||||||
|
private boolean isModified = false;
|
||||||
|
|
||||||
|
|
||||||
public FormWarshipCreator(){
|
public FormWarshipCreator(){
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -49,80 +50,91 @@ public class FormWarshipCreator extends JDialog{
|
|||||||
setContentPane(PictureBox);
|
setContentPane(PictureBox);
|
||||||
setTitle("Warship");
|
setTitle("Warship");
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
setSize(900, 700);
|
setSize(1000, 600);
|
||||||
|
|
||||||
|
//Определение типа объекта
|
||||||
|
comboBoxType.addItemListener(e -> isModified = e.getItem().toString().equals("AircraftCarrier"));
|
||||||
|
|
||||||
|
//количество блоков
|
||||||
TwoRadioButton.addActionListener(e -> {
|
TwoRadioButton.addActionListener(e -> {
|
||||||
_block =BlockCount.TwoBlocks;
|
_block = BlockCount.TwoBlocks;
|
||||||
});
|
});
|
||||||
FourRadioButton.addActionListener(e -> {
|
FourRadioButton.addActionListener(e -> {
|
||||||
_block =BlockCount.FourBlocks;
|
_block = BlockCount.FourBlocks;
|
||||||
});
|
});
|
||||||
SixRadioButton.addActionListener(e -> {
|
SixRadioButton.addActionListener(e -> {
|
||||||
_block =BlockCount.SixBlocks;
|
_block = BlockCount.SixBlocks;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Квадратная форма блоков
|
||||||
RectangleFormRadioButton.addActionListener(e -> {
|
RectangleFormRadioButton.addActionListener(e -> {
|
||||||
if(_block ==null){
|
if(_block == null) return;
|
||||||
return;
|
|
||||||
}
|
objectBlock = new DrawingBlocks(_block);
|
||||||
objectBlock =new DrawingBlocks(_block);
|
|
||||||
if(objectBlock ==null)
|
|
||||||
return;
|
|
||||||
objectBlock.SetBlockCount(_block.GetBlockCount());
|
objectBlock.SetBlockCount(_block.GetBlockCount());
|
||||||
createrGeneric.AddBlock(objectBlock);
|
warshipCreator.AddBlock(objectBlock);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Круглая форма блоков
|
||||||
RoundFormRadioButton.addActionListener(e -> {
|
RoundFormRadioButton.addActionListener(e -> {
|
||||||
if(_block ==null){
|
if(_block ==null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
objectBlock =new DrawingRoundBlocks(_block);
|
objectBlock = new DrawingRoundBlocks(_block);
|
||||||
if(objectBlock ==null)
|
|
||||||
return;
|
|
||||||
objectBlock.SetBlockCount(_block.GetBlockCount());
|
objectBlock.SetBlockCount(_block.GetBlockCount());
|
||||||
createrGeneric.AddBlock(objectBlock);
|
warshipCreator.AddBlock(objectBlock);
|
||||||
});
|
});
|
||||||
|
|
||||||
TriangleFormRadioButton.addActionListener(e -> {
|
//Закруглено-квадратная форма блоков
|
||||||
if(_block ==null){
|
RoundRectangleFormRadioButton.addActionListener(e -> {
|
||||||
|
if(_block == null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
objectBlock =new DrawingRoundBlocks(_block);
|
objectBlock = new DrawingRoundBlocks(_block);
|
||||||
if(objectBlock ==null)
|
|
||||||
return;
|
|
||||||
objectBlock.SetBlockCount(_block.GetBlockCount());
|
objectBlock.SetBlockCount(_block.GetBlockCount());
|
||||||
createrGeneric.AddBlock(objectBlock);
|
warshipCreator.AddBlock(objectBlock);
|
||||||
});
|
});
|
||||||
|
|
||||||
BasicRadioButton.addActionListener(e -> {
|
CreateButton.addActionListener(e -> {
|
||||||
Color color=JColorChooser.showDialog(this,"Выберите цвет корпуса корабля",Color.WHITE);
|
Random rnd = new Random();
|
||||||
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color==null){
|
if (_block != null && objectBlock != null) {
|
||||||
return;
|
Color color = JColorChooser.showDialog(this, "Choose color", Color.WHITE);
|
||||||
}
|
|
||||||
createrGeneric.AddWarship(new EntityWarship(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),color));
|
|
||||||
});
|
|
||||||
|
|
||||||
AdvancedRadioButton.addActionListener(e -> {
|
if (isModified) {
|
||||||
Color color1=JColorChooser.showDialog(this,"Выберите цвет корпуса корабля",Color.WHITE);
|
Color additionalColor = JColorChooser.showDialog(this, "Choose color", Color.GRAY);
|
||||||
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color1==null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Color color2=JColorChooser.showDialog(this,"Выберите цвет модификаций корабля",Color.WHITE);
|
|
||||||
if(color2==null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
createrGeneric.AddWarship(new EntityAircraftCarrier(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),
|
|
||||||
color1,color2,HelipadCheckBox.isSelected(),AntennaCheckBox.isSelected(),MissileCheckBox.isSelected()));
|
|
||||||
});
|
|
||||||
|
|
||||||
ShowWarshipButton.addActionListener(e -> {
|
warshipCreator.AddWarship(
|
||||||
Random rand=new Random();
|
new EntityAircraftCarrier(
|
||||||
_warship=createrGeneric.NewWarshipCreating();
|
rnd.nextInt(10, 300),
|
||||||
_warship.SetPosition(rand.nextInt(100),rand.nextInt(100),getWidth(),getHeight());
|
rnd.nextFloat(10, 3000),
|
||||||
repaint();
|
color,
|
||||||
|
additionalColor,
|
||||||
|
AreaCheckBox.isSelected(),
|
||||||
|
CabinCheckBox.isSelected(),
|
||||||
|
EngineCheckBox.isSelected()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
warshipCreator.AddWarship(
|
||||||
|
new EntityWarship(
|
||||||
|
rnd.nextInt(10, 300),
|
||||||
|
rnd.nextFloat(10, 3000),
|
||||||
|
color)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_warship = warshipCreator.NewWarshipCreating();
|
||||||
|
_warship.SetPosition(
|
||||||
|
rnd.nextInt(20),
|
||||||
|
rnd.nextInt(20),
|
||||||
|
PictureBox.getWidth(),
|
||||||
|
PictureBox.getHeight());
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
ChooseButton.addActionListener(e -> {
|
SelectButton.addActionListener(e -> {
|
||||||
selectedWarship=_warship;
|
selectedWarship = _warship;
|
||||||
dispose();
|
dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -19,19 +19,19 @@ public class MapWithSetWarshipsGeneric <T extends IDrawingObject,U extends Abstr
|
|||||||
_map = map;
|
_map = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int add(T warship)
|
public int Plus(T warship)
|
||||||
{
|
{
|
||||||
return _setWarships.Insert(warship);
|
return _setWarships.Insert(warship);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T remove(int position)
|
public T Minus(int position)
|
||||||
{
|
{
|
||||||
return _setWarships.Remove(position);
|
return _setWarships.Remove(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image ShowSet()
|
public Image ShowSet()
|
||||||
{
|
{
|
||||||
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureWidth,BufferedImage.TYPE_INT_RGB);
|
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureWidth,BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics gr = bmp.getGraphics();
|
Graphics gr = bmp.getGraphics();
|
||||||
DrawBackground(gr);
|
DrawBackground(gr);
|
||||||
DrawWarship(gr);
|
DrawWarship(gr);
|
||||||
@ -43,13 +43,13 @@ public class MapWithSetWarshipsGeneric <T extends IDrawingObject,U extends Abstr
|
|||||||
Shaking();
|
Shaking();
|
||||||
for (int i = 0; i < _setWarships.getCount(); i++)
|
for (int i = 0; i < _setWarships.getCount(); i++)
|
||||||
{
|
{
|
||||||
var warship = _setWarships.Get(i);
|
T warship = _setWarships.Get(i);
|
||||||
if (warship != null)
|
if (warship != null)
|
||||||
{
|
{
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, warship);
|
return _map.CreateMap(_pictureWidth, _pictureHeight, warship);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new BufferedImage(_pictureWidth, _pictureHeight,BufferedImage.TYPE_INT_RGB);
|
return new BufferedImage(_pictureWidth, _pictureHeight, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image MoveObject(Direction direction)
|
public Image MoveObject(Direction direction)
|
||||||
@ -58,7 +58,7 @@ public class MapWithSetWarshipsGeneric <T extends IDrawingObject,U extends Abstr
|
|||||||
{
|
{
|
||||||
return _map.MoveObject(direction);
|
return _map.MoveObject(direction);
|
||||||
}
|
}
|
||||||
return new BufferedImage(_pictureWidth, _pictureHeight,BufferedImage.TYPE_INT_RGB);
|
return new BufferedImage(_pictureWidth, _pictureHeight, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Shaking()
|
public void Shaking()
|
||||||
@ -88,25 +88,23 @@ public class MapWithSetWarshipsGeneric <T extends IDrawingObject,U extends Abstr
|
|||||||
|
|
||||||
private void DrawBackground(Graphics gr)
|
private void DrawBackground(Graphics gr)
|
||||||
{
|
{
|
||||||
Graphics2D g=(Graphics2D)gr;
|
Graphics2D g = (Graphics2D)gr;
|
||||||
|
|
||||||
Color brush=Color.BLACK;
|
Color brush=Color.BLACK;
|
||||||
Stroke penWide = new BasicStroke(5);
|
Stroke penWide = new BasicStroke(3);
|
||||||
Stroke penThin = new BasicStroke(1);
|
|
||||||
|
|
||||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
for (int j = 0; j <= _pictureHeight / _placeSizeHeight ; ++j)
|
||||||
{
|
{
|
||||||
g.setColor(brush);
|
g.setColor(brush);
|
||||||
g.setStroke(penWide);
|
g.setStroke(penWide);
|
||||||
g.drawLine(i * _placeSizeWidth + 20, j * _placeSizeHeight+2, i * _placeSizeWidth + (int)(_placeSizeWidth*0.8), j * _placeSizeHeight+2);
|
g.drawLine(i * _placeSizeWidth + 20, j * _placeSizeHeight+2, i * _placeSizeWidth + (int)(_placeSizeWidth*0.8), j * _placeSizeHeight+2);
|
||||||
g.drawLine(i * _placeSizeWidth + 20, j * _placeSizeHeight + _placeSizeHeight/2+2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight/2+2);
|
|
||||||
g.drawLine(i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight/2);
|
g.drawLine(i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight/2);
|
||||||
g.drawLine(i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2, i * _placeSizeWidth+ (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight);
|
g.drawLine(i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2, i * _placeSizeWidth+ (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight);
|
||||||
g.setStroke(penThin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawWarship(Graphics gr)
|
private void DrawWarship(Graphics gr)
|
||||||
@ -118,7 +116,7 @@ public class MapWithSetWarshipsGeneric <T extends IDrawingObject,U extends Abstr
|
|||||||
{
|
{
|
||||||
if (_setWarships.Get(i) != null)
|
if (_setWarships.Get(i) != null)
|
||||||
{
|
{
|
||||||
_setWarships.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
_setWarships.Get(i).SetObject(i % width * _placeSizeWidth, ((height - 1 - i / width) * _placeSizeHeight) + 6, _pictureWidth, _pictureHeight);
|
||||||
_setWarships.Get(i).DrawingObject(gr);
|
_setWarships.Get(i).DrawingObject(gr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
public class SetWarshipsGeneric<T>{
|
public class SetWarshipsGeneric<T extends Object>{
|
||||||
private T[] _places;
|
private final Object[] _places;
|
||||||
|
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return _places != null ? _places.length : 0;
|
return _places.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SetWarshipsGeneric(int count)
|
public SetWarshipsGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = (T[]) new Object[count];
|
_places = new Object[count];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T warship)
|
public int Insert(T warship)
|
||||||
@ -17,7 +17,7 @@ public class SetWarshipsGeneric<T>{
|
|||||||
|
|
||||||
public int Insert(T warship, int position)
|
public int Insert(T warship, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= getCount() || _places[position] == null)
|
if (position < 0 || position >= getCount())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int empty = -1;
|
int empty = -1;
|
||||||
@ -43,7 +43,7 @@ public class SetWarshipsGeneric<T>{
|
|||||||
if (position >= getCount() || position < 0 || _places[position] == null)
|
if (position >= getCount() || position < 0 || _places[position] == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
T deleted =_places[position];
|
T deleted =(T) _places[position];
|
||||||
_places[position] = null;
|
_places[position] = null;
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
@ -53,6 +53,6 @@ public class SetWarshipsGeneric<T>{
|
|||||||
if (position >= getCount() || position < 0)
|
if (position >= getCount() || position < 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return _places[position];
|
return (T) _places[position];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,39 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class WarshipCreatorGeneric <T extends EntityWarship, U extends IDrawingObjectBlock>{
|
public class WarshipCreatorGeneric <T extends EntityWarship, U extends IDrawingObjectBlock>{
|
||||||
private final EntityWarship[] Warships;
|
private final ArrayList<T> Warships;
|
||||||
private final IDrawingObjectBlock[] Blocks;
|
private final ArrayList<U> Blocks;
|
||||||
private int WarshipsCount = 0;
|
private int WarshipsCount = 0;
|
||||||
private int BlocksCount = 0;
|
private int BlocksCount = 0;
|
||||||
public WarshipCreatorGeneric(int warshipsCount, int blocksCount){
|
public WarshipCreatorGeneric(int warshipsCount, int blocksCount){
|
||||||
Warships = new EntityWarship[warshipsCount];
|
Warships = new ArrayList<>(warshipsCount);
|
||||||
Blocks = new IDrawingObjectBlock[blocksCount];
|
Blocks = new ArrayList<>(blocksCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int AddWarship(T warship){
|
public int AddWarship(T warship){
|
||||||
if(WarshipsCount < Warships.length){
|
if(WarshipsCount <= Warships.size()){
|
||||||
Warships[WarshipsCount] = warship;
|
Warships.add(warship);
|
||||||
WarshipsCount++;
|
WarshipsCount++;
|
||||||
return WarshipsCount - 1;
|
return WarshipsCount - 1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int AddBlock(U block){
|
public int AddBlock(U block){
|
||||||
if(BlocksCount < Blocks.length){
|
if(BlocksCount <= Blocks.size()){
|
||||||
Blocks[BlocksCount] = block;
|
Blocks.add(block);
|
||||||
BlocksCount++;
|
BlocksCount++;
|
||||||
return BlocksCount - 1;
|
return BlocksCount - 1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrawingWarship NewWarshipCreating()
|
public DrawingWarship NewWarshipCreating()
|
||||||
{
|
{
|
||||||
Random rand=new Random();
|
Random rand=new Random();
|
||||||
T warship = (T)Warships[rand.nextInt(WarshipsCount)];
|
T warship = (T)Warships.get(rand.nextInt(WarshipsCount));
|
||||||
U block = (U)Blocks[rand.nextInt(BlocksCount)];
|
U block = (U)Blocks.get(rand.nextInt(BlocksCount));
|
||||||
|
|
||||||
if(warship instanceof EntityAircraftCarrier){
|
if(warship instanceof EntityAircraftCarrier){
|
||||||
return new DrawingAircraftCarrier(warship, block);
|
return new DrawingAircraftCarrier(warship, block);
|
||||||
|
Loading…
Reference in New Issue
Block a user