собранная лаба
This commit is contained in:
parent
1934acdcae
commit
2c9b5d5c13
@ -106,9 +106,7 @@ public class FormMap extends JFrame{
|
|||||||
ButtonRight.addActionListener(e -> {
|
ButtonRight.addActionListener(e -> {
|
||||||
ButtonMove_Click("buttonRight");
|
ButtonMove_Click("buttonRight");
|
||||||
});
|
});
|
||||||
comboBoxSelector.addActionListener(new ActionListener() {
|
comboBoxSelector.addActionListener(e -> {
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
comboBoxSelector = (JComboBox)e.getSource();
|
comboBoxSelector = (JComboBox)e.getSource();
|
||||||
String item = (String)comboBoxSelector.getSelectedItem();
|
String item = (String)comboBoxSelector.getSelectedItem();
|
||||||
switch (item) {
|
switch (item) {
|
||||||
@ -121,7 +119,6 @@ public class FormMap extends JFrame{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
156
FormMapWithSetPlanes.form
Normal file
156
FormMapWithSetPlanes.form
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetPlanes">
|
||||||
|
<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="20" y="20" width="785" height="400"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="afa3d" binding="PictureBox" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||||
|
<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/>
|
||||||
|
</grid>
|
||||||
|
<grid id="e9a63" binding="groupBox" layout-manager="GridLayoutManager" row-count="8" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="f23ee" class="javax.swing.JButton" binding="buttonAdd">
|
||||||
|
<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>
|
||||||
|
<text value="Добавить корабль"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="2e61e" class="javax.swing.JComboBox" binding="comboBoxSelectorMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<model/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="5c428" class="javax.swing.JButton" binding="buttonRemove">
|
||||||
|
<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="Удалить корабль"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="e24b9" class="javax.swing.JButton" binding="buttonShowStorage">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" 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="ac087" class="javax.swing.JButton" binding="buttonShowOnMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" 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>
|
||||||
|
<grid id="2821b" layout-manager="GridLayoutManager" row-count="2" 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>
|
||||||
|
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="6d803" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
|
<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">
|
||||||
|
<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="c0db2" class="javax.swing.JButton" binding="buttonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" 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="ca0da" class="javax.swing.JButton" binding="buttonDown">
|
||||||
|
<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">
|
||||||
|
<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="c3e45" class="javax.swing.JButton" binding="buttonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" 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>
|
||||||
|
<hspacer id="1f200">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<hspacer id="f8b3b">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" 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>
|
||||||
|
<vspacer id="b833e">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" 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="181ac" class="javax.swing.JTextField" binding="textBoxPosition">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" 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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
192
FormMapWithSetPlanes.java
Normal file
192
FormMapWithSetPlanes.java
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class FormMapWithSetPlanes extends JFrame {
|
||||||
|
|
||||||
|
private MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> _mapPlanesCollectionGeneric;
|
||||||
|
|
||||||
|
public JPanel Mainpanel;
|
||||||
|
private JButton buttonAdd;
|
||||||
|
private JComboBox comboBoxSelectorMap;
|
||||||
|
private JTextField textBoxPosition;
|
||||||
|
private JButton buttonRemove;
|
||||||
|
private JButton buttonShowStorage;
|
||||||
|
private JButton buttonShowOnMap;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JPanel PictureBox;
|
||||||
|
private JPanel groupBox;
|
||||||
|
AbstractMap _abstractMap;
|
||||||
|
|
||||||
|
private JFrame getFrame() {
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
frame.setVisible(false);
|
||||||
|
frame.setBounds(300, 100, 800, 600);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
JFrame jFrame = getFrame();
|
||||||
|
|
||||||
|
private void ButtonMove_Click(String name)
|
||||||
|
{
|
||||||
|
if (_mapPlanesCollectionGeneric == null) return;
|
||||||
|
Direction direction = Direction.None;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonLeft":
|
||||||
|
direction = Direction.Left;
|
||||||
|
break;
|
||||||
|
case "buttonUp":
|
||||||
|
direction = Direction.Up;
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
direction = Direction.Right;
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
direction = Direction.Down;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PictureBox.removeAll();
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBox.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.MoveObject(direction)));
|
||||||
|
PictureBox.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBox.revalidate();
|
||||||
|
PictureBox.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormMapWithSetPlanes() {
|
||||||
|
comboBoxSelectorMap.addItem("Простая карта");
|
||||||
|
comboBoxSelectorMap.addItem("Вторая карта");
|
||||||
|
try {
|
||||||
|
Image img = ImageIO.read(FormMap.class.getResource("/Resource/arrowUp.jpg"));
|
||||||
|
buttonUp.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(FormMap.class.getResource("/Resource/arrowDown.jpg"));
|
||||||
|
buttonDown.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(FormMap.class.getResource("/Resource/arrowLeft.jpg"));
|
||||||
|
buttonLeft.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(FormMap.class.getResource("/Resource/arrowRight.jpg"));
|
||||||
|
buttonRight.setIcon(new ImageIcon(img));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
comboBoxSelectorMap.addActionListener(e -> {
|
||||||
|
AbstractMap map = null;
|
||||||
|
switch (comboBoxSelectorMap.getSelectedItem().toString())
|
||||||
|
{
|
||||||
|
case "Простая карта":
|
||||||
|
map = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "Вторая карта":
|
||||||
|
map = new MyMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (map != null)
|
||||||
|
{
|
||||||
|
_mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric(PictureBox.getWidth(), PictureBox.getHeight(), map);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_mapPlanesCollectionGeneric = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonAdd.addActionListener(e -> {
|
||||||
|
if (_mapPlanesCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormPlane dialog = new FormPlane();
|
||||||
|
dialog.setSize(800, 600);
|
||||||
|
dialog.setLocation(500, 200);
|
||||||
|
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
|
||||||
|
if (dialog.GetSelectedPlane() == null) return;
|
||||||
|
|
||||||
|
DrawningObjectPlane plane = new DrawningObjectPlane(dialog.GetSelectedPlane());
|
||||||
|
|
||||||
|
if (_mapPlanesCollectionGeneric.addPlane(plane) != -1)
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(jFrame, "Объект добавлен");
|
||||||
|
PictureBox.removeAll();
|
||||||
|
JLabel imageOfShip = new JLabel();
|
||||||
|
imageOfShip.setPreferredSize(PictureBox.getSize());
|
||||||
|
imageOfShip.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageOfShip.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.ShowSet()));
|
||||||
|
PictureBox.add(imageOfShip,BorderLayout.CENTER);
|
||||||
|
PictureBox.revalidate();
|
||||||
|
PictureBox.repaint();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(jFrame, "Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonRemove.addActionListener(e -> {
|
||||||
|
if(_mapPlanesCollectionGeneric == null) return;
|
||||||
|
|
||||||
|
String text = textBoxPosition.getText();
|
||||||
|
if(text.isEmpty()) return;
|
||||||
|
|
||||||
|
if(JOptionPane.showConfirmDialog(jFrame, "Вы действительно хотите удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Integer.parseInt(text);
|
||||||
|
}
|
||||||
|
catch (Exception ex){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = Integer.parseInt(text);
|
||||||
|
if (_mapPlanesCollectionGeneric.removePlane(pos) != null)
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(jFrame, "Объект удален");
|
||||||
|
PictureBox.removeAll();
|
||||||
|
JLabel imageOfShip = new JLabel();
|
||||||
|
imageOfShip.setPreferredSize(PictureBox.getSize());
|
||||||
|
imageOfShip.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageOfShip.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.ShowSet()));
|
||||||
|
PictureBox.add(imageOfShip,BorderLayout.CENTER);
|
||||||
|
PictureBox.revalidate();
|
||||||
|
PictureBox.repaint();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(jFrame, "Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonShowStorage.addActionListener(e -> {
|
||||||
|
if (_mapPlanesCollectionGeneric == null) return;
|
||||||
|
PictureBox.removeAll();
|
||||||
|
JLabel imageOfShip = new JLabel();
|
||||||
|
imageOfShip.setPreferredSize(PictureBox.getSize());
|
||||||
|
imageOfShip.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageOfShip.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.ShowSet()));
|
||||||
|
PictureBox.add(imageOfShip,BorderLayout.CENTER);
|
||||||
|
PictureBox.revalidate();
|
||||||
|
PictureBox.repaint();
|
||||||
|
});
|
||||||
|
buttonShowOnMap.addActionListener(e -> {
|
||||||
|
if (_mapPlanesCollectionGeneric == null) return;
|
||||||
|
PictureBox.removeAll();
|
||||||
|
JLabel imageOfShip = new JLabel();
|
||||||
|
imageOfShip.setPreferredSize(PictureBox.getSize());
|
||||||
|
imageOfShip.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageOfShip.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.ShowOnMap()));
|
||||||
|
PictureBox.add(imageOfShip,BorderLayout.CENTER);
|
||||||
|
PictureBox.revalidate();
|
||||||
|
PictureBox.repaint();
|
||||||
|
});
|
||||||
|
buttonUp.addActionListener(e -> ButtonMove_Click("buttonUp"));
|
||||||
|
buttonLeft.addActionListener(e -> ButtonMove_Click("buttonLeft"));
|
||||||
|
buttonDown.addActionListener(e -> ButtonMove_Click("buttonDown"));
|
||||||
|
buttonRight.addActionListener(e -> ButtonMove_Click("buttonRight"));
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?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="FormPlane">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormPlane">
|
||||||
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="7" 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="513" height="406"/>
|
<xy x="20" y="20" width="513" height="406"/>
|
||||||
@ -13,7 +13,7 @@
|
|||||||
<children>
|
<children>
|
||||||
<component id="2ea16" class="javax.swing.JButton" binding="ButtonDown">
|
<component id="2ea16" class="javax.swing.JButton" binding="ButtonDown">
|
||||||
<constraints>
|
<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">
|
<grid row="2" 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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -25,7 +25,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="4f60a" class="javax.swing.JButton" binding="ButtonLeft">
|
<component id="4f60a" class="javax.swing.JButton" binding="ButtonLeft">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
<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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -37,7 +37,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="4eb88" class="javax.swing.JButton" binding="ButtonRight">
|
<component id="4eb88" class="javax.swing.JButton" binding="ButtonRight">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
<grid row="2" column="6" 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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -50,7 +50,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<toolbar id="e747d" binding="StatusStrip">
|
<toolbar id="e747d" binding="StatusStrip">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="3" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="3" column="0" row-span="1" col-span="7" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="-1" height="20"/>
|
<minimum-size width="-1" height="20"/>
|
||||||
<preferred-size width="-1" height="20"/>
|
<preferred-size width="-1" height="20"/>
|
||||||
<maximum-size width="-1" height="20"/>
|
<maximum-size width="-1" height="20"/>
|
||||||
@ -72,7 +72,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<grid id="febd4" binding="PictureBox" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
<grid id="febd4" binding="PictureBox" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="6" 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="7" 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"/>
|
||||||
@ -80,7 +80,7 @@
|
|||||||
</grid>
|
</grid>
|
||||||
<component id="fb937" class="javax.swing.JButton" binding="ButtonUp">
|
<component id="fb937" class="javax.swing.JButton" binding="ButtonUp">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
<grid row="1" 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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -98,7 +98,15 @@
|
|||||||
<text value="Модификация"/>
|
<text value="Модификация"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<hspacer id="dd0eb">
|
<component id="f022f" class="javax.swing.JButton" binding="ButtonSelectPlane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="3" 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>
|
||||||
|
<hspacer id="3f9b1">
|
||||||
<constraints>
|
<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"/>
|
<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>
|
</constraints>
|
||||||
|
@ -8,7 +8,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import static java.lang.Boolean.parseBoolean;
|
import static java.lang.Boolean.parseBoolean;
|
||||||
|
|
||||||
public class FormPlane extends JFrame{
|
public class FormPlane extends JDialog{
|
||||||
public JPanel Mainpanel;
|
public JPanel Mainpanel;
|
||||||
private JButton ButtonCreate;
|
private JButton ButtonCreate;
|
||||||
private JButton ButtonLeft;
|
private JButton ButtonLeft;
|
||||||
@ -19,9 +19,14 @@ public class FormPlane extends JFrame{
|
|||||||
private JPanel PictureBox;
|
private JPanel PictureBox;
|
||||||
private JToolBar StatusStrip;
|
private JToolBar StatusStrip;
|
||||||
private JButton ButtonModif;
|
private JButton ButtonModif;
|
||||||
|
private JButton ButtonSelectPlane;
|
||||||
private final JLabel JLabelSpeed = new JLabel();
|
private final JLabel JLabelSpeed = new JLabel();
|
||||||
private final JLabel JLabelWeight = new JLabel();
|
private final JLabel JLabelWeight = new JLabel();
|
||||||
private final JLabel JLabelColor = new JLabel();
|
private final JLabel JLabelColor = new JLabel();
|
||||||
|
private DrawningPlane SelectedPlane;
|
||||||
|
public DrawningPlane GetSelectedPlane() {
|
||||||
|
return SelectedPlane;
|
||||||
|
}
|
||||||
public void Draw() {
|
public void Draw() {
|
||||||
PictureBox.removeAll();
|
PictureBox.removeAll();
|
||||||
BufferedImage bmp = new BufferedImage(PictureBox.getWidth(), PictureBox.getHeight(),BufferedImage.TYPE_INT_RGB);
|
BufferedImage bmp = new BufferedImage(PictureBox.getWidth(), PictureBox.getHeight(),BufferedImage.TYPE_INT_RGB);
|
||||||
@ -46,6 +51,7 @@ public class FormPlane extends JFrame{
|
|||||||
JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " "));
|
JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " "));
|
||||||
}
|
}
|
||||||
public FormPlane() {
|
public FormPlane() {
|
||||||
|
add(Mainpanel);
|
||||||
Box LabelBox = Box.createHorizontalBox();
|
Box LabelBox = Box.createHorizontalBox();
|
||||||
LabelBox.setMinimumSize(new Dimension(1, 20));
|
LabelBox.setMinimumSize(new Dimension(1, 20));
|
||||||
LabelBox.add(JLabelSpeed);
|
LabelBox.add(JLabelSpeed);
|
||||||
@ -66,13 +72,16 @@ public class FormPlane extends JFrame{
|
|||||||
}
|
}
|
||||||
ButtonCreate.addActionListener(e -> {
|
ButtonCreate.addActionListener(e -> {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
_plane = new DrawningPlane(random.nextInt(100, 300),random.nextInt(1000, 2000),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
Color color = JColorChooser.showDialog(null, "Цвет", null);
|
||||||
|
_plane = new DrawningPlane(random.nextInt(100, 300),random.nextInt(1000, 2000),color);
|
||||||
SetData();
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
});
|
});
|
||||||
ButtonModif.addActionListener(e -> {
|
ButtonModif.addActionListener(e -> {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
_plane = new DrawningAirbus(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), random.nextBoolean(), random.nextBoolean(), random.nextBoolean());
|
Color first = JColorChooser.showDialog(null, "Цвет", null);
|
||||||
|
Color second = JColorChooser.showDialog(null, "Цвет", null);
|
||||||
|
_plane = new DrawningAirbus(random.nextInt(100, 300), random.nextInt(1000, 2000), first, second, random.nextBoolean(), random.nextBoolean(), random.nextBoolean());
|
||||||
SetData();
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
});
|
});
|
||||||
@ -106,5 +115,11 @@ public class FormPlane extends JFrame{
|
|||||||
PictureBox.revalidate();
|
PictureBox.revalidate();
|
||||||
Draw();
|
Draw();
|
||||||
});
|
});
|
||||||
|
ButtonSelectPlane.addActionListener(e -> {
|
||||||
|
SelectedPlane = _plane;
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ public class Main {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JFrame frame = new JFrame("Самолёт");
|
JFrame frame = new JFrame("Самолёт");
|
||||||
frame.setContentPane(new FormMap().Mainpanel);
|
frame.setContentPane(new FormMapWithSetPlanes().Mainpanel);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setLocation(500, 200);
|
frame.setLocation(500, 200);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
|
@ -41,20 +41,18 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
|
|||||||
|
|
||||||
public BufferedImage ShowOnMap()
|
public BufferedImage ShowOnMap()
|
||||||
{
|
{
|
||||||
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
|
||||||
Graphics2D g = (Graphics2D) img.getGraphics();
|
|
||||||
Shaking();
|
Shaking();
|
||||||
for (int i = 0; i < _setPlanes.Count(); i++)
|
for (int i = 0; i < _setPlanes.Count(); i++)
|
||||||
{
|
{
|
||||||
var car = _setPlanes.Get(i);
|
var ship = _setPlanes.Get(i);
|
||||||
if (car != null)
|
if (ship != null)
|
||||||
{
|
{
|
||||||
_map.CreateMap(_pictureWidth, _pictureHeight, car);
|
return _map.CreateMap(_pictureWidth, _pictureHeight, ship);
|
||||||
_map.DrawMapWithObject();
|
|
||||||
return img;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return img;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage MoveObject(Direction direction)
|
public BufferedImage MoveObject(Direction direction)
|
||||||
@ -63,7 +61,6 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
|
|||||||
if (_map != null)
|
if (_map != null)
|
||||||
{
|
{
|
||||||
_map.MoveObject(direction);
|
_map.MoveObject(direction);
|
||||||
_map.DrawMapWithObject();
|
|
||||||
}
|
}
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user