zoukankan      html  css  js  c++  java
  • 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();
        }
    }

  • 相关阅读:
    jQuery before 和 after
    pm2常用的命令
    git 常见命令
    Number 和 parseInt 区别
    枚举创建单例模式 安全 而且利用反射也读不到
    spring 的数据库工具类 JDBCTemplate
    阿里druid数据库连接及配置文件
    java C3P0连接数据库
    JDBC利用.properties文件连接数据库
    JDBC工具类的使用
  • 原文地址:https://www.cnblogs.com/jayceli/p/2428645.html
Copyright © 2011-2022 走看看