112 lines
4.9 KiB
Java
112 lines
4.9 KiB
Java
|
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) {
|
|||
|
_plane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100),
|
|||
|
pictureBoxPlane.getWidth(), pictureBoxPlane.getHeight());
|
|||
|
_plane.DrawTransport(gr);
|
|||
|
JLabelSpeed.setText("Cкорость: " + _plane.GetPlane().GetSpeed() + " ");
|
|||
|
JLabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " ");
|
|||
|
JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " "));
|
|||
|
JLabel imageOfShip = new JLabel();
|
|||
|
imageOfShip.setPreferredSize(pictureBoxPlane.getSize());
|
|||
|
imageOfShip.setMinimumSize(new Dimension(1, 1));
|
|||
|
imageOfShip.setIcon(new ImageIcon(bmp));
|
|||
|
pictureBoxPlane.add(imageOfShip,BorderLayout.CENTER);
|
|||
|
}
|
|||
|
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);
|
|||
|
ButtonCreate.addActionListener(new ActionListener() {
|
|||
|
@Override
|
|||
|
public void actionPerformed(ActionEvent e){
|
|||
|
Random random = new Random();
|
|||
|
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
|
|||
|
EntityPlane ship=new EntityPlane(random.nextInt(100,300), random.nextInt(1000,2000),colorFirst);
|
|||
|
IDrawningIlluminator deck = SetData();
|
|||
|
int DecksCount=random.nextInt(1,4) * 10;
|
|||
|
deck.SetIlluminatorCount(DecksCount);
|
|||
|
if((_drawningEntities.Insert(ship)!=-1) & (_drawningEntities.Insert(deck)!=-1))
|
|||
|
{
|
|||
|
JOptionPane.showMessageDialog(null,"Объект добавлен");
|
|||
|
Draw(_drawningEntities.CreatePlane());
|
|||
|
LabelInfo.setText(_drawningEntities.indx+ " " + _drawningEntities.indy);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
ButtonCreateModif.addActionListener(new ActionListener() {
|
|||
|
@Override
|
|||
|
public void actionPerformed(ActionEvent e) {
|
|||
|
Random random = new Random();
|
|||
|
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
|
|||
|
Color colorSecond = JColorChooser.showDialog(null, "Цвет", null);
|
|||
|
EntityAirbus _ship=new EntityAirbus(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst, colorSecond, random.nextBoolean(), random.nextBoolean(), random.nextBoolean());
|
|||
|
IDrawningIlluminator deck = SetData();
|
|||
|
int DecksCount=random.nextInt(1,4) * 10;
|
|||
|
deck.SetIlluminatorCount(DecksCount);
|
|||
|
if((_drawningEntities.Insert(_ship)!=-1) & (_drawningEntities.Insert(deck)!=-1))
|
|||
|
{
|
|||
|
JOptionPane.showMessageDialog(null,"Объект добавлен");
|
|||
|
Draw(_drawningEntities.CreatePlane());
|
|||
|
LabelInfo.setText(_drawningEntities.indx+ " " + _drawningEntities.indy);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|