5-я лабораторная.

This commit is contained in:
Programmist73 2022-11-18 18:38:30 +04:00
parent e520452540
commit 80a4d1c7d7
3 changed files with 32 additions and 28 deletions

View File

@ -10,7 +10,7 @@ import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.HashMap;
public class FormMapWithSetPlanesGeneric {
public class FormMapWithSetPlanesGeneric extends JFrame{
public JPanel MainPanel;
private JPanel PictureBoxPlane;
private JPanel GroupBoxTools;
@ -44,6 +44,7 @@ public class FormMapWithSetPlanesGeneric {
public FormMapWithSetPlanesGeneric()
{
super("Хранилище");
CreateWindow();
_mapsCollection = new MapsCollection(730, 650);
ComboBoxSelectorMap.removeAllItems();

View File

@ -335,15 +335,6 @@
<text value="Доп. цвет"/>
</properties>
</component>
<grid id="db00" binding="PictureBoxObject" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<component id="da776" class="javax.swing.JLabel" binding="LabelTypeWindow">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@ -354,6 +345,14 @@
<text value="Форма"/>
</properties>
</component>
<grid id="f0d81" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<component id="d1cce" class="javax.swing.JButton" binding="ButtonAddObject">

View File

@ -2,12 +2,12 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.beans.Expression;
import java.rmi.server.ExportException;
import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.function.Consumer;
public class FormPlaneConfig extends JDialog{
public class FormPlaneConfig extends JFrame{
private JButton ButtonAddObject;
private JButton ButtonCancel;
private JPanel GroupBoxConfig;
@ -25,7 +25,6 @@ public class FormPlaneConfig extends JDialog{
private JLabel LabelModifiedObject;
private JLabel LabelBaseColor;
private JLabel LabelAddColor;
private JPanel PictureBoxObject;
private JLabel LabelSpeed;
private JLabel LabelWeight;
private JSpinner NumericUpDownWeight;
@ -40,6 +39,7 @@ public class FormPlaneConfig extends JDialog{
private JLabel LabelSimpleWindow;
private JLabel LabelRectWindow;
private JLabel LabelTriangleWindow;
private JPanel PictureBoxPlane;
//переменная-выбранный самолёт
DrawingPlane _plane;
@ -54,15 +54,13 @@ public class FormPlaneConfig extends JDialog{
//конструктор
public FormPlaneConfig()
{
super(new Frame("Аэробус"));
super("Самолёт");
CreateWindow();
setModal(true);
getContentPane().add(MainPanel);
}
public void Draw(DrawingPlane _plane)
{
PictureBoxObject.removeAll();
PictureBoxPlane.removeAll();
BufferedImage bmp = new BufferedImage(250, 200, BufferedImage.TYPE_INT_RGB);
Graphics gr = bmp.getGraphics();
@ -72,10 +70,10 @@ public class FormPlaneConfig extends JDialog{
if (_plane.GetPlane() != null) {
_plane.DrawTransport(gr);
JLabel imageOfLogo = new JLabel();
imageOfLogo.setPreferredSize(PictureBoxObject.getSize());
imageOfLogo.setPreferredSize(PictureBoxPlane.getSize());
imageOfLogo.setMinimumSize(new Dimension(1, 1));
imageOfLogo.setIcon(new ImageIcon(bmp));
PictureBoxObject.add(imageOfLogo, BorderLayout.CENTER);
PictureBoxPlane.add(imageOfLogo, BorderLayout.CENTER);
}
validate();
@ -122,7 +120,7 @@ public class FormPlaneConfig extends JDialog{
};
//настройки курсоров
PictureBoxObject.addMouseListener(defCursor);
PictureBoxPlane.addMouseListener(defCursor);
LabelBaseColor.addMouseListener(defCursor);
LabelAddColor.addMouseListener(defCursor);
LabelTypeWindow.addMouseListener(defCursor);
@ -168,16 +166,18 @@ public class FormPlaneConfig extends JDialog{
{
_plane.SetColor(panel.getBackground());
Draw(_plane);
repaint();
}
if(LabelAddColor.getMousePosition() != null && _plane instanceof DrawingAirbus airbus)
{
airbus.SetAddColor(panel.getBackground());
Draw(_plane);
repaint();
}
}
if(dropItem instanceof JLabel label && PictureBoxObject.getMousePosition() != null)
if(dropItem instanceof JLabel label && PictureBoxPlane.getMousePosition() != null)
{
int speed = (int)NumericUpDownSpeed.getValue();
int weight = (int)NumericUpDownWeight.getValue();
@ -189,9 +189,9 @@ public class FormPlaneConfig extends JDialog{
{
try
{
PictureBoxObject.remove(_plane);
_plane = new DrawingPlane(speed, weight, Color.WHITE, countWindow);
Draw(_plane);
repaint();
}
catch(Exception ex) { }
}
@ -199,21 +199,23 @@ public class FormPlaneConfig extends JDialog{
{
try
{
PictureBoxObject.remove(_plane);
_plane = new DrawingAirbus(speed, weight, Color.WHITE, countWindow, Color.WHITE, addCompartment, addEngine);
Draw(_plane);
repaint();
}
catch (Exception ex) { };
}
if(_plane != null)
{
_plane.SetPosition(PictureBoxObject.getWidth() - 200, PictureBoxObject.getHeight() - 150, PictureBoxObject.getWidth(), PictureBoxObject.getHeight());
PictureBoxObject.add(_plane, BorderLayout.CENTER);
_plane.SetPosition(PictureBoxPlane.getWidth() - 200, PictureBoxPlane.getHeight() - 150, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
PictureBoxPlane.add(_plane, BorderLayout.CENTER);
Draw(_plane);
repaint();
revalidate();
}
}
else if(dropItem instanceof JLabel label && LabelTypeWindow.getMousePosition() != null && _plane != null)
else if(dropItem instanceof JLabel label && LabelTypeWindow.getMousePosition() != null && _plane!=null)
{
if(label == LabelSimpleWindow)
{
@ -232,6 +234,8 @@ public class FormPlaneConfig extends JDialog{
_plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingTriangleAirplaneWindow());
Draw(_plane);
}
repaint();
}
}
}