我有我的 3 个按钮,添加了它们并在每个按钮上都有动作监听器。在执行的动作部分,他们假设将 g.setcolor 更改为某种颜色并重新绘制我的椭圆形。我究竟做错了什么 ?
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class zzz extends Applet implements ActionListener {
Button a, b, c;
public void init()
{
setLayout(new FlowLayout());
a = new Button("Red");
b = new Button("Blue");
c = new Button("Green");
add(a);
add(b);
add(c);
a.addActionListener(this);
b.addActionListener(this);
c.addActionListener(this);
}
public void paint(Graphics g){
g.drawOval(250,100,100,100);
g.drawString("Circle",275,100);
g.setColor(Color.white);
g.fillOval(250,100,100,100);
}
public void actionPerformed (ActionEvent evt)
{
if (evt.getSource() == a){
g.setColor(Color.red);
repaint();
}
else if (evt.getSource() == b){
g.setColor(Color.blue);
repaint();
}
else if (evt.getSource() == c){
g.setColor(Color.green);
repaint();
}
}
}