long totalMilliSeconds = System.currentTimeMillis();
long totalSeconds = totalMilliSeconds / 1000;
long currentSecond = totalSeconds % 60;
long totalMinutes = totalSeconds / 60;
long currentMinute = totalMinutes % 60;
long totalHours = totalMinutes / 60;
long currentHour = totalHours % 24;
System.out.println("Current time is:" + currentHour + ":" + currentMinute + ":" + currentSecond);
if(currentHour <= 9 && currentHour >=18)
readFile.setForeground(YELLOW);
readFile.setBackground(BLACK);
graph.setForeground(YELLOW);
graph.setBackground(BLACK);
search.setForeground(YELLOW);
search.setBackground(BLACK);
snippet.setForeground(YELLOW);
snippet.setBackground(BLACK);
prediction.setForeground(YELLOW);
prediction.setBackground(BLACK);
export.setForeground(YELLOW);
export.setBackground(BLACK);
back.setForeground(YELLOW);
back.setBackground(BLACK);
程序应该从下午6点到上午9点改变按钮的颜色,但我不确定为什么它在设定的时间之前仍然在变化。任何想法都将不胜感激。
答案 0 :(得分:-1)
我发现您的代码有两个问题:
true
。为此,该值必须小于或等于9,同时大于或等于18. 缺少大括号(包含所有颜色更改语句)if-statement的主体
if(currentHour <= 9 && currentHour >=18) {
readFile.setForeground(YELLOW);
}
readFile.setBackground(BLACK);
graph.setForeground(YELLOW);
graph.setBackground(BLACK);
因此,许多颜色的设置与if条件无关。