Доработка формы, модификкация FormPlane и одного класса Generic.
This commit is contained in:
parent
6474259b5f
commit
571b302e4b
@ -1,17 +0,0 @@
|
||||
import javax.swing.*;
|
||||
|
||||
public class FormMapWithSetPlanes {
|
||||
private JPanel MainPanel;
|
||||
private JPanel PictureBoxPlane;
|
||||
private JPanel ButtonGroupPanel;
|
||||
private JComboBox ComboBoxSelectorMap;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonShowOnMap;
|
||||
private JButton ButtonShowStorage;
|
||||
private JButton ButtonAddPlane;
|
||||
private JTextField __TextField;
|
||||
private JButton ButtonRemovePlane;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetPlanes">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetPlanesGeneric">
|
||||
<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>
|
||||
@ -133,7 +133,7 @@
|
||||
<text value="Добавить самолёт"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6f119" class="javax.swing.JTextField" binding="__TextField" default-binding="true">
|
||||
<component id="6f119" class="javax.swing.JTextField" binding="MaskedTextBoxPosition">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="220" height="30"/>
|
271
Project/src/FormMapWithSetPlanesGeneric.java
Normal file
271
Project/src/FormMapWithSetPlanesGeneric.java
Normal file
@ -0,0 +1,271 @@
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class FormMapWithSetPlanesGeneric {
|
||||
private JPanel MainPanel;
|
||||
private JPanel PictureBoxPlane;
|
||||
private JPanel ButtonGroupPanel;
|
||||
private JComboBox ComboBoxSelectorMap;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonShowOnMap;
|
||||
private JButton ButtonShowStorage;
|
||||
private JButton ButtonAddPlane;
|
||||
private JTextField MaskedTextBoxPosition;
|
||||
private JButton ButtonRemovePlane;
|
||||
|
||||
//объект от класса карты с набором объектов
|
||||
private MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> _mapPlanesCollectionGeneric;
|
||||
|
||||
//обновление отрисовки
|
||||
public void UpdateWindow(BufferedImage bmp)
|
||||
{
|
||||
PictureBoxPlane.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(bmp));
|
||||
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
PictureBoxPlane.revalidate();
|
||||
}
|
||||
|
||||
public FormMapWithSetPlanesGeneric()
|
||||
{
|
||||
//загрузка изображений для кнопок
|
||||
try
|
||||
{
|
||||
Image img = ImageIO.read(getClass().getResource("resourses/Up.png"));
|
||||
ButtonUp.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(getClass().getResource("resourses/Left.png"));
|
||||
ButtonLeft.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(getClass().getResource("resourses/Down.png"));
|
||||
ButtonDown.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(getClass().getResource("resourses/Right.png"));
|
||||
ButtonRight.setIcon(new ImageIcon(img));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println(ex.getMessage());
|
||||
}
|
||||
|
||||
//добавление самолёта
|
||||
ButtonAddPlane.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_mapPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormPlane form = new FormPlane();
|
||||
form.setSize(1000,700);
|
||||
form.setVisible(true);
|
||||
form.setModal(true);
|
||||
DrawningObjectPlane plane = new DrawningObjectPlane(form.GetSelectedShip());
|
||||
|
||||
if(_mapPlanesCollectionGeneric.Add(plane) != -1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Объект добавлен");
|
||||
UpdateWindow(_mapPlanesCollectionGeneric.ShowSet());
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//удаление самолёта
|
||||
ButtonRemovePlane.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (MaskedTextBoxPosition.getText().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int result = JOptionPane.showConfirmDialog(null,"Удалить объект?","Удаление",
|
||||
JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
|
||||
if(result==JOptionPane.NO_OPTION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Integer.parseInt(MaskedTextBoxPosition.getText());
|
||||
|
||||
if(_mapPlanesCollectionGeneric.Delete(pos) != null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Объект удалён");
|
||||
UpdateWindow(_mapPlanesCollectionGeneric.ShowSet());
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//показ хранилища
|
||||
ButtonShowStorage.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_mapPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateWindow(_mapPlanesCollectionGeneric.ShowSet());
|
||||
}
|
||||
});
|
||||
|
||||
//показ карты
|
||||
ButtonShowOnMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_mapPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateWindow(_mapPlanesCollectionGeneric.ShowSet());
|
||||
}
|
||||
});
|
||||
|
||||
ButtonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_mapPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PictureBoxPlane.removeAll();
|
||||
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.MoveObject((Direction.Up))));
|
||||
|
||||
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
PictureBoxPlane.revalidate();
|
||||
PictureBoxPlane.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
ButtonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_mapPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PictureBoxPlane.removeAll();
|
||||
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.MoveObject((Direction.Left))));
|
||||
|
||||
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
PictureBoxPlane.revalidate();
|
||||
PictureBoxPlane.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
ButtonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_mapPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PictureBoxPlane.removeAll();
|
||||
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.MoveObject((Direction.Down))));
|
||||
|
||||
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
PictureBoxPlane.revalidate();
|
||||
PictureBoxPlane.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
ButtonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_mapPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PictureBoxPlane.removeAll();
|
||||
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.MoveObject((Direction.Right))));
|
||||
|
||||
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
PictureBoxPlane.revalidate();
|
||||
PictureBoxPlane.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
//выпадающий список с вариантами карт
|
||||
ComboBoxSelectorMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
AbstractMap map = null;
|
||||
|
||||
ComboBoxSelectorMap = (JComboBox)e.getSource();
|
||||
String item = (String)ComboBoxSelectorMap.getSelectedItem();
|
||||
switch(item)
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Буря в пустыне":
|
||||
map = new DesertStormMap();
|
||||
break;
|
||||
case "Звёздные войны":
|
||||
map = new StarWarsMap();
|
||||
break;
|
||||
}
|
||||
|
||||
if(map != null)
|
||||
{
|
||||
_mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>(
|
||||
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight(), map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapPlanesCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
MaskedTextBoxPosition.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
char c = e.getKeyChar();
|
||||
|
||||
if ( ((c < '0') || (c > '9')) || MaskedTextBoxPosition.getText().length() >= 2) {
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormPlane">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="7" 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="10" 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="42" width="864" height="483"/>
|
||||
<xy x="20" y="42" width="1040" height="483"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="67a15" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="7" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="45" height="45"/>
|
||||
<preferred-size width="45" height="45"/>
|
||||
<maximum-size width="45" height="45"/>
|
||||
@ -23,7 +23,7 @@
|
||||
</component>
|
||||
<component id="b10a1" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="9" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="45" height="45"/>
|
||||
<preferred-size width="45" height="45"/>
|
||||
<maximum-size width="45" height="45"/>
|
||||
@ -36,36 +36,28 @@
|
||||
</component>
|
||||
<hspacer id="5b756">
|
||||
<constraints>
|
||||
<grid row="2" column="3" 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="6" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="-1"/>
|
||||
<preferred-size width="50" height="-1"/>
|
||||
<maximum-size width="50" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="a48b0" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="2" 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="100" height="25"/>
|
||||
<preferred-size width="100" height="25"/>
|
||||
<maximum-size width="100" height="25"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="100" height="30"/>
|
||||
<preferred-size width="100" height="30"/>
|
||||
<maximum-size width="100" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<toolbar id="ede45" binding="StatusStrip">
|
||||
<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">
|
||||
<minimum-size width="345" height="25"/>
|
||||
<preferred-size width="345" height="25"/>
|
||||
<maximum-size width="345" height="25"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</toolbar>
|
||||
<grid id="b0c9a" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<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"/>
|
||||
<grid row="0" column="0" row-span="1" col-span="10" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@ -73,7 +65,7 @@
|
||||
</grid>
|
||||
<component id="51778" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="8" 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="45" height="45"/>
|
||||
<preferred-size width="45" height="45"/>
|
||||
<maximum-size width="45" height="45"/>
|
||||
@ -86,7 +78,7 @@
|
||||
</component>
|
||||
<component id="44002" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="1" column="8" 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="45" height="45"/>
|
||||
<preferred-size width="45" height="45"/>
|
||||
<maximum-size width="45" height="45"/>
|
||||
@ -97,14 +89,46 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="993b6">
|
||||
<component id="96587" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||
<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">
|
||||
<minimum-size width="220" height="25"/>
|
||||
<preferred-size width="220" height="25"/>
|
||||
<maximum-size width="220" height="25"/>
|
||||
<grid row="2" 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="120" height="30"/>
|
||||
<preferred-size width="120" height="30"/>
|
||||
<maximum-size width="120" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Модификация"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c1262" class="javax.swing.JButton" binding="ButtonSelectPlane">
|
||||
<constraints>
|
||||
<grid row="2" column="5" 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="100" height="30"/>
|
||||
<preferred-size width="100" height="30"/>
|
||||
<maximum-size width="100" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Выбрать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<toolbar id="ede45" binding="StatusStrip">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="345" height="25"/>
|
||||
<preferred-size width="345" height="25"/>
|
||||
<maximum-size width="345" height="25"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</toolbar>
|
||||
<hspacer id="5bc63">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
|
@ -1,16 +1,12 @@
|
||||
import javax.imageio.ImageIO;
|
||||
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.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormPlane
|
||||
public class FormPlane extends JDialog
|
||||
{
|
||||
protected DrawingPlane plane;
|
||||
|
||||
public JPanel MainPanel;
|
||||
private JButton ButtonCreate;
|
||||
private JButton ButtonLeft;
|
||||
@ -19,12 +15,54 @@ public class FormPlane
|
||||
private JButton ButtonUp;
|
||||
private JToolBar StatusStrip;
|
||||
private JPanel PictureBoxPlane;
|
||||
private JButton ButtonCreateModif;
|
||||
private JButton ButtonSelectPlane;
|
||||
private JLabel LabelSpeed = new JLabel();
|
||||
private JLabel LabelWeight = new JLabel();
|
||||
private JLabel LabelColor = new JLabel();
|
||||
|
||||
protected DrawingPlane plane;
|
||||
protected DrawingPlane _selectedPlane;
|
||||
|
||||
public DrawingPlane GetSelectedShip()
|
||||
{
|
||||
return _selectedPlane;
|
||||
}
|
||||
|
||||
//метод отрисовки
|
||||
public void Draw(DrawingPlane _plane) {
|
||||
PictureBoxPlane.removeAll();
|
||||
BufferedImage bmp = new BufferedImage(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
|
||||
gr.setColor(new Color(238, 238, 238));
|
||||
gr.fillRect(0, 0, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||
|
||||
if (plane.GetPlane() != null) {
|
||||
_plane.DrawTransport(gr);
|
||||
JLabel imageOfLogo = new JLabel();
|
||||
imageOfLogo.setPreferredSize(PictureBoxPlane.getSize());
|
||||
imageOfLogo.setMinimumSize(new Dimension(1, 1));
|
||||
imageOfLogo.setIcon(new ImageIcon(bmp));
|
||||
PictureBoxPlane.add(imageOfLogo, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
validate();
|
||||
}
|
||||
|
||||
//создание всплывающего окна
|
||||
public FormPlane()
|
||||
{
|
||||
super(new Frame("Airbus"));
|
||||
CreateWindow();
|
||||
setModal(true);
|
||||
getContentPane().add(MainPanel);
|
||||
}
|
||||
|
||||
public void CreateWindow()
|
||||
{
|
||||
setModal(true);
|
||||
|
||||
//создание строки отображения скорости, веса и цвета объекта
|
||||
Box LableBox = Box.createHorizontalBox();
|
||||
LableBox.setMinimumSize(new Dimension(1, 20));
|
||||
@ -49,30 +87,60 @@ public class FormPlane
|
||||
System.out.println(ex.getMessage());
|
||||
}
|
||||
|
||||
_selectedPlane = plane;
|
||||
|
||||
ButtonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null);
|
||||
|
||||
plane = new DrawingPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||
colorSimple);
|
||||
plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
||||
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||
|
||||
LabelSpeed.setText("Скорость: " + plane.GetPlane().GetSpeed() + " ");
|
||||
LabelWeight.setText("Вес: " + plane.GetPlane().GetWeight() + " ");
|
||||
LabelColor.setText("Цвет: r = " + plane.GetPlane().GetColor().getRed() + " g = " + plane.GetPlane().GetColor().getGreen() +
|
||||
" b = " + plane.GetPlane().GetColor().getBlue());
|
||||
Draw();
|
||||
|
||||
Draw(plane);
|
||||
}
|
||||
});
|
||||
|
||||
//обновление размеров формы
|
||||
MainPanel.addComponentListener(new ComponentAdapter() {
|
||||
ButtonCreateModif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null);
|
||||
Color colorModif = JColorChooser.showDialog(null, "Выберите цвет", null);
|
||||
|
||||
plane = new DrawingAirbus(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
colorSimple, colorModif, rnd.nextBoolean(), rnd.nextBoolean());
|
||||
plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
||||
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||
|
||||
LabelSpeed.setText("Скорость: " + plane.GetPlane().GetSpeed() + " ");
|
||||
LabelWeight.setText("Вес: " + plane.GetPlane().GetWeight() + " ");
|
||||
LabelColor.setText("Цвет: r = " + plane.GetPlane().GetColor().getRed() + " g = " + plane.GetPlane().GetColor().getGreen() +
|
||||
" b = " + plane.GetPlane().GetColor().getBlue());
|
||||
|
||||
Draw(plane);
|
||||
}
|
||||
});
|
||||
|
||||
PictureBoxPlane.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
super.componentResized(e);
|
||||
plane.ChangeBorders(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||
Draw();
|
||||
|
||||
if(plane != null)
|
||||
{
|
||||
plane.ChangeBorders(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||
PictureBoxPlane.revalidate();
|
||||
Draw(plane);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -80,7 +148,8 @@ public class FormPlane
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
plane.MoveTransport(Direction.Up);
|
||||
Draw();
|
||||
PictureBoxPlane.revalidate();
|
||||
Draw(plane);
|
||||
}
|
||||
});
|
||||
|
||||
@ -88,7 +157,8 @@ public class FormPlane
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
plane.MoveTransport(Direction.Left);
|
||||
Draw();
|
||||
PictureBoxPlane.revalidate();
|
||||
Draw(plane);
|
||||
}
|
||||
});
|
||||
|
||||
@ -96,7 +166,8 @@ public class FormPlane
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
plane.MoveTransport(Direction.Down);
|
||||
Draw();
|
||||
PictureBoxPlane.revalidate();
|
||||
Draw(plane);
|
||||
}
|
||||
});
|
||||
|
||||
@ -104,18 +175,18 @@ public class FormPlane
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
plane.MoveTransport(Direction.Right);
|
||||
Draw();
|
||||
PictureBoxPlane.revalidate();
|
||||
Draw(plane);
|
||||
}
|
||||
});
|
||||
|
||||
//кнопка подтверждение выбора
|
||||
ButtonSelectPlane.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_selectedPlane = plane;
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if(plane.GetPlane() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
plane.DrawTransport(PictureBoxPlane.getGraphics());
|
||||
}
|
||||
}
|
||||
|
@ -32,19 +32,15 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
|
||||
_map = map;
|
||||
}
|
||||
|
||||
/*
|
||||
//пеергрузка оператора сложения
|
||||
public static int operator +(MapWithSetPlanesGeneric<T, U> map, T plane)
|
||||
public int Add(T plane)
|
||||
{
|
||||
return map._setPlanes.Insert(plane);
|
||||
return _setPlanes.Insert(plane);
|
||||
}
|
||||
|
||||
//перегрузка оператора вычитания
|
||||
public static T operator -(MapWithSetPlanesGeneric<T, U> map, int position)
|
||||
public T Delete(int position)
|
||||
{
|
||||
return map._setPlanes.Remove(position);
|
||||
return _setPlanes.Remove(position);
|
||||
}
|
||||
*/
|
||||
|
||||
//вывод всего набора объектов
|
||||
public BufferedImage ShowSet()
|
||||
|
Loading…
Reference in New Issue
Block a user