JAVA小程序,按钮圆变色
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class Sample extends Applet
{
final JButton b = new JButton("换颜色");
int i = 0;
boolean c = false;
public void init()
{
this.setSize(500, 500);
add(b);
final Color c[] = {Color.red, Color.orange, Color.yellow, Color.green, Color.black, Color.blue, Color.gray};
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(i == 6)
{
i = 0;
}
else
{
i++;
}
Graphics g1 = getGraphics();
g1.setColor(c[i]);
update(g1);
}
});
}
public void paint(Graphics g)
{
super.paint(g);
if(!c)
{
g.setColor(Color.red);
c = true;
}
g.fillOval(50, 50, 400, 400);
}
public static void main(String[] args)
{
new Sample().start();
}
}
以上是 JAVA小程序,按钮圆变色 的全部内容, 来源链接: utcz.com/z/390105.html