12内部类

内部类执行动画效果:

动画是如何运动的:

 

import javax.swing.*;
import java.awt.*;

public class Test {

    int x = 70;
    int y = 70;

    public static void main(String[] args) {
        Test t = new Test();
        t.go();
    }

    public void go() {
        JFrame frame = new JFrame();
        MyJpanel panel = new MyJpanel();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(panel);
        frame.setSize(500,500);
        frame.setVisible(true);

        for(int i = 0; i < 130; i++) {
            x++;
            y++;

            panel.repaint();
            try{
                Thread.sleep(50);
            } catch (Exception e) {
                System.out.println("异常");
            }
        }
    }

    class MyJpanel extends  JPanel{
        public void paintComponent(Graphics g) {
            g.setColor(Color.white);
            g.fillOval(0,0,this.getWidth(), this.getHeight());

            g.setColor(Color.orange);
            g.fillOval(x,y,100,100);
        }
    }

}

 

posted @ 2017-08-08 19:12  亡命鸡礼花  阅读(76)  评论(0编辑  收藏  举报