Изменения в формах, добавление доп. задания

This commit is contained in:
Inohara 2022-11-03 18:06:25 +04:00
parent 0391fff9dc
commit 86539b4d23
12 changed files with 269 additions and 494 deletions

View File

@ -8,6 +8,11 @@ public class DrawingAircraftCarrier extends DrawingWarship{
Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, cabin, superEngine); Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, cabin, superEngine);
} }
public DrawingAircraftCarrier(EntityWarship warship, IDrawingObjectBlock additionalObject) {
super(warship, additionalObject);
Warship = warship;
}
@Override @Override
public void DrawTransport(Graphics gr){ public void DrawTransport(Graphics gr){
if(!(Warship instanceof EntityAircraftCarrier)) if(!(Warship instanceof EntityAircraftCarrier))
@ -79,4 +84,4 @@ public class DrawingAircraftCarrier extends DrawingWarship{
g2.drawRect(_startPosX + 85, _startPosY + 13, 10, 14); g2.drawRect(_startPosX + 85, _startPosY + 13, 10, 14);
} }
} }
} }

View File

@ -1,67 +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 rnd = new Random();
warship.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), getWidth(),getHeight());
Map.toolBarLabelSpeed.setText("Color: " + warship.GetWarship().GetSpeed() + " ");
Map.toolBarLabelWieght.setText("Weight: " + warship.GetWarship().GetWeight() + " ");
Map.toolBarLabelColor.setText("Color: " + warship.GetWarship().GetBodyColor().getRed() + " " +
warship.GetWarship().GetBodyColor().getGreen() + " " + warship.GetWarship().GetBodyColor().getBlue());
bufferedImage = _abstractMap.CreateMap(750,550,new DrawingObjectWarship(warship));
}
//Создание обычного корабля
public void CreateButtonAction(){
Random rnd=new Random();
DrawingWarship warship=new DrawingWarship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(3));
SetData(warship);
}
//Создание модифицированного корабля
public void CreateModifButtonAction(){
Random rnd = new Random();
DrawingWarship warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
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 LineMap();
break;
}
}
public void DrawMap(Graphics g){
g.drawImage(bufferedImage,0,0,null);
}
}

View File

