Modified object

This commit is contained in:
ArtemEmelyanov 2022-11-29 00:13:32 +04:00
parent 0487aff030
commit 41e6816ee5
5 changed files with 130 additions and 23 deletions

53
DrawningAirbus.java Normal file
View File

@ -0,0 +1,53 @@
import java.awt.*;
public class DrawningAirbus extends DrawningPlane{
public DrawningAirbus(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine)
{
super(speed, weight, bodyColor, 140, 70);
Plane = new EntityAirbus(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
}
@Override
public void DrawTransport(Graphics g)
{
if (! (Plane instanceof EntityAirbus Airbus))
{
return;
}
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
_startPosX += 10;
_startPosY += 5;
super.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 5;
if (Airbus.BodyKit)
{
g.drawRect(_startPosX + 70, _startPosY + 50, 22, 16);
g.drawRect(_startPosX + 8, _startPosY + 18, 22, 16);
g.drawOval(_startPosX, _startPosY + 18, 16, 16);
g.drawOval(_startPosX + 62, _startPosY + 50, 16, 16);
g2d.setPaint(Airbus.DopColor);
g.fillRect(_startPosX + 70, _startPosY + 50, 22, 16);
g.fillOval(_startPosX + 84, _startPosY + 50, 16, 16);
g.fillOval(_startPosX + 24, _startPosY + 18, 16, 16);
g.fillRect(_startPosX + 8, _startPosY + 18, 22, 16);
g2d.setPaint(Color.BLACK);
g.fillOval(_startPosX, _startPosY + 18, 16, 16);
g.fillOval(_startPosX + 62, _startPosY + 50, 16, 16);
}
if (Airbus.Wing)
{
g.drawLine(_startPosX + 70, _startPosY + 20, _startPosX + 70, _startPosY + 35);
g.drawLine(_startPosX + 70, _startPosY + 20, _startPosX + 90, _startPosY + 35);
}
if (Airbus.SportLine)
{
g.drawOval(_startPosX + 110, _startPosY + 40, 9, 9);
g.fillOval(_startPosX + 110, _startPosY + 40, 9, 9);
}
}
}

View File

@ -5,19 +5,19 @@ import java.util.random.RandomGenerator;
public class DrawningPlane extends JPanel {
private EntityPlane Plane;
EntityPlane Plane;
public EntityPlane GetPlane(){
return Plane;
}
private int _startPosX;
private int _startPosY;
protected int _startPosX;
protected int _startPosY;
public DrawningIlluminator IlluminatorDraw;
public Integer _pictureWidth = null;
public Integer _pictureHeight = null;
private final int _PlaneWidth = 130;
private final int _PlaneHeight = 70;
private int _PlaneWidth = 130;
private int _PlaneHeight = 70;
public void SetIlluminator() {
Random r = new Random();
@ -78,6 +78,13 @@ public class DrawningPlane extends JPanel {
}
}
protected DrawningPlane(int speed, float weight, Color bodyColor, int planeWidth, int planeHeight)
{
this(speed, weight, bodyColor);
_PlaneWidth = planeWidth;
_PlaneHeight = planeHeight;
}
public void DrawTransport(Graphics g) {
if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) {
return;

27
EntityAirbus.java Normal file
View File

@ -0,0 +1,27 @@
import java.awt.*;
public class EntityAirbus extends EntityPlane{
public Color DopColor;
public Color GetDopColor() {
return DopColor;
}
public boolean BodyKit;
public boolean GetBodyKit(){ return BodyKit; }
public boolean Wing;
public boolean GetWing(){ return Wing; }
public boolean SportLine;
public boolean GetSportLine(){ return SportLine; }
public EntityAirbus(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine) {
super(speed, weight, bodyColor);
DopColor = dopColor;
BodyKit = bodyKit;
Wing = wing;
SportLine = sportLine;
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormPlane">
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" 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="513" height="406"/>
@ -13,7 +13,7 @@
<children>
<component id="2ea16" class="javax.swing.JButton" binding="ButtonDown">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -25,7 +25,7 @@
</component>
<component id="4f60a" class="javax.swing.JButton" binding="ButtonLeft">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -37,7 +37,7 @@
</component>
<component id="4eb88" class="javax.swing.JButton" binding="ButtonRight">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<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">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -50,7 +50,7 @@
</component>
<toolbar id="e747d" binding="StatusStrip">
<constraints>
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<grid row="3" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="20"/>
<preferred-size width="-1" height="20"/>
<maximum-size width="-1" height="20"/>
@ -62,11 +62,6 @@
<border type="none"/>
<children/>
</toolbar>
<hspacer id="d86ff">
<constraints>
<grid row="2" 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="9e2ce" class="javax.swing.JButton" binding="ButtonCreate">
<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"/>
@ -77,7 +72,7 @@
</component>
<grid id="febd4" binding="PictureBox" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints>
<grid row="0" column="0" row-span="1" 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="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@ -85,7 +80,7 @@
</grid>
<component id="fb937" class="javax.swing.JButton" binding="ButtonUp">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -95,6 +90,19 @@
<text value=""/>
</properties>
</component>
<component id="44b75" class="javax.swing.JButton" binding="ButtonModif">
<constraints>
<grid row="2" column="1" 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="Модификация"/>
</properties>
</component>
<hspacer id="dd0eb">
<constraints>
<grid row="2" 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>
</hspacer>
</children>
</grid>
</form>

View File

@ -1,12 +1,13 @@
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.image.BufferedImage;
import java.util.Random;
import static java.lang.Boolean.parseBoolean;
public class FormPlane extends JFrame{
public JPanel Mainpanel;
private JButton ButtonCreate;
@ -17,6 +18,7 @@ public class FormPlane extends JFrame{
protected DrawningPlane _plane;
private JPanel PictureBox;
private JToolBar StatusStrip;
private JButton ButtonModif;
private final JLabel JLabelSpeed = new JLabel();
private final JLabel JLabelWeight = new JLabel();
private final JLabel JLabelColor = new JLabel();
@ -36,6 +38,13 @@ public class FormPlane extends JFrame{
}
validate();
}
private void SetData(){
Random random = new Random();
_plane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), PictureBox.getWidth(), PictureBox.getHeight());
JLabelSpeed.setText("орость: " + _plane.GetPlane().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " "));
}
public FormPlane() {
Box LabelBox = Box.createHorizontalBox();
LabelBox.setMinimumSize(new Dimension(1, 20));
@ -58,10 +67,13 @@ public class FormPlane extends JFrame{
ButtonCreate.addActionListener(e -> {
Random random = new Random();
_plane = new DrawningPlane(random.nextInt(100, 300),random.nextInt(1000, 2000),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
_plane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), PictureBox.getWidth(), PictureBox.getHeight());
JLabelSpeed.setText("орость: " + _plane.GetPlane().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " "));
SetData();
Draw();
});
ButtonModif.addActionListener(e -> {
Random random = new Random();
_plane = new DrawningAirbus(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), random.nextBoolean(), random.nextBoolean(), random.nextBoolean());
SetData();
Draw();
});
PictureBox.addComponentListener(new ComponentAdapter() {