Complete lab

This commit is contained in:
ArtemEmelyanov 2022-11-29 21:33:34 +04:00
parent 0c7b7b773c
commit 0f832390b4
6 changed files with 92 additions and 6 deletions

View File

@ -1,15 +1,15 @@
import javax.swing.*;
import java.awt.*;
public class DrawningIlluminator extends JComponent {
public class DrawningIlluminator implements IDrawningIlluminator{
private IlluminatorCount _Illuminator;
@Override
public void SetIlluminatorCount(int numOfIllum) {
_Illuminator = IlluminatorCount.GetIlluminatorCount(numOfIllum);
}
@Override
public void DrawIlluminator(Graphics g, int _startPosX, int _startPosY) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
int numOfIlluminator = 0;

View File

@ -13,7 +13,7 @@ public class DrawningPlane extends JPanel {
protected int _startPosX;
protected int _startPosY;
public DrawningIlluminator IlluminatorDraw;
public IDrawningIlluminator IlluminatorDraw;
public Integer _pictureWidth = null;
public Integer _pictureHeight = null;
private int _PlaneWidth = 130;
@ -29,7 +29,18 @@ public class DrawningPlane extends JPanel {
public DrawningPlane(int speed, float weight, Color bodyColor)
{
Plane = new EntityPlane(speed, weight, bodyColor);
IlluminatorDraw = new DrawningIlluminator();
Random random = new Random();
switch (random.nextInt(3)){
case 0:
IlluminatorDraw = new DrawningIlluminator();
break;
case 1:
IlluminatorDraw = new DrawningSqareIlluminator();
break;
case 2:
IlluminatorDraw = new DrawningTriangleIlluminator();
break;
}
SetIlluminator();
}

View File

@ -0,0 +1,33 @@
import java.awt.*;
public class DrawningSqareIlluminator implements IDrawningIlluminator{
private IlluminatorCount _Illuminator;
@Override
public void SetIlluminatorCount(int numOfIllum) {_Illuminator = IlluminatorCount.GetIlluminatorCount(numOfIllum); }
@Override
public void DrawIlluminator(Graphics g, int _startPosX, int _startPosY) {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
int numOfIlluminator = 0;
switch (_Illuminator)
{
case Ten:
numOfIlluminator = 10;
break;
case Twenty:
numOfIlluminator = 20;
break;
case Thirty:
numOfIlluminator = 30;
break;
}
for(int i = numOfIlluminator; i >= 1; --i){
g2d.setColor(Color.CYAN);
g2d.fillRect(_startPosX + 105 - 3 * i, _startPosY + 35, 3, 3);
g2d.setColor(Color.BLACK);
g2d.drawRect(_startPosX + 105 - 3 * i, _startPosY + 35, 3, 3);
}
}
}

View File

@ -0,0 +1,36 @@
import java.awt.*;
public class DrawningTriangleIlluminator implements IDrawningIlluminator{
private IlluminatorCount _Illuminator;
@Override
public void SetIlluminatorCount(int numOfIllum) {
_Illuminator = IlluminatorCount.GetIlluminatorCount(numOfIllum);
}
@Override
public void DrawIlluminator(Graphics g, int _startPosX, int _startPosY) {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
int numOfIlluminator = 0;
switch (_Illuminator)
{
case Ten:
numOfIlluminator = 10;
break;
case Twenty:
numOfIlluminator = 20;
break;
case Thirty:
numOfIlluminator = 30;
break;
}
for(int i = numOfIlluminator; i >= 1; --i){
g2d.setColor(Color.CYAN);
g2d.drawPolygon(new int[] {_startPosX + 105 - 3 * i, _startPosX + 102 - 3 * i, _startPosX + 108 - 3 * i}, new int[] {_startPosY + 35, _startPosY + 38, _startPosY + 38}, 3);
g2d.setColor(Color.BLACK);
g2d.fillPolygon(new int[] {_startPosX + 105 - 3 * i, _startPosX + 102 - 3 * i, _startPosX + 108 - 3 * i}, new int[] {_startPosY + 35, _startPosY + 38, _startPosY + 38}, 3);
}
}
}

View File

@ -0,0 +1,7 @@
import java.awt.*;
public interface IDrawningIlluminator {
void SetIlluminatorCount(int numOfIllum);
void DrawIlluminator(Graphics g, int _startPosX, int _startPosY);
}

View File

@ -1,5 +1,4 @@
import java.awt.*;
import java.util.Enumeration;
public interface IDrawningObject {
float Step();