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

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);
}
public DrawingAircraftCarrier(EntityWarship warship, IDrawingObjectBlock additionalObject) {
super(warship, additionalObject);
Warship = warship;
}
@Override
public void DrawTransport(Graphics gr){
if(!(Warship instanceof EntityAircraftCarrier))

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;
}
public DrawingWarship(EntityWarship warship,IDrawingObjectBlock block){
Warship = warship;
Blocks = block;
}
public int BlockRandom(){
Random rnd = new Random();
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>
<properties>
<model>
<item value="Первая карта"/>
<item value="Вторая карта"/>
<item value="Простая карта"/>
<item value="Преграды-линии"/>
</model>
</properties>
</component>

View File

@ -2,8 +2,6 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class FormMapWithSetWarships extends JFrame{
private JPanel mainPanel;
@ -24,8 +22,15 @@ public class FormMapWithSetWarships extends JFrame{
public FormMapWithSetWarships(){
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(){
@ -48,7 +53,7 @@ public class FormMapWithSetWarships extends JFrame{
@Override
public void actionPerformed(ActionEvent e) {
AbstractMap map = null;
switch ((String) СomboBoxSelectorMap.getSelectedItem()){
switch (СomboBoxSelectorMap.getSelectedItem().toString()){
case "Простая карта":
map = new SimpleMap();
break;
@ -67,39 +72,32 @@ public class FormMapWithSetWarships extends JFrame{
}
});
ButtonAddWarship.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonAddWarship.addActionListener(e -> {
if(_mapWarshipsCollectionGeneric == null){
System.out.println("null");
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, "Объект добавлен");
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());
if (_mapWarshipsCollectionGeneric.add(warship) >= 0) {
JOptionPane.showMessageDialog(this,
"Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
repaint();
} else {
JOptionPane.showMessageDialog(this,
"Не удалось добавить объект", "Ошибка",JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
}
});
}
});
ButtonRemoveWarship.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonRemoveWarship.addActionListener(e -> {
String text = TextBoxPosition.getText();
if (text == null || _mapWarshipsCollectionGeneric == null || text.isEmpty())
{
@ -117,38 +115,61 @@ public class FormMapWithSetWarships extends JFrame{
int pos = Integer.parseInt(text);
if (_mapWarshipsCollectionGeneric.remove(pos) != null)
{
JOptionPane.showMessageDialog(null,"Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(this,
"Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE);
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
repaint();
}
else
{
JOptionPane.showMessageDialog(null,"Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE);
}
JOptionPane.showMessageDialog(this,
"Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE);
}
});
ButtonShowStorage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonShowStorage.addActionListener(e -> {
if(_mapWarshipsCollectionGeneric == null)
{
return;
}
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
repaint();
}
});
ButtonShowOnMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonShowOnMap.addActionListener(e -> {
if (_mapWarshipsCollectionGeneric == null)
{
return;
}
bufferedImage = _mapWarshipsCollectionGeneric.ShowOnMap();
repaint();
});
ButtonUp.addActionListener(e -> {
if (_mapWarshipsCollectionGeneric != null) {
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Up);
repaint();
}
});
ButtonDown.addActionListener(e -> {
if (_mapWarshipsCollectionGeneric != null) {
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Down);
repaint();
}
});
ButtonRight.addActionListener(e -> {
if (_mapWarshipsCollectionGeneric != null) {
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Right);
repaint();
}
});
ButtonLeft.addActionListener(e -> {
if (_mapWarshipsCollectionGeneric != null) {
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Left);
repaint();
}
});
}

View File

@ -1,7 +1,5 @@
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.Random;
@ -69,21 +67,16 @@ public class FormWarship extends JFrame {
buttonRight.setIcon(iconRight);
//кнопка добавления объекта
buttonCreate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonCreate.addActionListener(e -> {
Random rnd = new Random();
_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();
Draw();
}
});
//добавление модифицированного объекта
buttonCreateModif.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonCreateModif.addActionListener(e -> {
Random rnd = new Random();
_warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
@ -91,49 +84,33 @@ public class FormWarship extends JFrame {
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
SetData();
Draw();
}
});
buttonSelect.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonSelect.addActionListener(e -> {
if(_warship != null){
selectedWarship =_warship;
DialogResult = true;
}
}
});
buttonLeft.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonLeft.addActionListener(e -> {
if (_warship != null) _warship.MoveTransport(Direction.Left);
Draw();
}
});
buttonRight.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonRight.addActionListener(e -> {
if (_warship != null) _warship.MoveTransport(Direction.Right);
Draw();
}
});
buttonUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonUp.addActionListener(e -> {
if (_warship != null) _warship.MoveTransport(Direction.Up);
Draw();
}
});
buttonDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonDown.addActionListener(e -> {
if (_warship != null) _warship.MoveTransport(Direction.Down);
Draw();
}
});
mainPanel.addComponentListener(new ComponentAdapter() {

View File

@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<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"/>
<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"/>
@ -20,13 +20,13 @@
<children>
<vspacer id="3ff70">
<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>
</vspacer>
<grid id="fee11" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<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>
<properties/>
<border type="etched" title="Тип корабля:"/>
@ -49,52 +49,10 @@
</component>
</children>
</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">
<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"/>
<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="Характеристики груза:"/>
@ -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">
<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"/>
<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="Количество ящиков:"/>
@ -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">
<margin top="0" left="0" bottom="0" right="0"/>
<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>
<properties/>
<border type="none"/>
@ -190,16 +148,16 @@
</grid>
<vspacer id="6c05e">
<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>
</vspacer>
<grid id="5220b" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<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>
<properties/>
<border type="etched" title="Улучшения:"/>
<border type="etched" title="Modification"/>
<children>
<component id="c96ee" class="javax.swing.JCheckBox" binding="MissileCheckBox">
<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"/>
</constraints>
<properties>
<label value="Вертолетная площадка"/>
<text value="Вертолетная площадка"/>
<label value="Посадочная площадка"/>
<text value="Посадочная площадка"/>
</properties>
</component>
</children>

View File

@ -1,4 +1,6 @@
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class FormWarshipCreator extends JDialog{
private JPanel PictureBox;
@ -7,8 +9,6 @@ public class FormWarshipCreator extends JDialog{
private JRadioButton AdvancedRadioButton;
private JTextField WeightTextField;
private JTextField SpeedTextField;
private JLabel SetWeightLabel;
private JLabel SetSpeedLabel;
private JPanel CargoPanel;
private JRadioButton TriangleFormRadioButton;
private JRadioButton RoundFormRadioButton;
@ -22,9 +22,108 @@ public class FormWarshipCreator extends JDialog{
private JCheckBox MissileCheckBox;
private JCheckBox AntennaCheckBox;
private JCheckBox HelipadCheckBox;
BlockCount block=null;
IDrawingObjectBlock fblock=null;
private final CreaterGeneric<EntityWarship,IDrawingObjectBlock> createrGeneric=new CreaterGeneric<>(40,40);
BlockCount _block = null;
IDrawingObjectBlock objectBlock = null;
private final WarshipCreatorGeneric<EntityWarship,IDrawingObjectBlock> createrGeneric=new WarshipCreatorGeneric<>(40,40);
private DrawingWarship _warship;
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) {
new FormMapWithSetWarships();
}
}

View File

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