@ -31,6 +31,11 @@ public class DrawingWarship {
_warshipHeight = warshipHeight; _warshipHeight = warshipHeight;
} }
public DrawingWarship(EntityWarship warship,IDrawingObjectBlock block){
Warship = warship;
Blocks = block;
}
public int BlockRandom(){ public int BlockRandom(){
Random rnd = new Random(); Random rnd = new Random();
int count = rnd.nextInt(0,3); int count = rnd.nextInt(0,3);

View File

@ -1,137 +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="mainPanel" 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>
<xy x="20" y="20" width="897" height="504"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<toolbar id="ced8" binding="toolBar">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="20"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="7c17c" class="javax.swing.JLabel" binding="toolBarLabelSpeed">
<constraints/>
<properties>
<text value="Speed"/>
</properties>
</component>
<component id="a7229" class="javax.swing.JLabel" binding="toolBarLabelWieght">
<constraints/>
<properties>
<text value="Weight"/>
</properties>
</component>
<component id="7c70" class="javax.swing.JLabel" binding="toolBarLabelColor">
<constraints/>
<properties>
<text value="Color"/>
</properties>
</component>
</children>
</toolbar>
<grid id="3b625" binding="drawPanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" 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="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="c54f8" class="javax.swing.JButton" binding="buttonCreate">
<constraints>
<grid row="3" 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="Create"/>
</properties>
</component>
<hspacer id="a1d54">
<constraints>
<grid row="3" 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="4c365">
<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>
<component id="aaec9" class="javax.swing.JButton" binding="buttonCreateModif">
<constraints>
<grid row="3" 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="Modificarion"/>
</properties>
</component>
<component id="c7660" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="3" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="e0470" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="a6de2" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="633e1" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="e1523" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
<constraints>
<grid row="0" column="3" 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>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -1,84 +0,0 @@
import javax.swing.*;
import java.awt.*;
import java.util.Objects;
public class FormMap extends JFrame{
DrawingMap map = new DrawingMap(this);
private JPanel mainPanel;
private JToolBar toolBar;
public JLabel toolBarLabelSpeed;
public JLabel toolBarLabelWieght;
public JLabel toolBarLabelColor;
private JButton buttonCreate;
private JButton buttonCreateModif;
private JButton buttonRight;
private JButton buttonUp;
private JButton buttonDown;
private JButton buttonLeft;
private JComboBox ComboBoxSelectorMap;
private JPanel drawPanel;
public FormMap(){
InitializeComponent();
}
private void InitializeComponent() {
setContentPane(mainPanel);
setTitle("Warship");
setSize(900, 700);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
Icon iconUp = new ImageIcon("src\\Images\\ArrowUp.jpg");
buttonUp.setIcon(iconUp);
Icon iconDown = new ImageIcon("src\\Images\\ArrowDown.jpg");
buttonDown.setIcon(iconDown);
Icon iconLeft = new ImageIcon("src\\Images\\ArrowLeft.jpg");
buttonLeft.setIcon(iconLeft);
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
buttonRight.setIcon(iconRight);
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) drawPanel.getGraphics();
graphics.clearRect(0, 0, drawPanel.getWidth(), drawPanel.getHeight());
drawPanel.paintComponents(graphics);
map.DrawMap(graphics);
}
}

View File

@ -43,8 +43,8 @@
</constraints> </constraints>
<properties> <properties>
<model> <model>
<item value="Первая карта"/> <item value="Простая карта"/>
<item value="Вторая карта"/> <item value="Преграды-линии"/>
</model> </model>
</properties> </properties>
</component> </component>

View File

@ -2,8 +2,6 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class FormMapWithSetWarships extends JFrame{ public class FormMapWithSetWarships extends JFrame{
private JPanel mainPanel; private JPanel mainPanel;
@ -24,8 +22,15 @@ public class FormMapWithSetWarships extends JFrame{
public FormMapWithSetWarships(){ public FormMapWithSetWarships(){
InitializeComponent(); InitializeComponent();
}
@Override
public void paint(Graphics g) {
super.paint(g);
if (bufferedImage != null) {
PictureBox.paintComponents(bufferedImage.getGraphics());
PictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
}
} }
public void InitializeComponent(){ public void InitializeComponent(){
@ -48,7 +53,7 @@ public class FormMapWithSetWarships extends JFrame{
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
AbstractMap map = null; AbstractMap map = null;
switch ((String) СomboBoxSelectorMap.getSelectedItem()){ switch (СomboBoxSelectorMap.getSelectedItem().toString()){
case "Простая карта": case "Простая карта":
map = new SimpleMap(); map = new SimpleMap();
break; break;
@ -67,87 +72,103 @@ public class FormMapWithSetWarships extends JFrame{
} }
}); });
ButtonAddWarship.addActionListener(new ActionListener() { ButtonAddWarship.addActionListener(e -> {
@Override if(_mapWarshipsCollectionGeneric == null){
public void actionPerformed(ActionEvent e) { System.out.println("null");
if(_mapWarshipsCollectionGeneric == null){ return;
return;
}
FormWarship form = new FormWarship();
form.setSize(1200,700);
form.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
form.setVisible(true);
form.addWindowListener(new WindowAdapter() {
@Override
public void windowDeactivated(WindowEvent e) {
DrawingObjectWarship warship = new DrawingObjectWarship(form.getSelectedCar());
if (_mapWarshipsCollectionGeneric.add(warship) > 0)
{
if (form.DialogResult)
JOptionPane.showMessageDialog(null, "Объект добавлен");
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
repaint();
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
}
});
} }
}); FormWarshipCreator warshipCreator = new FormWarshipCreator();
warshipCreator.setSize(1200,700);
warshipCreator.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
warshipCreator.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
warshipCreator.setVisible(true);
if (warshipCreator.getSelectedWarship() != null) {
DrawingObjectWarship warship = new DrawingObjectWarship(warshipCreator.getSelectedWarship());
ButtonRemoveWarship.addActionListener(new ActionListener() { if (_mapWarshipsCollectionGeneric.add(warship) >= 0) {
@Override JOptionPane.showMessageDialog(this,
public void actionPerformed(ActionEvent e) { "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
String text = TextBoxPosition.getText();
if (text == null || _mapWarshipsCollectionGeneric == null || text.isEmpty())
{
return;
}
int result = JOptionPane.showConfirmDialog(
null,
"Удалить объект?",
"Удаление",
JOptionPane.YES_NO_CANCEL_OPTION);
if (result == JOptionPane.NO_OPTION)
{
return;
}
int pos = Integer.parseInt(text);
if (_mapWarshipsCollectionGeneric.remove(pos) != null)
{
JOptionPane.showMessageDialog(null,"Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE);
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet(); bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
repaint(); repaint();
} } else {
else JOptionPane.showMessageDialog(this,
{ "Не удалось добавить объект", "Ошибка",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE);
} }
} }
}); });
ButtonShowStorage.addActionListener(new ActionListener() { ButtonRemoveWarship.addActionListener(e -> {
@Override String text = TextBoxPosition.getText();
public void actionPerformed(ActionEvent e) { if (text == null || _mapWarshipsCollectionGeneric == null || text.isEmpty())
if(_mapWarshipsCollectionGeneric == null) {
{ return;
return; }
} int result = JOptionPane.showConfirmDialog(
null,
"Удалить объект?",
"Удаление",
JOptionPane.YES_NO_CANCEL_OPTION);
if (result == JOptionPane.NO_OPTION)
{
return;
}
int pos = Integer.parseInt(text);
if (_mapWarshipsCollectionGeneric.remove(pos) != null)
{
JOptionPane.showMessageDialog(this,
"Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE);
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet(); bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
repaint(); repaint();
} }
else
{
JOptionPane.showMessageDialog(this,
"Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE);
}
});
ButtonShowStorage.addActionListener(e -> {
if(_mapWarshipsCollectionGeneric == null)
{
return;
}
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
repaint();
});
ButtonShowOnMap.addActionListener(e -> {
if (_mapWarshipsCollectionGeneric == null)
{
return;
}
bufferedImage = _mapWarshipsCollectionGeneric.ShowOnMap();
repaint();
});
ButtonUp.addActionListener(e -> {
if (_mapWarshipsCollectionGeneric != null) {
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Up);
repaint();
}
}); });
ButtonShowOnMap.addActionListener(new ActionListener() { ButtonDown.addActionListener(e -> {
@Override if (_mapWarshipsCollectionGeneric != null) {
public void actionPerformed(ActionEvent e) { bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Down);
if (_mapWarshipsCollectionGeneric == null) repaint();
{ }
return; });
}
bufferedImage = _mapWarshipsCollectionGeneric.ShowOnMap(); ButtonRight.addActionListener(e -> {
if (_mapWarshipsCollectionGeneric != null) {
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Right);
repaint();
}
});
ButtonLeft.addActionListener(e -> {
if (_mapWarshipsCollectionGeneric != null) {
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Left);
repaint(); repaint();
} }
}); });

View File

@ -1,7 +1,5 @@
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
import java.util.Random; import java.util.Random;
@ -69,71 +67,50 @@ public class FormWarship extends JFrame {
buttonRight.setIcon(iconRight); buttonRight.setIcon(iconRight);
//кнопка добавления объекта //кнопка добавления объекта
buttonCreate.addActionListener(new ActionListener() { buttonCreate.addActionListener(e -> {
@Override Random rnd = new Random();
public void actionPerformed(ActionEvent e) { _warship = new DrawingWarship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
Random rnd = new Random(); new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(3));
_warship = new DrawingWarship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), SetData();
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(3)); Draw();
SetData();
Draw();
}
}); });
//добавление модифицированного объекта //добавление модифицированного объекта
buttonCreateModif.addActionListener(new ActionListener() { buttonCreateModif.addActionListener(e -> {
@Override Random rnd = new Random();
public void actionPerformed(ActionEvent e) { _warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
Random rnd = new Random(); new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
_warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), SetData();
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean()); Draw();
SetData(); });
Draw();
buttonSelect.addActionListener(e -> {
if(_warship != null){
selectedWarship =_warship;
DialogResult = true;
} }
}); });
buttonSelect.addActionListener(new ActionListener() { buttonLeft.addActionListener(e -> {
@Override if (_warship != null) _warship.MoveTransport(Direction.Left);
public void actionPerformed(ActionEvent e) { Draw();
if(_warship != null){
selectedWarship =_warship;
DialogResult = true;
}
}
}); });
buttonLeft.addActionListener(new ActionListener() { buttonRight.addActionListener(e -> {
@Override if (_warship != null) _warship.MoveTransport(Direction.Right);
public void actionPerformed(ActionEvent e) { Draw();
if (_warship != null) _warship.MoveTransport(Direction.Left);
Draw();
}
}); });
buttonRight.addActionListener(new ActionListener() { buttonUp.addActionListener(e -> {
@Override if (_warship != null) _warship.MoveTransport(Direction.Up);
public void actionPerformed(ActionEvent e) { Draw();
if (_warship != null) _warship.MoveTransport(Direction.Right);
Draw();
}
}); });
buttonUp.addActionListener(new ActionListener() { buttonDown.addActionListener(e -> {
@Override if (_warship != null) _warship.MoveTransport(Direction.Down);
public void actionPerformed(ActionEvent e) { Draw();
if (_warship != null) _warship.MoveTransport(Direction.Up);
Draw();
}
});
buttonDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_warship != null) _warship.MoveTransport(Direction.Down);
Draw();
}
}); });
mainPanel.addComponentListener(new ComponentAdapter() { mainPanel.addComponentListener(new ComponentAdapter() {

View File

@ -8,7 +8,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<grid id="b8cad" binding="PropertiesPanel" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <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">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@ -20,13 +20,13 @@
<children> <children>
<vspacer id="3ff70"> <vspacer id="3ff70">
<constraints> <constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> <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> </constraints>
</vspacer> </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="fee11" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="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="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> </constraints>
<properties/> <properties/>
<border type="etched" title="Тип корабля:"/> <border type="etched" title="Тип корабля:"/>
@ -49,52 +49,10 @@
</component> </component>
</children> </children>
</grid> </grid>
<grid id="f9f1b" 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="10585" 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="8b062" 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="d443" 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="4ca48" 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="41669" binding="CargoPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <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"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <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"/> <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> </constraints>
<properties/> <properties/>
<border type="etched" title="Характеристики груза:"/> <border type="etched" title="Характеристики груза:"/>
@ -129,7 +87,7 @@
<grid id="21a40" binding="CountOfBlocksPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="21a40" binding="CountOfBlocksPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="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"/> <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> </constraints>
<properties/> <properties/>
<border type="etched" title="Количество ящиков:"/> <border type="etched" title="Количество ящиков:"/>
@ -163,7 +121,7 @@
<grid id="15d71" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <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"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="6" 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="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> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
@ -190,16 +148,16 @@
</grid> </grid>
<vspacer id="6c05e"> <vspacer id="6c05e">
<constraints> <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"/> <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> </constraints>
</vspacer> </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" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="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="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> </constraints>
<properties/> <properties/>
<border type="etched" title="Улучшения:"/> <border type="etched" title="Modification"/>
<children> <children>
<component id="c96ee" class="javax.swing.JCheckBox" binding="MissileCheckBox"> <component id="c96ee" class="javax.swing.JCheckBox" binding="MissileCheckBox">
<constraints> <constraints>
@ -224,8 +182,8 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<label value="Вертолетная площадка"/> <label value="Посадочная площадка"/>
<text value="Вертолетная площадка"/> <text value="Посадочная площадка"/>
</properties> </properties>
</component> </component>
</children> </children>

View File

@ -1,4 +1,6 @@
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class FormWarshipCreator extends JDialog{ public class FormWarshipCreator extends JDialog{
private JPanel PictureBox; private JPanel PictureBox;
@ -7,8 +9,6 @@ public class FormWarshipCreator extends JDialog{
private JRadioButton AdvancedRadioButton; private JRadioButton AdvancedRadioButton;
private JTextField WeightTextField; private JTextField WeightTextField;
private JTextField SpeedTextField; private JTextField SpeedTextField;
private JLabel SetWeightLabel;
private JLabel SetSpeedLabel;
private JPanel CargoPanel; private JPanel CargoPanel;
private JRadioButton TriangleFormRadioButton; private JRadioButton TriangleFormRadioButton;
private JRadioButton RoundFormRadioButton; private JRadioButton RoundFormRadioButton;
@ -22,9 +22,108 @@ public class FormWarshipCreator extends JDialog{
private JCheckBox MissileCheckBox; private JCheckBox MissileCheckBox;
private JCheckBox AntennaCheckBox; private JCheckBox AntennaCheckBox;
private JCheckBox HelipadCheckBox; private JCheckBox HelipadCheckBox;
BlockCount block=null; BlockCount _block = null;
IDrawingObjectBlock fblock=null; IDrawingObjectBlock objectBlock = null;
private final CreaterGeneric<EntityWarship,IDrawingObjectBlock> createrGeneric=new CreaterGeneric<>(40,40); private final WarshipCreatorGeneric<EntityWarship,IDrawingObjectBlock> createrGeneric=new WarshipCreatorGeneric<>(40,40);
private DrawingWarship _warship; private DrawingWarship _warship;
private DrawingWarship selectedWarship; private DrawingWarship selectedWarship;
public FormWarshipCreator(){
InitializeComponent();
}
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) PictureBox.getGraphics();
if (_warship != null) {
_warship.DrawTransport(g2d);
}
}
public DrawingWarship getSelectedWarship() {
return selectedWarship;
}
private void InitializeComponent(){
setContentPane(PictureBox);
setTitle("Warship");
setResizable(false);
setSize(900, 700);
TwoRadioButton.addActionListener(e -> {
_block =BlockCount.TwoBlocks;
});
FourRadioButton.addActionListener(e -> {
_block =BlockCount.FourBlocks;
});
SixRadioButton.addActionListener(e -> {
_block =BlockCount.SixBlocks;
});
RectangleFormRadioButton.addActionListener(e -> {
if(_block ==null){
return;
}
objectBlock =new DrawingBlocks(_block);
if(objectBlock ==null)
return;
objectBlock.SetBlockCount(_block.GetBlockCount());
createrGeneric.AddBlock(objectBlock);
});
RoundFormRadioButton.addActionListener(e -> {
if(_block ==null){
return;
}
objectBlock =new DrawingRoundBlocks(_block);
if(objectBlock ==null)
return;
objectBlock.SetBlockCount(_block.GetBlockCount());
createrGeneric.AddBlock(objectBlock);
});
TriangleFormRadioButton.addActionListener(e -> {
if(_block ==null){
return;
}
objectBlock =new DrawingRoundBlocks(_block);
if(objectBlock ==null)
return;
objectBlock.SetBlockCount(_block.GetBlockCount());
createrGeneric.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));
});
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()));
});
ShowWarshipButton.addActionListener(e -> {
Random rand=new Random();
_warship=createrGeneric.NewWarshipCreating();
_warship.SetPosition(rand.nextInt(100),rand.nextInt(100),getWidth(),getHeight());
repaint();
});
ChooseButton.addActionListener(e -> {
selectedWarship=_warship;
dispose();
});
}
} }

