Emelyanov A.S. LabWork03 #3

Closed
Emelyanov535 wants to merge 5 commits from LabWork03 into LabWork02
7 changed files with 261 additions and 9 deletions
Showing only changes of commit 176c2b9601 - Show all commits

View File

@ -7,6 +7,12 @@ public class DrawningAirbus extends DrawningPlane{
super(speed, weight, bodyColor, 140, 70);
Plane = new EntityAirbus(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
}
protected DrawningAirbus(EntityPlane plane, IDrawningIlluminator illum){
super(plane,illum);
Plane = plane;
}
@Override
public void DrawTransport(Graphics g)
{

57
DrawningEntities.java Normal file
View File

@ -0,0 +1,57 @@
import java.util.Random;
public class DrawningEntities <T extends EntityPlane, U extends IDrawningIlluminator>
{
public T[] _entities;
public U[] _illuminator;
int entitiesCount = 0;
int illumCount = 0;
String indx;
String indy;
public DrawningEntities(int countE,int countI){
_entities = (T[]) new EntityPlane[countE];
_illuminator = (U[]) new IDrawningIlluminator[countI];
}
public int Insert(T plane){
if(entitiesCount < _entities.length){
_entities[entitiesCount] = plane;
entitiesCount++;
return entitiesCount - 1;
}
return -1;
}
public int Insert(U illuminator){
if(illumCount < _illuminator.length){
_illuminator[illumCount] = illuminator;
illumCount++;
return illumCount - 1;
}
return -1;
}
public void SetIndexs(int ind1, int ind2)
{
indx=Integer.toString(ind1);
indy=Integer.toString(ind2);
}
public DrawningPlane CreatePlane(){
Random random = new Random();
int indEnt = 0;
int indIllum = 0;
if(entitiesCount - 1 != 0 & illumCount - 1 != 0){
indEnt = random.nextInt(0,entitiesCount - 1);
indIllum = random.nextInt(0, illumCount - 1);
}
T plane = (T)_entities[indEnt];
U illum = (U)_illuminator[indIllum];
SetIndexs(indEnt,indIllum);
if(plane instanceof EntityAirbus){
return new DrawningAirbus(plane,illum);
}
return new DrawningPlane(plane,illum);
}
}

View File

@ -43,6 +43,11 @@ public class DrawningPlane extends JPanel {
SetIlluminator();
}
protected DrawningPlane(EntityPlane plane, IDrawningIlluminator illum){
Plane = plane;
IlluminatorDraw = illum;
}
public void SetPosition(int x, int y, int width, int height)
{
if (x >= 0 && x + _PlaneWidth <= width && y >= 0 && y + _PlaneHeight <= height) {

View File

@ -16,7 +16,7 @@
<border type="none"/>
<children/>
</grid>
<grid id="e9a63" binding="groupBox" layout-manager="GridLayoutManager" row-count="8" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e9a63" binding="groupBox" layout-manager="GridLayoutManager" row-count="10" 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="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
@ -28,7 +28,7 @@
<children>
<component id="f23ee" class="javax.swing.JButton" binding="buttonAdd">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Добавить самолёт"/>
@ -44,7 +44,7 @@
</component>
<component id="5c428" class="javax.swing.JButton" binding="buttonRemove">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Удалить самолёт"/>
@ -52,7 +52,7 @@
</component>
<component id="e24b9" class="javax.swing.JButton" binding="buttonShowStorage">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Посмотреть Хранилище"/>
@ -60,7 +60,7 @@
</component>
<component id="ac087" class="javax.swing.JButton" binding="buttonShowOnMap">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Посмотреть карту"/>
@ -69,7 +69,7 @@
<grid id="2821b" layout-manager="GridLayoutManager" row-count="2" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="150" height="-1"/>
</grid>
</constraints>
@ -138,17 +138,27 @@
</grid>
<vspacer id="b833e">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="181ac" class="javax.swing.JTextField" binding="textBoxPosition">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<vspacer id="53ec0">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="a6919">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</children>

62
FormParam.form Normal file
View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormParam">
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="7700e" binding="pictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" 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="b960b" class="javax.swing.JButton" binding="ButtonCreate">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<component id="a44b0" class="javax.swing.JButton" binding="ButtonCreateModif">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Модификация"/>
</properties>
</component>
<hspacer id="56304">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="31e01" class="javax.swing.JLabel" binding="LabelInfo">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<toolbar id="7a0ba" binding="StatusStrip">
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="20"/>
</grid>
</constraints>
<properties>
<enabled value="false"/>
</properties>
<border type="none"/>
<children/>
</toolbar>
</children>
</grid>
</form>

111
FormParam.java Normal file
View File

@ -0,0 +1,111 @@
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("орость: " + _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, "Не удалось добавить объект");
}
}
});
}
}

View File

@ -4,7 +4,8 @@ public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("Самолёт");
frame.setContentPane(new FormMapWithSetPlanes().Mainpanel);
// frame.setContentPane(new FormMapWithSetPlanes().Mainpanel);
frame.setContentPane(new FormParam().MainPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(500, 200);
frame.pack();