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