PIbd-23_Vrazhkin_S_A_Electr.../DrawningWheels.java
2023-12-12 12:31:03 +04:00

97 lines
3.1 KiB
Java

import javax.swing.*;
import java.awt.*;
public class DrawningWheels {
private int WheelSz;
JPanel MonorailPanel;
private NumberType WheelsNum;
private Color WheelColor, TireColor;
private int VehicleHeight, VehicleWidth;
public int StartPosX, StartPosY;
public int WheelSz(){
return WheelSz;
}
boolean Init(int width, int height, int startPosX, int startPosY, Color wheelColor, Color tireColor, JPanel monorailPanel){
VehicleWidth = width;
VehicleHeight = height;
StartPosX = startPosX;
WheelColor = wheelColor;
StartPosY = startPosY;
TireColor = tireColor;
MonorailPanel = monorailPanel;
return true;
}
public void ChangeWheelsNumb(int x){
if(x <= 2)
WheelsNum = NumberType.Two;
if(x == 3)
WheelsNum = NumberType.Three;
if(x >= 4)
WheelsNum = NumberType.Four;
}
public NumberType WheelsNumb(){
return WheelsNum;
}
public void DrawWheels(){
Graphics2D g2d = (Graphics2D)MonorailPanel.getGraphics();
int xWheel = StartPosX + 5;
int yWheel = StartPosY + VehicleHeight - 20;
if (WheelsNum == NumberType.Two){
g2d.setColor(WheelColor);
g2d.drawOval(xWheel, yWheel, 20, 20);
g2d.setColor(TireColor);
g2d.fillOval(xWheel, yWheel, 20, 20);
xWheel += 130;
g2d.setColor(WheelColor);
g2d.drawOval(xWheel, yWheel, 20, 20);
g2d.setColor(TireColor);
g2d.fillOval(xWheel, yWheel, 20, 20);
}
else if (WheelsNum == NumberType.Three){
g2d.setColor(WheelColor);
g2d.drawOval(xWheel, yWheel, 20, 20);
g2d.setColor(TireColor);
g2d.fillOval(xWheel, yWheel, 20, 20);
xWheel += 65;
g2d.setColor(WheelColor);
g2d.drawOval(xWheel, yWheel, 20, 20);
g2d.setColor(TireColor);
g2d.fillOval(xWheel, yWheel, 20, 20);
xWheel += 65;
g2d.setColor(WheelColor);
g2d.drawOval(xWheel, yWheel, 20, 20);
g2d.setColor(TireColor);
g2d.fillOval(xWheel, yWheel, 20, 20);
}
else if (WheelsNum == NumberType.Four){
g2d.setColor(WheelColor);
g2d.drawOval(xWheel, yWheel, 20, 20);
g2d.setColor(TireColor);
g2d.fillOval(xWheel, yWheel, 20, 20);
xWheel += 45;
g2d.setColor(WheelColor);
g2d.drawOval(xWheel, yWheel, 20, 20);
g2d.setColor(TireColor);
g2d.fillOval(xWheel, yWheel, 20, 20);
xWheel += 45;
g2d.setColor(WheelColor);
g2d.drawOval(xWheel, yWheel, 20, 20);
g2d.setColor(TireColor);
g2d.fillOval(xWheel, yWheel, 20, 20);
xWheel += 45;
g2d.setColor(WheelColor);
g2d.drawOval(xWheel, yWheel, 20, 20);
g2d.setColor(TireColor);
g2d.fillOval(xWheel, yWheel, 20, 20);
xWheel += 45;
}
}
}