Home > Back-end >  Questions about Java, it should be an array, you can help me to see if any of the problem
Questions about Java, it should be an array, you can help me to see if any of the problem

Time:09-24

 import Java. Util. The Timer; 
Import the Java. Util. TimerTask;

Public class TrafficLight extends TimerTask {
Private int workStatus;
Private int trafficSignal;
Public int [] lightTime=new int [3].
Private Timer myTimer=new Timer ();
int count=0;
Public TrafficLight () {
WorkStatus=0;
TrafficSignal=3;
LightTime [0]=20.
LightTime [1]=5;
LightTime [2]=30;
}
Public void bootUp () {
WorkStatus=1;
MyTimer. The schedule (this, 0100);
}
Public int getWorkStatus () {
Return the workStatus;
}
Public void setWorkStatus (Boolean value) {
If (value) {
WorkStatus=1;
}
The else {
WorkStatus=0;
}
}
Public int getTrafficSignal () {
If (workStatus> 0)
Return trafficSignal;
The else
return 0;
}
Public void setTrafficSignal (int) signal {
If (signal> 0 & amp; & Signal
=3)TrafficSignal=signal;
count=0;
}
Public Boolean setSignalTime (int [] signalTime) {
Boolean value=https://bbs.csdn.net/topics/false;
If (signalTime. Length==3) {
for(int i=0; iLightTime [I]=signalTime [I];
}
value=https://bbs.csdn.net/topics/true;
}
return value;
}
Public void getSignalTime (int [] signalTime) {
for(int i=0; iSignalTime [I]=lightTime [I];
}
}
Public void switchSignal () {
If (trafficSignal<3) {
TrafficSignal++;
}
The else {
TrafficSignal=1;
}
count=0;
}
Public void the run () {
If (workStatus==1) {
count++;
If (count==lightTime [trafficSignal - 1]) {
count=0;
SwitchSignal ();
}
}
}
Public void displayStatus () {
System. The out. Println (" the current traffic lights work in "+ trafficSignal +" status ");
}
}

 import Java awt. Color; 
Import the Java. The awt. Graphics;

Public class CircleLight extends TrafficLight {
Int the radius=0;
Int direction=0;
int x=0;
Int y=0;
Graphics board;
Public CircleLight () {
The radius=10;
Direction=0;
}
Public void setPosition (int xvalue, int yvalue, int radiusValue) {
X=xvalue;
Y=yvalue;
The radius=radiusValue;
}
Public void setBoard (Graphics boardValue) {
Board=boardValue;
}
Public void showLight () {
Int edge=2;
Board. SetColor (Color black);
Board. FillRect (x - the radius - edge, y - the radius - edge, (the edge radius, +) * 2, (edge radius, +) * 3);
The switch (getTrafficSignal ()) {
Case 1:
Board. SetColor (Color. Green);
break;
Case 2:
Board. SetColor (Color. Yellow);
break;
Case 3:
Board. SetColor (Color. Red);
}
Board. FillOval (radius, x -, y - the radius, 2 * the radius, the radius, 2 *);
Board. DrawString (String. The valueOf (lightTime [getTrafficSignal () - 1) - count), x, y + 2 * the radius).
}
Public void the run () {
If (this. GetWorkStatus ()==1) {
count++;
If (count==lightTime [getTrafficSignal () - 1]) {
count=0;
SwitchSignal ();
}
ShowLight ();
}
}
}

CodePudding user response:

The second code lines 34 and 42 no need to worry about the image (when I upload photos uploaded wrong)

CodePudding user response:

Log under the second guild automatic positioning to the wrong place ah, there you see - 1 is under debugging

CodePudding user response:

refer to the second floor dmankill response:
log under the second guild automatic positioning to the wrong place ah, you are debugging is there to look at - 1 under
how to debug? I debugging also not too will

CodePudding user response:

reference zwl_2019 reply: 3/f
Quote: refer to the second floor dmankill response:

Second guild automatically locate the log to the wrong place ah, you are debugging is there to look at - 1 under
how to debug? I will debug is less


You haven't posted the test program, look at the light can't see anything, first to learn how to ask questions,

CodePudding user response:

reference 4 floor qq_39936465 response:
Quote: reference zwl_2019 reply: 3/f

Quote: refer to the second floor dmankill response:

Second guild automatically locate the log to the wrong place ah, you are debugging is there to look at - 1 under
how to debug? I will debug is less


You haven't posted the test program, see the light can not see, what to learn how to ask questions first,
code fit inside the

CodePudding user response:

reference zwl_2019 reply: 3/f
Quote: refer to the second floor dmankill response:

nullnullnullnullnullnullnullnullnullnullnull
  • Related