Частично изменил с перечислением

This commit is contained in:
ujijrujijr 2023-11-13 10:56:37 +03:00
parent 31cdee9b88
commit f681dfddc4
2 changed files with 14 additions and 22 deletions

View File

@ -1,14 +1,7 @@
package Trolleybus;
public enum CntOfDoors {
Three (3),
Four (4),
Five (5);
private int Cnt;
CntOfDoors(int cnt) {
Cnt = cnt;
}
public int getCnt(){
return Cnt;
}
Three,
Four,
Five
}

View File

@ -4,22 +4,21 @@ import java.awt.*;
public class DrawingDoors {
private CntOfDoors _cntOfDoors;
public void SetCntOfDoors(int cnt) {
if (cnt < 3 || cnt > 5) {
cnt = 3;
if (cnt <= 3) {
_cntOfDoors = CntOfDoors.Three;
}
//Проход по перечислению
for (CntOfDoors temp : CntOfDoors.values()) {
if (temp.getCnt() == cnt) {
_cntOfDoors = temp;
return;
}
if (cnt == 4) {
_cntOfDoors = CntOfDoors.Four;
}
if (cnt >= 5) {
_cntOfDoors = CntOfDoors.Five;
}
}
public void DrawDoors(Graphics2D g, Color BodyColor, int _startPosX, int _startPosY) {
switch (_cntOfDoors.getCnt())
switch (_cntOfDoors)
{
case 3:
case Three:
g.setColor(BodyColor);
g.drawRect(_startPosX + 2, _startPosY + 50, 16, 30);
g.drawRect(_startPosX + 67, _startPosY + 50, 16, 30);
@ -30,7 +29,7 @@ public class DrawingDoors {
g.drawOval(_startPosX + 87, _startPosY + 35, 16, 24);
g.drawOval(_startPosX + 112, _startPosY + 35, 16, 24);
break;
case 4:
case Four:
g.setColor(BodyColor);
g.drawRect(_startPosX + 2, _startPosY + 50, 16, 30);
g.drawRect(_startPosX + 48, _startPosY + 50, 16, 30);
@ -41,7 +40,7 @@ public class DrawingDoors {
g.drawOval(_startPosX + 67, _startPosY + 35, 16, 24);
g.drawOval(_startPosX + 109, _startPosY + 35, 16, 24);
break;
case 5:
case Five:
g.setColor(BodyColor);
g.drawRect(_startPosX + 2, _startPosY + 50, 16, 30);
g.drawRect(_startPosX + 48, _startPosY + 50, 16, 30);