0
我有我的3個按鈕,添加它們並在每個按鈕上都有動作偵聽器。在動作執行部分,他們假設將g.setcolor更改爲某種顏色並重新繪製我的橢圓。我究竟做錯了什麼 ?Java Applet設置顏色動作列表器
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();
}
}
}
其工作。謝謝。 – user1760790 2013-05-01 04:44:51