我正在尝试在我的applet上正确显示日期。我希望它能够从总天数开始向后计数到零,从上一个月的第一个停止之后的右边开始。 current是当前月份,数组来自索引0 - 11。
if (evt.getSource()==last){//NOT CURRENTLY WORKING...
current--;
if(current == -1){//resets to February
current = 11;
year--;
String now = "Year " +year;
showYear.setText(now);
}
month.setText(months[current]);
stringParse = Integer.parseInt(monthDays[current]);
for (int i = 0; i < 7; i++){//check first week
if(allDays[i].getText().equals("1")){
dateHold =i;//plus then minus to fix index and next month
}
}
for(int j = 0; j < 37; j++)//erase dates
allDays[j].setText("");
int something;//local number holder
int countDown = stringParse;//local count down for reverse printing
if(current ==1 && year%4!=0)//February fix
countDown = 28;
something = countDown - 1 + (dateHold);
for (int i = 36; i >0; i--){//reverse date printing
if(((36 -i)-dateHold)>stringParse)//if date over max
continue;
if(something < 0)
continue;
try{//kept reaching out of index here
allDays[something].setText("" + (countDown));
//System.out.println("i:" + i + "\ndateHold:" + dateHold + "\ncountDown:" + countDown);
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("error i:" + i + "\ndateHold:" + dateHold + "\ncountDown:" + countDown);
}
countDown--;
something--;
if(countDown <= 0)
break;
}
for(int i = 0; i < 37; i++){
eventMarker[i].setText("");
}
}//end last evt