需要导入的颜色包:
import java.awt.Color;
按钮的事件:
txtOutput.setText("");
txtOutput.setBackground(Color.WHITE);
// 定义学生成绩变量:
double score;
String output="";
score=Double.parseDouble(txtScore.getText());
// 定义学生成绩
if(score>=65){
output="考试通过";
txtOutput.setBackground(Color.green);
txtOutput.setText(output);
}else if(score<60){
output="考试未通过";
txtOutput.setBackground(Color.red);
txtOutput.setText(output);
}