我遇到了一个问题,我有一个计时器类,它会改变我的 GUI 程序的灯光。但是我已经使用了 public void 方法行,所以我现在正在努力添加绘画图形 G。
/*public void paint(Graphics back)
{
back.setColor(Color.black);
back.fillRect(30,30,330,900); //make traffic light for car
back.fillRect(440,140,330,720); //make traffic light for peds
back.setColor(Color.red); //creates red circle
back.fillOval(45,45, 300, 280);
back.fillOval(455,155, 300, 280); //creates red ped circle
back.setColor(Color.yellow); //creates yellow circle
back.fillOval(45, 335, 300,280);
back.setColor(Color.green);
back.fillOval(45,625, 300, 280);
back.fillOval(455,555, 300, 280); //creates green ped circle
}*/
class LightChange implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
paint (Graphics back);
seconds++;
if (seconds == 0 & seconds <= 5)
{
back.setColor(Color.red); //creates red circle
back.fillOval(45,45, 300, 280);
}
else
{
back.setColor(Color.yellow); //creates yellow circle
back.fillOval(45, 335, 300,280);
}
repaint();
}
}
我有一个错误说它找不到后面的符号。任何帮助都会很棒!
编辑:
我做了一些更改并尝试添加油漆(图形背面);进入课堂。出现一些错误消息(表达式的非法开始),但我在正确的路线上吗?