Промежуточный коммит
This commit is contained in:
parent
a2e5535386
commit
b3746ca983
39
src/CreaterGeneric.java
Normal file
39
src/CreaterGeneric.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class CreaterGeneric<T extends EntityWarship, U extends IDrawingObjectBlock> {
|
||||||
|
Object[] Warships;
|
||||||
|
Object[] Blocks;
|
||||||
|
int WarshipsCount=0;
|
||||||
|
int BlocksCount=0;
|
||||||
|
public CreaterGeneric(int warshipsCount,int blocksCount){
|
||||||
|
Warships=new Object[warshipsCount];
|
||||||
|
Blocks=new Object[blocksCount];
|
||||||
|
}
|
||||||
|
public int AddWarship(T warship){
|
||||||
|
if(WarshipsCount<Warships.length){
|
||||||
|
Warships[WarshipsCount]=warship;
|
||||||
|
WarshipsCount++;
|
||||||
|
return WarshipsCount-1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int AddBlock(U block){
|
||||||
|
if(BlocksCount<Blocks.length){
|
||||||
|
Blocks[BlocksCount]=block;
|
||||||
|
BlocksCount++;
|
||||||
|
return BlocksCount-1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingWarship NewWarshipCreate(){
|
||||||
|
Random rand= new Random();
|
||||||
|
DrawingWarship finalVersionWarship;
|
||||||
|
T selectedWarship =(T) Warships[rand.nextInt(WarshipsCount+1)];
|
||||||
|
U selectedBlock = (U)Blocks[rand.nextInt(BlocksCount+1)];
|
||||||
|
if(selectedWarship instanceof EntityAdvancedWarship){
|
||||||
|
return new DrawingAdvancedWarship(selectedWarship,selectedBlock);
|
||||||
|
}
|
||||||
|
return new DrawingWarship(selectedWarship,selectedBlock);
|
||||||
|
}
|
||||||
|
}
|
102
src/CreaterGenericField.java
Normal file
102
src/CreaterGenericField.java
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class CreaterGenericField extends JPanel {
|
||||||
|
private final FormCreater formCreater;
|
||||||
|
private final CreaterGeneric<EntityWarship,IDrawingObjectBlock> createrGeneric;
|
||||||
|
private DrawingObjectWarship _warship;
|
||||||
|
|
||||||
|
public CreaterGenericField(FormCreater form){
|
||||||
|
formCreater=form;
|
||||||
|
createrGeneric=new CreaterGeneric<>(40,40);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g){
|
||||||
|
super.paintComponent(g);
|
||||||
|
if(_warship!=null){
|
||||||
|
_warship.DrawingObject(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Draw(Graphics g){
|
||||||
|
if(_warship!=null){
|
||||||
|
_warship.DrawingObject(g);
|
||||||
|
}
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BasicRadioButtonAction(int speed,int weight){
|
||||||
|
Color color=JColorChooser.showDialog(formCreater,"Выберите цвет корпуса корабля",Color.WHITE);
|
||||||
|
if(speed==0 || weight==0 || color==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
createrGeneric.AddWarship(new EntityWarship(speed,weight,color));
|
||||||
|
Draw(formCreater.getGraphics());
|
||||||
|
}
|
||||||
|
public void AdvancedRadioButtonAction(int speed,int weight, Boolean antenna, Boolean missile, Boolean helipad){
|
||||||
|
Color color1=JColorChooser.showDialog(formCreater,"Выберите цвет корпуса корабля",Color.WHITE);
|
||||||
|
if(speed==0 || weight==0 || color1==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Color color2=JColorChooser.showDialog(formCreater,"Выберите цвет модификаций корабля",Color.WHITE);
|
||||||
|
if(color2==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
createrGeneric.AddWarship(new EntityAdvancedWarship(speed,weight,color1,color2,helipad,antenna,missile));
|
||||||
|
Draw(formCreater.getGraphics());
|
||||||
|
}
|
||||||
|
public BlockCount TwoRadioButtonAction(){
|
||||||
|
return BlockCount.TwoBlocks;
|
||||||
|
}
|
||||||
|
public BlockCount FourRadioButtonAction(){
|
||||||
|
return BlockCount.FourBlocks;
|
||||||
|
}
|
||||||
|
public BlockCount SixRadioButtonAction(){
|
||||||
|
return BlockCount.SixBlocks;
|
||||||
|
}
|
||||||
|
public void RectangleFormRadioButtonAction(BlockCount count){
|
||||||
|
if(count==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
IDrawingObjectBlock block=new DrawingBlock(count);
|
||||||
|
if(block==null)
|
||||||
|
return;
|
||||||
|
block.SetBlockCount(count.GetBlockCount());
|
||||||
|
createrGeneric.AddBlock(block);
|
||||||
|
Draw(formCreater.getGraphics());
|
||||||
|
}
|
||||||
|
public void RoundFormRadioButtonAction(BlockCount count){
|
||||||
|
if(count==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
IDrawingObjectBlock block=new DrawingRoundBlocks(count);
|
||||||
|
if(block==null)
|
||||||
|
return;
|
||||||
|
block.SetBlockCount(count.GetBlockCount());
|
||||||
|
createrGeneric.AddBlock(block);
|
||||||
|
Draw(formCreater.getGraphics());
|
||||||
|
}
|
||||||
|
public void TriangleFormRadioButtonAction(BlockCount count){
|
||||||
|
if(count==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
IDrawingObjectBlock block=new DrawingTriangleBlocks(count);
|
||||||
|
if(block==null)
|
||||||
|
return;
|
||||||
|
block.SetBlockCount(count.GetBlockCount());
|
||||||
|
createrGeneric.AddBlock(block);
|
||||||
|
Draw(formCreater.getGraphics());
|
||||||
|
}
|
||||||
|
public void ShowWarshipButtonAction(){
|
||||||
|
Random rand=new Random();
|
||||||
|
_warship=new DrawingObjectWarship(createrGeneric.NewWarshipCreate());
|
||||||
|
_warship.SetObject(rand.nextInt(100),rand.nextInt(100),getWidth(),getHeight());
|
||||||
|
Draw(formCreater.getGraphics());
|
||||||
|
}
|
||||||
|
public void RemoveSelect(){
|
||||||
|
_warship=null;
|
||||||
|
}
|
||||||
|
public DrawingObjectWarship GetWarship(){
|
||||||
|
return _warship;
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,11 @@ public class DrawingAdvancedWarship extends DrawingWarship {
|
|||||||
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrawingAdvancedWarship(EntityWarship selectedWarship, IDrawingObjectBlock selectedBlock) {
|
||||||
|
super(selectedWarship,selectedBlock);
|
||||||
|
Warship=selectedWarship;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void DrawTransport(Graphics g) {
|
public void DrawTransport(Graphics g) {
|
||||||
|
|
||||||
|
119
src/DrawingDocks.java
Normal file
119
src/DrawingDocks.java
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingDocks extends JPanel {
|
||||||
|
private final FormMapWithSetWarships Dock;
|
||||||
|
private FormCreater formCreater;
|
||||||
|
private MapWithSetWarshipsGeneric<DrawingObjectWarship,AbstractMap> _mapWarshipsCollectionGeneric;
|
||||||
|
BufferedImage bufferedImage;
|
||||||
|
public DrawingDocks(FormMapWithSetWarships dock) {
|
||||||
|
Dock = dock;
|
||||||
|
formCreater=new FormCreater(Dock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2=(Graphics2D)g;
|
||||||
|
g2.drawImage(bufferedImage,0,0,null);
|
||||||
|
}
|
||||||
|
public void DrawDock(Graphics g){
|
||||||
|
Graphics2D g2=(Graphics2D)g;
|
||||||
|
g2.drawImage(bufferedImage,0,0,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddWarshipButtonAction(){
|
||||||
|
if (_mapWarshipsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
formCreater.Open();
|
||||||
|
DrawingObjectWarship warship = formCreater.GetField().GetWarship();
|
||||||
|
if (_mapWarshipsCollectionGeneric.plus(warship)>=0)
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(Dock,"Объект добавлен");
|
||||||
|
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
||||||
|
DrawDock(Dock.getGraphics());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(Dock,"Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DeleteWarshipButtonAction(String count, JPanel panel){
|
||||||
|
if (count==""||_mapWarshipsCollectionGeneric==null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int result = JOptionPane.showConfirmDialog(
|
||||||
|
panel,
|
||||||
|
"Удалить объект?",
|
||||||
|
"Удаление",
|
||||||
|
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||||
|
if (result == JOptionPane.NO_OPTION)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Integer.parseInt(count);
|
||||||
|
if (_mapWarshipsCollectionGeneric.minus(pos) !=null)
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(Dock,"Объект удален");
|
||||||
|
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(Dock,"Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowStorageButtonAction()
|
||||||
|
{
|
||||||
|
if (_mapWarshipsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
||||||
|
DrawDock(Dock.getGraphics());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowOnMapButtonAction()
|
||||||
|
{
|
||||||
|
if (_mapWarshipsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bufferedImage = _mapWarshipsCollectionGeneric.ShowOnMap();
|
||||||
|
DrawDock(Dock.getGraphics());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ComboBoxAction(String name,JPanel panel){
|
||||||
|
AbstractMap map = null;
|
||||||
|
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "Первая карта":
|
||||||
|
map = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "Вторая карта":
|
||||||
|
map = new SecondMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (map != null)
|
||||||
|
{
|
||||||
|
_mapWarshipsCollectionGeneric = new MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap>(
|
||||||
|
panel.getWidth(), panel.getHeight(), map);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_mapWarshipsCollectionGeneric = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DirectionButtonAction(Direction side){
|
||||||
|
if(_mapWarshipsCollectionGeneric != null){
|
||||||
|
bufferedImage=_mapWarshipsCollectionGeneric.MoveObject(side);
|
||||||
|
}
|
||||||
|
DrawDock(Dock.getGraphics());
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,9 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class DrawingField extends JPanel{
|
public class DrawingField extends JPanel{
|
||||||
private final FormWarship Field;
|
private final FormWarship Field;
|
||||||
DrawingWarship _warship=null;
|
private DrawingWarship _warship=null;
|
||||||
|
|
||||||
|
public DrawingWarship SelectedWarship;
|
||||||
public DrawingField(FormWarship field) {
|
public DrawingField(FormWarship field) {
|
||||||
Field = field;
|
Field = field;
|
||||||
}
|
}
|
||||||
@ -51,4 +53,11 @@ public class DrawingField extends JPanel{
|
|||||||
_warship.DrawTransport(graphics);
|
_warship.DrawTransport(graphics);
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
|
public DrawingWarship GetDrawingWarship() {
|
||||||
|
return _warship;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetSelected() {
|
||||||
|
_warship=null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class DrawingMap extends JPanel {
|
|
||||||
private final FormMap Map;
|
|
||||||
private AbstractMap _abstractMap;
|
|
||||||
BufferedImage bufferedImage;
|
|
||||||
|
|
||||||
public DrawingMap(FormMap map){
|
|
||||||
Map=map;
|
|
||||||
_abstractMap = new SimpleMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
g.drawImage(bufferedImage,0,0,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetData(DrawingWarship warship) {
|
|
||||||
Random rand=new Random();
|
|
||||||
warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
|
||||||
Map.SpeedLabel.setText("Скорость: "+warship.GetWarship().GetSpeed());
|
|
||||||
Map.WeightLabel.setText("Вес: "+warship.GetWarship().GetWeight());
|
|
||||||
Map.BodyColorLabel.setText("Цвет: "+Integer.toHexString(warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
|
||||||
bufferedImage = _abstractMap.CreateMap(700,550,new DrawingObjectWarship(warship));
|
|
||||||
}
|
|
||||||
public void CreateButtonAction(){
|
|
||||||
Random rand=new Random();
|
|
||||||
Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
|
||||||
DrawingWarship warship=new DrawingWarship(rand.nextInt(50)+10,rand.nextInt(3000)+20000,color1,rand.nextInt(3));
|
|
||||||
SetData(warship);
|
|
||||||
}
|
|
||||||
public void CreateModifButtonAction(){
|
|
||||||
Random rand=new Random();
|
|
||||||
Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
|
||||||
Color color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
|
||||||
DrawingWarship warship = new DrawingAdvancedWarship(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, color1,
|
|
||||||
color2, rand.nextBoolean(), rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
|
||||||
SetData(warship);
|
|
||||||
}
|
|
||||||
public void DirectionButtonAction(Direction side){
|
|
||||||
if(_abstractMap != null){
|
|
||||||
bufferedImage = _abstractMap.MoveObject(side);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ComboBoxSelectorMapAction(String name){
|
|
||||||
switch (name){
|
|
||||||
case "Простая карта":
|
|
||||||
_abstractMap = new SimpleMap();
|
|
||||||
break;
|
|
||||||
case "Вторая карта":
|
|
||||||
_abstractMap = new SecondMap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawMap(Graphics g){
|
|
||||||
g.drawImage(bufferedImage,0,0,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -20,6 +20,10 @@ public class DrawingWarship {
|
|||||||
Blocks= GetFormOfBlock(blockForm);
|
Blocks= GetFormOfBlock(blockForm);
|
||||||
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
||||||
}
|
}
|
||||||
|
public DrawingWarship(EntityWarship selectedWarship, IDrawingObjectBlock selectedBlock) {
|
||||||
|
Warship=selectedWarship;
|
||||||
|
Blocks=selectedBlock;
|
||||||
|
}
|
||||||
|
|
||||||
public IDrawingObjectBlock GetFormOfBlock(int FormOfBlock){
|
public IDrawingObjectBlock GetFormOfBlock(int FormOfBlock){
|
||||||
BlockForm temp = null;
|
BlockForm temp = null;
|
||||||
|
253
src/FormCreater.form
Normal file
253
src/FormCreater.form
Normal file
@ -0,0 +1,253 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormCreater">
|
||||||
|
<grid id="27dc6" binding="PictureBox" 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="630" height="609"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="27a9" binding="PropertiesPanel" layout-manager="GridLayoutManager" row-count="7" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<opaque value="true"/>
|
||||||
|
</properties>
|
||||||
|
<border type="etched" title="Настройки"/>
|
||||||
|
<children>
|
||||||
|
<vspacer id="c17c4">
|
||||||
|
<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="e26e" 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="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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="etched" title="Тип корабля:"/>
|
||||||
|
<children>
|
||||||
|
<component id="beec9" 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="5837d" 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="d8b7b" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="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="9e0cc" class="javax.swing.JTextField" binding="WeightTextField">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="67385" class="javax.swing.JTextField" binding="SpeedTextField">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="77c84" class="javax.swing.JLabel" binding="SetWeightLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Вес"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ff8c4" class="javax.swing.JLabel" binding="SetSpeedLabel">
|
||||||
|
<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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="fc97" 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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="etched" title="Улучшения:"/>
|
||||||
|
<children>
|
||||||
|
<component id="fca4f" class="javax.swing.JCheckBox" binding="MissileCheckBox">
|
||||||
|
<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="Боевые ракеты"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="a7f46" class="javax.swing.JCheckBox" binding="AntennaCheckBox">
|
||||||
|
<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="Антенна"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="632da" class="javax.swing.JCheckBox" binding="HelipadCheckBox">
|
||||||
|
<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="Вертолетная площадка"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="d3b9d" 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="4" 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="fd3ec" class="javax.swing.JRadioButton" binding="TriangleFormRadioButton">
|
||||||
|
<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="Треугольные ящики"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="d03eb" class="javax.swing.JRadioButton" binding="RoundFormRadioButton">
|
||||||
|
<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="Круглые ящики"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="5048f" class="javax.swing.JRadioButton" binding="RectangleFormRadioButton">
|
||||||
|
<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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="e7910" 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="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="f4e43" class="javax.swing.JRadioButton" binding="SixRadioButton">
|
||||||
|
<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="6"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="38916" class="javax.swing.JRadioButton" binding="FourRadioButton">
|
||||||
|
<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="4"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="538af" class="javax.swing.JRadioButton" binding="TwoRadioButton">
|
||||||
|
<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="2"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="ded4" 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="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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="413bc" class="javax.swing.JButton" binding="ShowWarshipButton">
|
||||||
|
<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="Показать"/>
|
||||||
|
<text value="Показать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="8cb53" 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>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<hspacer id="ca2ae">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<buttonGroups>
|
||||||
|
<group name="Entity">
|
||||||
|
<member id="beec9"/>
|
||||||
|
<member id="5837d"/>
|
||||||
|
</group>
|
||||||
|
<group name="Form">
|
||||||
|
<member id="5048f"/>
|
||||||
|
<member id="d03eb"/>
|
||||||
|
<member id="fd3ec"/>
|
||||||
|
</group>
|
||||||
|
<group name="Count">
|
||||||
|
<member id="f4e43"/>
|
||||||
|
<member id="38916"/>
|
||||||
|
<member id="538af"/>
|
||||||
|
</group>
|
||||||
|
</buttonGroups>
|
||||||
|
</form>
|
94
src/FormCreater.java
Normal file
94
src/FormCreater.java
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class FormCreater extends JDialog {
|
||||||
|
private JLabel SetSpeedLabel;
|
||||||
|
private JPanel PropertiesPanel;
|
||||||
|
private JTextField SpeedTextField;
|
||||||
|
private JLabel SetWeightLabel;
|
||||||
|
private JTextField WeightTextField;
|
||||||
|
private JRadioButton BasicRadioButton;
|
||||||
|
private JRadioButton AdvancedRadioButton;
|
||||||
|
private JCheckBox MissileCheckBox;
|
||||||
|
private JCheckBox AntennaCheckBox;
|
||||||
|
private JCheckBox HelipadCheckBox;
|
||||||
|
private JPanel CargoPanel;
|
||||||
|
private JRadioButton TriangleFormRadioButton;
|
||||||
|
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 JPanel PictureBox;
|
||||||
|
CreaterGenericField field=new CreaterGenericField(this);
|
||||||
|
BlockCount block=null;
|
||||||
|
|
||||||
|
public FormCreater(JFrame frame){
|
||||||
|
super(frame,"Создание корабля");
|
||||||
|
setContentPane(PictureBox);
|
||||||
|
setModal(true);
|
||||||
|
setSize(1200,700);
|
||||||
|
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||||
|
ShowWindow();
|
||||||
|
}
|
||||||
|
private void ShowWindow(){
|
||||||
|
BasicRadioButton.addActionListener(e -> {
|
||||||
|
field.BasicRadioButtonAction(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()));
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
AdvancedRadioButton.addActionListener(e -> {
|
||||||
|
field.AdvancedRadioButtonAction(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),AntennaCheckBox.isSelected(),MissileCheckBox.isSelected(),HelipadCheckBox.isSelected());
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
TwoRadioButton.addActionListener(e -> {
|
||||||
|
block=field.TwoRadioButtonAction();
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
FourRadioButton.addActionListener(e -> {
|
||||||
|
block=field.FourRadioButtonAction();
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
SixRadioButton.addActionListener(e -> {
|
||||||
|
block=field.SixRadioButtonAction();
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
RectangleFormRadioButton.addActionListener(e -> {
|
||||||
|
field.RectangleFormRadioButtonAction(block);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
RoundFormRadioButton.addActionListener(e -> {
|
||||||
|
field.RoundFormRadioButtonAction(block);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
TriangleFormRadioButton.addActionListener(e -> {
|
||||||
|
field.TriangleFormRadioButtonAction(block);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ShowWarshipButton.addActionListener(e -> {
|
||||||
|
field.ShowWarshipButtonAction();
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ChooseButton.addActionListener(e -> {
|
||||||
|
Close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public void Close(){
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
public void Open(){
|
||||||
|
field.RemoveSelect();
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
public CreaterGenericField GetField(){
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
public void ReDraw(){
|
||||||
|
Graphics graphics = PictureBox.getGraphics();
|
||||||
|
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
PictureBox.paintComponents(graphics);
|
||||||
|
field.Draw(graphics);
|
||||||
|
}
|
||||||
|
}
|
175
src/FormMap.form
175
src/FormMap.form
@ -1,175 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
|
||||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="4" column-count="5" 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="24" width="816" height="551"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<grid id="73281" layout-manager="GridLayoutManager" row-count="1" 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="3" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<component id="9090d" class="javax.swing.JLabel" binding="SpeedLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Скорость: "/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<hspacer id="5a45f">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</hspacer>
|
|
||||||
<component id="c4bc2" class="javax.swing.JLabel" binding="WeightLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" 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>
|
|
||||||
<component id="74fba" class="javax.swing.JLabel" binding="BodyColorLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="2" 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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<hspacer id="6e33b">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</hspacer>
|
|
||||||
<vspacer id="e09c8">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="2" 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="786ee" 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>
|
|
||||||
<grid row="2" column="1" 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="92069" class="javax.swing.JButton" binding="ButtonCreate">
|
|
||||||
<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>
|
|
||||||
<text value="Создать"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="82dd2" class="javax.swing.JButton" binding="ButtonCreateModif">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" 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>
|
|
||||||
<text value="Модификация"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="b99f9" layout-manager="GridLayoutManager" row-count="2" 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="2" column="3" 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="ba264" class="javax.swing.JButton" binding="ButtonDown">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" 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="arrowDown.jpg"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="8f6d" class="javax.swing.JButton" binding="ButtonRight">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" 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="arrowRight.jpg"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="9d65" class="javax.swing.JButton" binding="ButtonLeft">
|
|
||||||
<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>
|
|
||||||
<icon value="arrowLeft.jpg"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="7d46" class="javax.swing.JButton" binding="ButtonUp">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" 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="arrowUp.jpg"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="7affd" 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="2" column="4" 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>
|
|
||||||
<hspacer id="25">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" 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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="81336" 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="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="none"/>
|
|
||||||
<children>
|
|
||||||
<hspacer id="89fd1">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" 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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<component id="fd77d" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="3" row-span="1" col-span="1" 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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</form>
|
|
@ -1,76 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ComponentAdapter;
|
|
||||||
import java.awt.event.ComponentEvent;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class FormMap extends JFrame {
|
|
||||||
private int Width;
|
|
||||||
private int Height;
|
|
||||||
DrawingMap map = new DrawingMap(this);
|
|
||||||
private JButton ButtonDown;
|
|
||||||
private JButton ButtonRight;
|
|
||||||
private JButton ButtonLeft;
|
|
||||||
private JButton ButtonUp;
|
|
||||||
private JButton ButtonCreate;
|
|
||||||
private JButton ButtonCreateModif;
|
|
||||||
public JLabel SpeedLabel;
|
|
||||||
public JLabel WeightLabel;
|
|
||||||
public JLabel BodyColorLabel;
|
|
||||||
private JComboBox ComboBoxSelectorMap;
|
|
||||||
private JPanel PictureBox;
|
|
||||||
|
|
||||||
public FormMap(){
|
|
||||||
super("Военный корабль");
|
|
||||||
setContentPane(PictureBox);
|
|
||||||
setSize(1000,700);
|
|
||||||
Width = getWidth();
|
|
||||||
Height = getHeight();
|
|
||||||
ShowWindow();
|
|
||||||
map.setBounds(0,0,Width,Height);
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ShowWindow(){
|
|
||||||
ButtonCreate.addActionListener(e -> {
|
|
||||||
map.CreateButtonAction();
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
ButtonCreateModif.addActionListener(e -> {
|
|
||||||
map.CreateModifButtonAction();
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
ButtonUp.addActionListener(e -> {
|
|
||||||
map.DirectionButtonAction(Direction.Up);
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
ButtonLeft.addActionListener(e -> {
|
|
||||||
map.DirectionButtonAction(Direction.Left);
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
ButtonRight.addActionListener(e -> {
|
|
||||||
map.DirectionButtonAction(Direction.Right);
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
ButtonDown.addActionListener(e -> {
|
|
||||||
map.DirectionButtonAction(Direction.Down);
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
|
|
||||||
ComboBoxSelectorMap.addActionListener(e -> {
|
|
||||||
map.ComboBoxSelectorMapAction(Objects.requireNonNull(ComboBoxSelectorMap.getSelectedItem()).toString());
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
private void ReDraw()
|
|
||||||
{
|
|
||||||
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
|
||||||
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
|
||||||
PictureBox.paintComponents(graphics);
|
|
||||||
map.DrawMap(graphics);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
136
src/FormMapWithSetWarships.form
Normal file
136
src/FormMapWithSetWarships.form
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetWarships">
|
||||||
|
<grid id="27dc6" binding="MainPanel" 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="8" y="20" width="691" height="470"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="7fa54" 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>
|
||||||
|
<hspacer id="53f34">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="4ec10" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="9" 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="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="bevel-lowered" title="Инструменты" title-justification="1" title-position="2">
|
||||||
|
<font/>
|
||||||
|
</border>
|
||||||
|
<children>
|
||||||
|
<component id="cd72b" class="javax.swing.JComboBox" binding="СomboBoxSelectorMap">
|
||||||
|
<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="Вторая карта"/>
|
||||||
|
</model>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<vspacer id="b5fa4">
|
||||||
|
<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>
|
||||||
|
<component id="5312c" class="javax.swing.JButton" binding="ButtonAddWarship">
|
||||||
|
<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="d2569" class="javax.swing.JButton" binding="ButtonRemoveWarship">
|
||||||
|
<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="a8d48" 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="c5558" 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="11722" class="javax.swing.JButton" binding="ButtonDown">
|
||||||
|
<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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowDown.jpg"/>
|
||||||
|
<selectedIcon value="arrowDown.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="a2c02" class="javax.swing.JButton" binding="ButtonUp">
|
||||||
|
<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="arrowUp.jpg"/>
|
||||||
|
<selectedIcon value="arrowUp.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="2380f" class="javax.swing.JButton" binding="ButtonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" 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="arrowLeft.jpg"/>
|
||||||
|
<selectedIcon value="arrowLeft.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="de75d" class="javax.swing.JButton" binding="ButtonRight">
|
||||||
|
<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"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowRight.jpg"/>
|
||||||
|
<selectedIcon value="arrowRight.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b49b1" class="javax.swing.JTextField" binding="TextBoxPosition">
|
||||||
|
<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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
84
src/FormMapWithSetWarships.java
Normal file
84
src/FormMapWithSetWarships.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
|
public class FormMapWithSetWarships extends JFrame{
|
||||||
|
DrawingDocks dock = new DrawingDocks(this);
|
||||||
|
private JComboBox СomboBoxSelectorMap;
|
||||||
|
private JButton ButtonAddWarship;
|
||||||
|
private JTextField TextBoxPosition;
|
||||||
|
private JButton ButtonRemoveWarship;
|
||||||
|
private JButton ButtonShowStorage;
|
||||||
|
private JButton ButtonShowOnMap;
|
||||||
|
private JButton ButtonDown;
|
||||||
|
private JButton ButtonUp;
|
||||||
|
private JButton ButtonLeft;
|
||||||
|
private JButton ButtonRight;
|
||||||
|
private JPanel GroupBoxTools;
|
||||||
|
private JPanel PictureBox;
|
||||||
|
private JPanel MainPanel;
|
||||||
|
|
||||||
|
public FormMapWithSetWarships(){
|
||||||
|
super("Военный корабль");
|
||||||
|
setContentPane(MainPanel);
|
||||||
|
setResizable(false);
|
||||||
|
setSize(1000,700);
|
||||||
|
ShowWindow();
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowWindow(){
|
||||||
|
|
||||||
|
ButtonShowOnMap.addActionListener(e -> {
|
||||||
|
dock.ShowOnMapButtonAction();
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonShowStorage.addActionListener(e -> {
|
||||||
|
dock.ShowStorageButtonAction();
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonAddWarship.addActionListener(e -> {
|
||||||
|
dock.AddWarshipButtonAction();
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonRemoveWarship.addActionListener(e -> {
|
||||||
|
dock.DeleteWarshipButtonAction(TextBoxPosition.getText(),PictureBox);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
|
||||||
|
СomboBoxSelectorMap.addActionListener(e -> {
|
||||||
|
dock.ComboBoxAction(СomboBoxSelectorMap.getSelectedItem().toString(),PictureBox);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonUp.addActionListener(e -> {
|
||||||
|
dock.DirectionButtonAction(Direction.Up);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonDown.addActionListener(e -> {
|
||||||
|
dock.DirectionButtonAction(Direction.Down);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonRight.addActionListener(e -> {
|
||||||
|
dock.DirectionButtonAction(Direction.Right);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonLeft.addActionListener(e -> {
|
||||||
|
dock.DirectionButtonAction(Direction.Left);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public void ReDraw(){
|
||||||
|
Graphics graphics = MainPanel.getGraphics();
|
||||||
|
graphics.clearRect(0, 0, MainPanel.getWidth(), MainPanel.getHeight());
|
||||||
|
MainPanel.paintComponents(graphics);
|
||||||
|
dock.DrawDock(graphics);
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarship">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarship">
|
||||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="6" 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>
|
||||||
<xy x="20" y="20" width="637" height="507"/>
|
<xy x="20" y="20" width="660" height="507"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@ -11,7 +11,7 @@
|
|||||||
<grid id="11e3d" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="11e3d" layout-manager="GridLayoutManager" row-count="1" column-count="4" 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="5" 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="6" 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="none"/>
|
||||||
@ -50,7 +50,7 @@
|
|||||||
<grid id="ba3a6" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="ba3a6" layout-manager="GridLayoutManager" row-count="2" column-count="3" 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="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="4" 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="none"/>
|
||||||
@ -132,7 +132,7 @@
|
|||||||
<grid id="e85d9" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="e85d9" 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="1" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="5" 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="none"/>
|
||||||
@ -159,6 +159,24 @@
|
|||||||
</hspacer>
|
</hspacer>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
|
<grid id="c2e3" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="f6508" class="javax.swing.JButton" binding="ButtonSelect">
|
||||||
|
<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>
|
||||||
|
<text value="Выбрать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</form>
|
</form>
|
||||||
|
@ -3,10 +3,11 @@ import java.awt.*;
|
|||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
public class FormWarship extends JFrame{
|
public class FormWarship extends JDialog{
|
||||||
private int Width;
|
private int Width;
|
||||||
private int Height;
|
private int Height;
|
||||||
DrawingField field = new DrawingField(this);
|
DrawingField field = new DrawingField(this);
|
||||||
|
DrawingWarship SelectedWarship;
|
||||||
private JButton ButtonDown;
|
private JButton ButtonDown;
|
||||||
private JButton ButtonRight;
|
private JButton ButtonRight;
|
||||||
private JButton ButtonLeft;
|
private JButton ButtonLeft;
|
||||||
@ -17,16 +18,17 @@ public class FormWarship extends JFrame{
|
|||||||
public JLabel WeightLabel;
|
public JLabel WeightLabel;
|
||||||
public JLabel BodyColorLabel;
|
public JLabel BodyColorLabel;
|
||||||
private JPanel PictureBox;
|
private JPanel PictureBox;
|
||||||
|
private JButton ButtonSelect;
|
||||||
|
|
||||||
public FormWarship(){
|
public FormWarship(JFrame frame){
|
||||||
super("Военный корабль");
|
super(frame,"Военный корабль");
|
||||||
setContentPane(PictureBox);
|
setContentPane(PictureBox);
|
||||||
setSize(1000,700);
|
setSize(1000,700);
|
||||||
Width = getWidth();
|
Width = getWidth();
|
||||||
Height = getHeight();
|
Height = getHeight();
|
||||||
ShowWindow();
|
ShowWindow();
|
||||||
field.setBounds(0,0,Width,Height);
|
field.setBounds(0,0,Width,Height);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +58,10 @@ public class FormWarship extends JFrame{
|
|||||||
field.DirectionButtonAction(Direction.Down);
|
field.DirectionButtonAction(Direction.Down);
|
||||||
ReDraw();
|
ReDraw();
|
||||||
});
|
});
|
||||||
|
ButtonSelect.addActionListener(e -> {
|
||||||
|
SelectedWarship=field.GetDrawingWarship();
|
||||||
|
JOptionPane.showMessageDialog(PictureBox, "Корабль добавлен.");
|
||||||
|
});
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
addComponentListener(new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
@ -70,8 +76,7 @@ public class FormWarship extends JFrame{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private void ReDraw()
|
private void ReDraw() {
|
||||||
{
|
|
||||||
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
||||||
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
PictureBox.paintComponents(graphics);
|
PictureBox.paintComponents(graphics);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new FormMap();
|
new FormMapWithSetWarships();
|
||||||
}
|
}
|
||||||
}
|
}
|
121
src/MapWithSetWarshipsGeneric.java
Normal file
121
src/MapWithSetWarshipsGeneric.java
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
public class MapWithSetWarshipsGeneric<T extends IDrawingObject,U extends AbstractMap> {
|
||||||
|
private final int _pictureWidth;
|
||||||
|
private final int _pictureHeight;
|
||||||
|
private final int _placeSizeWidth = 120;
|
||||||
|
private final int _placeSizeHeight = 50;
|
||||||
|
private final SetWarshipsGeneric<T> _setWarship;
|
||||||
|
private final U _map;
|
||||||
|
|
||||||
|
public MapWithSetWarshipsGeneric(int picWidth,int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight/_placeSizeHeight;
|
||||||
|
_setWarship = new SetWarshipsGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int plus(T warship)
|
||||||
|
{
|
||||||
|
return _setWarship.Insert(warship);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T minus(int position)
|
||||||
|
{
|
||||||
|
return _setWarship.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage ShowSet()
|
||||||
|
{
|
||||||
|
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureWidth,1);
|
||||||
|
Graphics gr = bmp.getGraphics();
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawWarship(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
for (int i = 0; i < _setWarship.Count(); i++)
|
||||||
|
{
|
||||||
|
T warship = _setWarship.Get(i);
|
||||||
|
if (warship != null)
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, warship);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new BufferedImage(_pictureWidth, _pictureHeight,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
return _map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return new BufferedImage(_pictureWidth, _pictureHeight,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setWarship.Count() - 1;
|
||||||
|
for (int i = 0; i < _setWarship.Count(); i++)
|
||||||
|
{
|
||||||
|
if (_setWarship.Get(i) == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
T warship = _setWarship.Get(j);
|
||||||
|
if (warship != null)
|
||||||
|
{
|
||||||
|
_setWarship.Insert(warship, i);
|
||||||
|
_setWarship.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBackground(Graphics gr)
|
||||||
|
{
|
||||||
|
Graphics2D g=(Graphics2D)gr;
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
BasicStroke pen = new BasicStroke(5);
|
||||||
|
g.setStroke(pen);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawWarship(Graphics gr)
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
|
for (int i = 0; i < _setWarship.Count(); i++)
|
||||||
|
{
|
||||||
|
if (_setWarship.Get(i) != null)
|
||||||
|
{
|
||||||
|
_setWarship.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||||
|
_setWarship.Get(i).DrawingObject(gr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
src/SetWarshipsGeneric.java
Normal file
68
src/SetWarshipsGeneric.java
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
public class SetWarshipsGeneric<T extends Object> {
|
||||||
|
private final Object[] _places;
|
||||||
|
|
||||||
|
public int Count() {
|
||||||
|
return _places.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetWarshipsGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new Object[count];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T warship)
|
||||||
|
{
|
||||||
|
return Insert(warship,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T warship, int position)
|
||||||
|
{
|
||||||
|
int EmptyEl=-1;
|
||||||
|
|
||||||
|
if (position>=Count() || position < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (_places[position] == null)
|
||||||
|
{
|
||||||
|
_places[position] = warship;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (_places[position] != null)
|
||||||
|
{
|
||||||
|
for (int i = position + 1; i < Count(); i++)
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
EmptyEl = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EmptyEl == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (int i = EmptyEl; i > position; i--)
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
_places[position] = warship;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (position >= Count() || position < 0 || _places[position]==null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
T deleted =(T)_places[position];
|
||||||
|
_places[position] = null;
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Get(int position)
|
||||||
|
{
|
||||||
|
if (position >= Count() || position < 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return (T)_places[position];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user