• 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();
        }
    }

  • 相关阅读:
    P1495 曹冲养猪
    luoguP4281[AHOI2008]紧急集合 / 聚会
    NOIP1997 代数表达式
    luogu P3709大爷的字符串题
    luoguP3912 素数个数
    POJ 1065 Wooden Sticks
    POJ 1063 Flip and Shift
    POJ 1062 昂贵的聘礼
    POJ 1003 Hangover
    POJ 1001 Exponentiation
  • 原文地址:https://www.cnblogs.com/jayceli/p/2428645.html
Copyright © 2020-2023  润新知