Доработка доп. формы по заданию.

This commit is contained in:
Programmist73 2022-11-06 15:04:39 +04:00
parent 186c08abd8
commit 8320f6de72
3 changed files with 131 additions and 37 deletions

View File

@ -8,7 +8,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<toolbar id="d67f5"> <toolbar id="d67f5" binding="StatusStrip">
<constraints> <constraints>
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"> <grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="20"/> <preferred-size width="-1" height="20"/>
@ -54,8 +54,7 @@
<grid row="4" 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="4" 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>
</hspacer> </hspacer>
<grid id="ecc65" binding="PictureBoxPlane" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="ecc65" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="4" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="4" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
@ -65,33 +64,11 @@
</grid> </grid>
<component id="56eb2" class="javax.swing.JLabel" binding="LabelInfo"> <component id="56eb2" class="javax.swing.JLabel" binding="LabelInfo">
<constraints> <constraints>
<grid row="0" 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="0" column="5" row-span="4" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="de6c7" class="javax.swing.JLabel" binding="LableSpeed">
<constraints>
<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"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="711c1" class="javax.swing.JLabel" binding="LabelWeight">
<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"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="a956c" class="javax.swing.JLabel" binding="LabelColor">
<constraints>
<grid row="3" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<horizontalAlignment value="0"/>
<horizontalTextPosition value="0"/>
<text value=""/> <text value=""/>
</properties> </properties>
</component> </component>

View File

@ -1,14 +1,131 @@
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.nio.file.attribute.AclEntryType;
import java.util.Random;
import java.util.Set;
public class FormParam public class FormParam extends JFrame
{ {
public JPanel MainPanel;
private JButton ButtonAddPlane; private JButton ButtonAddPlane;
private JPanel PictureBoxPlane; private JPanel PictureBoxPlane;
private JButton ButtonCreateModif; private JButton ButtonCreateModif;
private JLabel LabelInfo; private JLabel LabelInfo;
private JLabel LableSpeed; private JLabel LabelSpeed = new JLabel();
private JLabel LabelWeight; private JLabel LabelWeight = new JLabel();
private JPanel MainPanel; private JLabel LabelColor = new JLabel();
private JLabel LabelColor; 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();
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, "Не удалось добавить объект");
}
}
});
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, "Не удалось добавить объект");
}
}
});
}
} }

View File

@ -4,12 +4,12 @@ public class Main
{ {
public static void main(String[] args) public static void main(String[] args)
{ {
JFrame frame = new JFrame("Airbus"); JFrame frame = new JFrame("Аэробус");
frame.setContentPane(new FormMapWithSetPlanesGeneric().MainPanel); frame.setContentPane(new FormParam().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();
frame.setSize(1000, 600); frame.setSize(800, 500);
frame.setVisible(true); frame.setVisible(true);
} }
} }