Pibd-22_Emelyanov_A.S._Airb.../FormParam.java

105 lines
4.6 KiB
Java
Raw Permalink Normal View History

2022-12-13 17:02:16 +04:00
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.Random;
public class FormParam extends JFrame{
public JPanel MainPanel;
private JPanel pictureBoxPlane;
private JButton ButtonCreate;
private JButton ButtonCreateModif;
private JToolBar StatusStrip;
private JLabel LabelInfo;
private JLabel JLabelSpeed = new JLabel();
private JLabel JLabelWeight = new JLabel();
private JLabel JLabelColor = new JLabel();
private DrawningEntities<EntityPlane,IDrawningIlluminator> _drawningEntities;
private IDrawningIlluminator SetData()
{
Random random=new Random();
int r = random.nextInt(3);
if(r==0)
{
return new DrawningIlluminator();
}
if(r==1)
{
return new DrawningSqareIlluminator();
}
else
{
return new DrawningTriangleIlluminator();
}
}
private void Draw(DrawningPlane _plane) {
pictureBoxPlane.removeAll();
Random random = 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) {
2022-12-14 13:13:38 +04:00
_plane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureBoxPlane.getWidth(), pictureBoxPlane.getHeight());
2022-12-13 17:02:16 +04:00
_plane.DrawTransport(gr);
JLabelSpeed.setText("орость: " + _plane.GetPlane().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " "));
2022-12-14 13:13:38 +04:00
JLabel imageOfPlane = new JLabel();
imageOfPlane.setPreferredSize(pictureBoxPlane.getSize());
imageOfPlane.setMinimumSize(new Dimension(1, 1));
imageOfPlane.setIcon(new ImageIcon(bmp));
pictureBoxPlane.add(imageOfPlane,BorderLayout.CENTER);
2022-12-13 17:02:16 +04:00
}
validate();
}
public FormParam()
{
Box LabelBox = Box.createHorizontalBox();
LabelBox.setMinimumSize(new Dimension(1, 20));
LabelBox.add(JLabelSpeed);
LabelBox.add(JLabelWeight);
LabelBox.add(JLabelColor);
StatusStrip.add(LabelBox);
_drawningEntities = new DrawningEntities<>(10,10);
2022-12-14 13:13:38 +04:00
ButtonCreate.addActionListener(e -> {
Random random = new Random();
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
EntityPlane _plane = new EntityPlane(random.nextInt(100,300), random.nextInt(1000,2000),colorFirst);
IDrawningIlluminator illum = SetData();
int IllumCount = random.nextInt(1,4) * 10;
illum.SetIlluminatorCount(IllumCount);
if((_drawningEntities.Insert(_plane)!=-1) & (_drawningEntities.Insert(illum)!=-1))
{
JOptionPane.showMessageDialog(null,"Объект добавлен");
Draw(_drawningEntities.CreatePlane());
LabelInfo.setText(_drawningEntities.indx+ " " + _drawningEntities.indy);
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
2022-12-13 17:02:16 +04:00
}
});
2022-12-14 13:13:38 +04:00
ButtonCreateModif.addActionListener(e -> {
Random random = new Random();
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
Color colorSecond = JColorChooser.showDialog(null, "Цвет", null);
EntityAirbus _plane = new EntityAirbus(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst, colorSecond, random.nextBoolean(), random.nextBoolean(), random.nextBoolean());
IDrawningIlluminator illum = SetData();
int IllumCount = random.nextInt(1,4) * 10;
illum.SetIlluminatorCount(IllumCount);
if((_drawningEntities.Insert(_plane)!=-1) & (_drawningEntities.Insert(illum)!=-1))
{
JOptionPane.showMessageDialog(null,"Объект добавлен");
Draw(_drawningEntities.CreatePlane());
LabelInfo.setText(_drawningEntities.indx+ " " + _drawningEntities.indy);
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
2022-12-13 17:02:16 +04:00
}
});
}
}