2022-11-06 14:04:17 +04:00
|
|
|
|
import javax.swing.*;
|
2022-11-06 15:04:39 +04:00
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.util.Random;
|
2022-11-06 14:04:17 +04:00
|
|
|
|
|
2022-11-06 15:04:39 +04:00
|
|
|
|
public class FormParam extends JFrame
|
2022-11-06 14:04:17 +04:00
|
|
|
|
{
|
2022-11-06 15:04:39 +04:00
|
|
|
|
public JPanel MainPanel;
|
2022-11-06 14:04:17 +04:00
|
|
|
|
private JButton ButtonAddPlane;
|
|
|
|
|
private JPanel PictureBoxPlane;
|
|
|
|
|
private JButton ButtonCreateModif;
|
|
|
|
|
private JLabel LabelInfo;
|
2022-11-06 15:04:39 +04:00
|
|
|
|
private JLabel LabelSpeed = new JLabel();
|
|
|
|
|
private JLabel LabelWeight = new JLabel();
|
|
|
|
|
private JLabel LabelColor = new JLabel();
|
|
|
|
|
private JToolBar StatusStrip;
|
|
|
|
|
|
|
|
|
|
private DrawingEntities<EntityPlane, IAdditionalDrawingObject> _drawingEntities;
|
|
|
|
|
|
|
|
|
|
private IAdditionalDrawingObject SetData()
|
|
|
|
|
{
|
|
|
|
|
Random rnd = new Random();
|
|
|
|
|
int r = rnd.nextInt(3);
|
|
|
|
|
|
|
|
|
|
if(r == 0)
|
|
|
|
|
{
|
|
|
|
|
return new DrawingAirplaneWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(r == 1)
|
|
|
|
|
{
|
|
|
|
|
return new DrawingTriangleAirplaneWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if r == 2
|
|
|
|
|
return new DrawingRectAirplaneWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Draw(DrawingPlane _plane)
|
|
|
|
|
{
|
|
|
|
|
PictureBoxPlane.removeAll();
|
|
|
|
|
Random rnd = new Random();
|
|
|
|
|
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 != null)
|
|
|
|
|
{
|
|
|
|
|
_plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
|
|
|
|
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
|
|
|
|
_plane.DrawTransport(gr);
|
|
|
|
|
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());
|
|
|
|
|
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 FormParam()
|
|
|
|
|
{
|
|
|
|
|
//создание строки отображения скорости, веса и цвета объекта
|
|
|
|
|
Box LableBox = Box.createHorizontalBox();
|
|
|
|
|
LableBox.setMinimumSize(new Dimension(1, 20));
|
|
|
|
|
LableBox.add(LabelSpeed);
|
|
|
|
|
LableBox.add(LabelWeight);
|
|
|
|
|
LableBox.add(LabelColor);
|
|
|
|
|
StatusStrip.add(LableBox);
|
|
|
|
|
|
|
|
|
|
_drawingEntities = new DrawingEntities<>(10, 10);
|
|
|
|
|
|
|
|
|
|
ButtonAddPlane.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
Random rnd = new Random();
|
|
|
|
|
Color colorCorpus = JColorChooser.showDialog(null, "Выбор цвета", null);
|
|
|
|
|
EntityPlane plane = new EntityPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), colorCorpus);
|
|
|
|
|
IAdditionalDrawingObject addWindows = SetData();
|
2022-11-07 21:17:44 +04:00
|
|
|
|
|
2022-11-06 15:04:39 +04:00
|
|
|
|
int countWindows = rnd.nextInt(1, 4);
|
|
|
|
|
addWindows.SetAddEnum(countWindows);
|
|
|
|
|
|
|
|
|
|
if((_drawingEntities.Insert(plane) != -1) && (_drawingEntities.Insert(addWindows) != -1))
|
|
|
|
|
{
|
|
|
|
|
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
|
|
|
|
Draw(_drawingEntities.CreatePlane());
|
|
|
|
|
LabelInfo.setText(_drawingEntities._x_index + " " + _drawingEntities._y_index);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
|
|
|
|
}
|
2022-11-07 21:17:44 +04:00
|
|
|
|
|
2022-11-06 15:04:39 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ButtonCreateModif.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
Random rnd = new Random();
|
|
|
|
|
Color colorFirst = JColorChooser.showDialog(null, "Выбор цвета", null);
|
|
|
|
|
Color colorSecond = JColorChooser.showDialog(null, "Выбор цвета", null);
|
|
|
|
|
EntityAirbus airbus = new EntityAirbus(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
|
|
|
|
colorFirst, colorSecond, rnd.nextBoolean(), rnd.nextBoolean());
|
|
|
|
|
IAdditionalDrawingObject addWindows = SetData();
|
|
|
|
|
int countWindows = rnd.nextInt(1, 4);
|
|
|
|
|
addWindows.SetAddEnum(countWindows);
|
|
|
|
|
|
|
|
|
|
if((_drawingEntities.Insert(airbus) != -1) && (_drawingEntities.Insert(addWindows) != -1))
|
|
|
|
|
{
|
|
|
|
|
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
|
|
|
|
Draw(_drawingEntities.CreatePlane());
|
|
|
|
|
LabelInfo.setText(_drawingEntities._x_index + " " + _drawingEntities._y_index);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-11-06 14:04:17 +04:00
|
|
|
|
}
|