View File

@ -2,5 +2,4 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
new FormMapWithSetWarships(); new FormMapWithSetWarships();
} }
} }

View File

@ -1,40 +1,39 @@
import java.util.Random; import java.util.Random;
public class WarshipCreatorGeneric <T extends EntityWarship, U extends IDrawingObjectBlock>{ public class WarshipCreatorGeneric <T extends EntityWarship, U extends IDrawingObjectBlock>{
T[] Warships; private final EntityWarship[] Warships;
U[] Blocks; private final IDrawingObjectBlock[] Blocks;
int WarshipsCount = 0; private int WarshipsCount = 0;
int BlocksCount = 0; private int BlocksCount = 0;
public WarshipCreatorGeneric(int warshipsCount, int blocksCount){ public WarshipCreatorGeneric(int warshipsCount, int blocksCount){
Warships = (T[])new Object[warshipsCount]; Warships = new EntityWarship[warshipsCount];
Blocks = (U[]) new Object[blocksCount]; Blocks = new IDrawingObjectBlock[blocksCount];
WarshipsCount = warshipsCount;
BlocksCount = blocksCount;
} }
public int AddWarship(T warship){ public int AddWarship(T warship){
if(WarshipsCount<Warships.length){ if(WarshipsCount < Warships.length){
Warships[WarshipsCount]=warship; Warships[WarshipsCount] = warship;
WarshipsCount++; WarshipsCount++;
return WarshipsCount-1; return WarshipsCount - 1;
} }
return -1; return -1;
} }
public int AddBlock(U block){ public int AddBlock(U block){
if(BlocksCount<Blocks.length){ if(BlocksCount < Blocks.length){
Blocks[BlocksCount]=block; Blocks[BlocksCount] = block;
BlocksCount++; BlocksCount++;
return BlocksCount-1; return BlocksCount - 1;
} }
return -1; return -1;
} }
public DrawingWarship NewWarshipCreating() public DrawingWarship NewWarshipCreating()
{ {
Random rand=new Random(); Random rand=new Random();
T warship = Warships[rand.nextInt(WarshipsCount)]; T warship = (T)Warships[rand.nextInt(WarshipsCount)];
U block = Blocks[rand.nextInt(BlocksCount)]; U block = (U)Blocks[rand.nextInt(BlocksCount)];
if(warship instanceof EntityAircraftCarrier){ if(warship instanceof EntityAircraftCarrier){
return new DrawingAircraftCarrier(warship,block); return new DrawingAircraftCarrier(warship, block);
} }
return new DrawingWarship(warship,block); return new DrawingWarship(warship,block);
} }