PIbd-21_Zhirnova_A_E_Double.../DoubleDeckerBus/DrawningObjects/DrawningDoorTriangle.java

74 lines
2.0 KiB
Java
Raw Normal View History

package DoubleDeckerBus.DrawningObjects;
import DoubleDeckerBus.DoorNumberType;
import javax.swing.*;
import java.awt.*;
public class DrawningDoorTriangle implements IDraw {
JPanel BusPanel;
private DoubleDeckerBus.DoorNumberType DoorNumberType;
private Color blackColor;
private int Width;
private int Height;
public int CurX;
public int CurY;
public DrawningDoorTriangle(int width, int height, int curX, int curY, JPanel busPanel) {
Width = width;
Height = height;
CurX = curX;
CurY = curY;
blackColor = Color.BLACK;
BusPanel = busPanel;
}
public void ChangeX(int x){
CurX = x;
}
public void ChangeY(int y){
CurY = y;
}
public void ChangeDoorsNumber(int x) {
if (x <= 3) {
DoorNumberType = DoorNumberType.Three;
}
if (x == 4) {
DoorNumberType = DoorNumberType.Four;
}
if (x >= 5) {
DoorNumberType = DoorNumberType.Five;
}
}
public DoorNumberType DoorNumberType() {
return DoorNumberType;
}
public void DrawDoor(int x, int y){
Graphics2D g2d = (Graphics2D)BusPanel.getGraphics();
int[] xPoints = {x, x + 5, x + 10};
int[] yPoints = {y + 20, y, y + 20};
g2d.fillPolygon(xPoints, yPoints, 3);
}
public void DrawDoors() {
Graphics2D g2d = (Graphics2D) BusPanel.getGraphics();
g2d.setColor(blackColor);
DrawDoor(CurX + 55, CurY + 60);
DrawDoor(CurX + 70, CurY + 60);
if (DoorNumberType() == DoorNumberType.Three || DoorNumberType() == DoorNumberType.Four || DoorNumberType() == DoorNumberType.Five) {
DrawDoor(CurX + 85, CurY + 60);
}
if (DoorNumberType() == DoorNumberType.Four || DoorNumberType() == DoorNumberType.Five) {
DrawDoor(CurX + 100, CurY + 60);
}
if (DoorNumberType() == DoorNumberType.Five) {
DrawDoor(CurX + 115, CurY + 60);
}
}
}