LabWork02 is done!

This commit is contained in:
Yuee Shiness 2022-11-08 17:32:36 +04:00
parent 1883bdcb8a
commit 58305e652e
10 changed files with 293 additions and 91 deletions

View File

@ -1,14 +1,14 @@
package Classes;
import java.awt.*;
import java.util.ArrayList;
import java.util.Random;
public class DrawingAircraft
{
public EntityAircraft Plane;
private DrawingEngines _engines;
private IDrawingEngines _engines;
protected int _startPosX;
protected int _startPosY;
@ -22,7 +22,20 @@ public class DrawingAircraft
public DrawingAircraft(int speed,float weight, Color bodyColor)
{
Random rnd = new Random();
_engines = new DrawingEngines();
int enginesType = rnd.nextInt(1,4);
if(enginesType == 1)
{
_engines = new DrawingArcEngines();
}
else if(enginesType == 2)
{
_engines = new DrawingRectangleEngines();
}
else if(enginesType == 3)
{
_engines = new DrawingOvalEngines();
}
_engines.setEngines(rnd.nextInt(2,7));
Plane = new EntityAircraft(speed,weight,bodyColor);
}

View File

@ -0,0 +1,70 @@
package Classes;
import java.awt.*;
public class DrawingArcEngines implements IDrawingEngines
{
private int enginesCount;
@Override
public void drawEngines(Graphics g, int startPosX, int startPosY,Color bodyColor)
{
switch(enginesCount)
{
case 2 -> {
g.setColor((Color.BLACK));
g.drawArc(startPosX + 40,startPosY + 5,30,10,80,200);
g.drawArc(startPosX + 40,startPosY + 90,30,10,80,200);
g.setColor((bodyColor));
g.fillArc(startPosX + 40,startPosY + 5,30,10,80,200);
g.fillArc(startPosX + 40,startPosY + 90,30,10,80,200);
}
case 4 -> {
g.setColor((Color.BLACK));
g.drawArc(startPosX + 40,startPosY + 5,30,10,80,200);
g.drawArc(startPosX + 40,startPosY + 90,30,10,80,200);
g.drawArc(startPosX + 40,startPosY + 20,30,10,80,200);
g.drawArc(startPosX + 40,startPosY + 75,30,10,80,200);
g.setColor(bodyColor);
g.fillArc(startPosX + 40,startPosY + 5,30,10,80,200);
g.fillArc(startPosX + 40,startPosY + 90,30,10,80,200);
g.fillArc(startPosX + 40,startPosY + 20,30,10,80,200);
g.fillArc(startPosX + 40,startPosY + 75,30,10,80,200);
}
case 6 -> {
g.setColor((Color.BLACK));
g.drawArc(startPosX + 40,startPosY + 5,30,10,80,200);
g.drawArc(startPosX + 40,startPosY + 90,30,10,80,200);
g.drawArc(startPosX + 40,startPosY + 20,30,10,80,200);
g.drawArc(startPosX + 40,startPosY + 75,30,10,80,200);
g.drawArc(startPosX + 40,startPosY + 35,30,10,80,200);
g.drawArc(startPosX + 40,startPosY + 60,30,10,80,200);
g.setColor(bodyColor);
g.fillArc(startPosX + 40,startPosY + 5,30,10,80,200);
g.fillArc(startPosX + 40,startPosY + 90,30,10,80,200);
g.fillArc(startPosX + 40,startPosY + 20,30,10,80,200);
g.fillArc(startPosX + 40,startPosY + 75,30,10,80,200);
g.fillArc(startPosX + 40,startPosY + 35,30,10,80,200);
g.fillArc(startPosX + 40,startPosY + 60,30,10,80,200);
}
}
}
@Override
public void setEngines(int count)
{
enginesCount = count;
}
@Override
public int getCount() {
return enginesCount;
}
}

View File

@ -1,69 +0,0 @@
package Classes;
import java.awt.*;
public class DrawingEngines
{
private Engines enginesCount;
public void setEngines(int count)
{
enginesCount = Engines.getEnginesEnum(count);
}
public void drawEngines(Graphics g,int startPosX,int startPosY,Color bodyColor)
{
if(enginesCount != null)
{
switch(enginesCount)
{
case TwoEngines -> {
g.setColor((Color.BLACK));
g.drawOval(startPosX + 40,startPosY + 5,30,10);
g.drawOval(startPosX + 40,startPosY + 90,30,10);
g.setColor((bodyColor));
g.fillOval(startPosX + 40,startPosY + 5,30,10);
g.fillOval(startPosX + 40,startPosY + 90,30,10);
}
case FourEngines -> {
g.setColor((Color.BLACK));
g.drawOval(startPosX + 40,startPosY + 5,30,10);
g.drawOval(startPosX + 40,startPosY + 90,30,10);
g.drawOval(startPosX + 40,startPosY + 20,30,10);
g.drawOval(startPosX + 40,startPosY + 75,30,10);
g.setColor(bodyColor);
g.fillOval(startPosX + 40,startPosY + 5,30,10);
g.fillOval(startPosX + 40,startPosY + 90,30,10);
g.fillOval(startPosX + 40,startPosY + 20,30,10);
g.fillOval(startPosX + 40,startPosY + 75,30,10);
}
case SixEngines -> {
g.setColor((Color.BLACK));
g.drawOval(startPosX + 40,startPosY + 5,30,10);
g.drawOval(startPosX + 40,startPosY + 90,30,10);
g.drawOval(startPosX + 40,startPosY + 20,30,10);
g.drawOval(startPosX + 40,startPosY + 75,30,10);
g.drawOval(startPosX + 40,startPosY + 35,30,10);
g.drawOval(startPosX + 40,startPosY + 60,30,10);
g.setColor(bodyColor);
g.fillOval(startPosX + 40,startPosY + 5,30,10);
g.fillOval(startPosX + 40,startPosY + 90,30,10);
g.fillOval(startPosX + 40,startPosY + 20,30,10);
g.fillOval(startPosX + 40,startPosY + 75,30,10);
g.fillOval(startPosX + 40,startPosY + 35,30,10);
g.fillOval(startPosX + 40,startPosY + 60,30,10);
}
}
}
}
}

View File

@ -47,9 +47,9 @@ public class DrawingMilitaryAircraft extends DrawingAircraft
Point point2W2 = new Point(point1W2.x , point1W2.y + 40);
Point point3W2 = new Point(point2W2.x + 10,point1W2.y);
pathExtraWing1.addPoint(point1W2.x,point1W2.y);
pathExtraWing1.addPoint(point2W2.x,point2W2.y);
pathExtraWing1.addPoint(point3W2.x,point3W2.y);
pathExtraWing2.addPoint(point1W2.x,point1W2.y);
pathExtraWing2.addPoint(point2W2.x,point2W2.y);
pathExtraWing2.addPoint(point3W2.x,point3W2.y);
g.setColor(Color.black);
g.drawPolygon(pathExtraWing2);

View File

@ -0,0 +1,69 @@
package Classes;
import java.awt.*;
public class DrawingOvalEngines implements IDrawingEngines
{
private int enginesCount;
@Override
public void drawEngines(Graphics g, int startPosX, int startPosY,Color bodyColor)
{
switch(enginesCount)
{
case 2 -> {
g.setColor((Color.BLACK));
g.drawOval(startPosX + 40,startPosY + 5,30,10);
g.drawOval(startPosX + 40,startPosY + 90,30,10);
g.setColor((bodyColor));
g.fillOval(startPosX + 40,startPosY + 5,30,10);
g.fillOval(startPosX + 40,startPosY + 90,30,10);
}
case 4 -> {
g.setColor((Color.BLACK));
g.drawOval(startPosX + 40,startPosY + 5,30,10);
g.drawOval(startPosX + 40,startPosY + 90,30,10);
g.drawOval(startPosX + 40,startPosY + 20,30,10);
g.drawOval(startPosX + 40,startPosY + 75,30,10);
g.setColor(bodyColor);
g.fillOval(startPosX + 40,startPosY + 5,30,10);
g.fillOval(startPosX + 40,startPosY + 90,30,10);
g.fillOval(startPosX + 40,startPosY + 20,30,10);
g.fillOval(startPosX + 40,startPosY + 75,30,10);
}
case 6 -> {
g.setColor((Color.BLACK));
g.drawOval(startPosX + 40,startPosY + 5,30,10);
g.drawOval(startPosX + 40,startPosY + 90,30,10);
g.drawOval(startPosX + 40,startPosY + 20,30,10);
g.drawOval(startPosX + 40,startPosY + 75,30,10);
g.drawOval(startPosX + 40,startPosY + 35,30,10);
g.drawOval(startPosX + 40,startPosY + 60,30,10);
g.setColor(bodyColor);
g.fillOval(startPosX + 40,startPosY + 5,30,10);
g.fillOval(startPosX + 40,startPosY + 90,30,10);
g.fillOval(startPosX + 40,startPosY + 20,30,10);
g.fillOval(startPosX + 40,startPosY + 75,30,10);
g.fillOval(startPosX + 40,startPosY + 35,30,10);
g.fillOval(startPosX + 40,startPosY + 60,30,10);
}
}
}
@Override
public void setEngines(int count)
{
enginesCount = count;
}
@Override
public int getCount() {
return enginesCount;
}
}

View File

@ -0,0 +1,70 @@
package Classes;
import java.awt.*;
public class DrawingRectangleEngines implements IDrawingEngines
{
private int enginesCount;
@Override
public void drawEngines(Graphics g, int startPosX, int startPosY,Color bodyColor)
{
switch(enginesCount)
{
case 2 -> {
g.setColor((Color.BLACK));
g.drawRect(startPosX + 40,startPosY + 5,30,10);
g.drawRect(startPosX + 40,startPosY + 90,30,10);
g.setColor((bodyColor));
g.fillRect(startPosX + 40,startPosY + 5,30,10);
g.fillRect(startPosX + 40,startPosY + 90,30,10);
}
case 4 -> {
g.setColor((Color.BLACK));
g.drawRect(startPosX + 40,startPosY + 5,30,10);
g.drawRect(startPosX + 40,startPosY + 90,30,10);
g.drawRect(startPosX + 40,startPosY + 20,30,10);
g.drawRect(startPosX + 40,startPosY + 75,30,10);
g.setColor(bodyColor);
g.fillRect(startPosX + 40,startPosY + 5,30,10);
g.fillRect(startPosX + 40,startPosY + 90,30,10);
g.fillRect(startPosX + 40,startPosY + 20,30,10);
g.fillRect(startPosX + 40,startPosY + 75,30,10);
}
case 6 -> {
g.setColor((Color.BLACK));
g.drawRect(startPosX + 40,startPosY + 5,30,10);
g.drawRect(startPosX + 40,startPosY + 90,30,10);
g.drawRect(startPosX + 40,startPosY + 20,30,10);
g.drawRect(startPosX + 40,startPosY + 75,30,10);
g.drawRect(startPosX + 40,startPosY + 35,30,10);
g.drawRect(startPosX + 40,startPosY + 60,30,10);
g.setColor(bodyColor);
g.fillRect(startPosX + 40,startPosY + 5,30,10);
g.fillRect(startPosX + 40,startPosY + 90,30,10);
g.fillRect(startPosX + 40,startPosY + 20,30,10);
g.fillRect(startPosX + 40,startPosY + 75,30,10);
g.fillRect(startPosX + 40,startPosY + 35,30,10);
g.fillRect(startPosX + 40,startPosY + 60,30,10);
}
}
}
@Override
public void setEngines(int count)
{
enginesCount = count;
}
@Override
public int getCount() {
return enginesCount;
}
}

View File

@ -0,0 +1,10 @@
package Classes;
import java.awt.*;
public interface IDrawingEngines
{
void drawEngines(Graphics g, int startX, int startY,Color bodyColor);
void setEngines(int count);
int getCount();
}

View File

@ -38,7 +38,7 @@
</component>
</children>
</grid>
<grid id="53a7f" binding="pictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="53a7f" binding="pictureBox" layout-manager="GridLayoutManager" row-count="3" 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 border-constraint="Center"/>
<properties/>
@ -46,7 +46,7 @@
<children>
<component id="f5248" class="javax.swing.JButton" binding="moveRight">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -61,17 +61,17 @@
</component>
<hspacer id="69b03">
<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"/>
<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>
<vspacer id="2a7c5">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="0" column="2" 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="71509" class="javax.swing.JButton" binding="moveDown">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -86,7 +86,7 @@
</component>
<component id="fb1e5" class="javax.swing.JButton" binding="moveLeft">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -101,7 +101,7 @@
</component>
<component id="cc503" class="javax.swing.JButton" binding="moveUp">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -122,6 +122,14 @@
<text value="Create"/>
</properties>
</component>
<component id="a41e9" class="javax.swing.JButton" binding="btnModification">
<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="Modification"/>
</properties>
</component>
</children>
</grid>
</children>

View File

@ -1,6 +1,7 @@
package Form;
import Classes.Direction;
import Classes.DrawingAircraft;
import Classes.DrawingMilitaryAircraft;
import javax.swing.*;
import java.awt.*;
@ -25,6 +26,7 @@ public class FormAirFighter extends JFrame
private JButton moveLeft;
private JButton moveUp;
private JButton btnCreate;
private JButton btnModification;
private void moveButtonClick(ActionEvent event) {
if (_aircraft == null) return;
@ -46,6 +48,21 @@ public class FormAirFighter extends JFrame
Draw();
}
private void SetData()
{
Random rnd = new Random();
_aircraft.SetPosition(
rnd.nextInt(0, 100),
rnd.nextInt(0, 100),
Form.getWidth(),
Form.getHeight()
);
speedLabel.setText("Speed: " + _aircraft.Plane.getSpeed());
weightLabel.setText("Weight: " + _aircraft.Plane.getWeight());
colorLabel.setText("Color: " + _aircraft.Plane.getBodyColor());
}
private void CreateEntity() {
Random random = new Random();
_aircraft = new DrawingAircraft(random.nextInt(10, 300),
@ -55,19 +72,21 @@ public class FormAirFighter extends JFrame
random.nextInt(0,256)
));
_aircraft.SetPosition(
random.nextInt(0, 100),
random.nextInt(0, 100),
Form.getWidth(),
Form.getHeight()
);
speedLabel.setText("Speed: " + _aircraft.Plane.getSpeed());
weightLabel.setText("Weight: " + _aircraft.Plane.getWeight());
colorLabel.setText("Color: " + _aircraft.Plane.getBodyColor());
SetData();
Draw();
}
private void CreateModifiedEntity()
{
Random rnd = new Random();
_aircraft = new DrawingMilitaryAircraft(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0,256),rnd.nextInt(0,256),rnd.nextInt(0,256)), new Color(rnd.nextInt(0,256),rnd.nextInt(0,256),rnd.nextInt(0,256)),
rnd.nextBoolean(), rnd.nextBoolean());
SetData();
Draw();
}
private void resizeWindow() {
_aircraft.ChangeBorders(pictureBox.getWidth(), pictureBox.getHeight());
Draw();
@ -95,6 +114,7 @@ public class FormAirFighter extends JFrame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
btnCreate.addActionListener(e -> CreateEntity());
btnModification.addActionListener(e -> CreateModifiedEntity());
Form.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {

11
LisovJava.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>