zoukankan      html  css  js  c++  java
  • 16.12

     1 import java.awt.*;
     2 import java.awt.event.ActionEvent;
     3 import java.awt.event.ActionListener;
     4 
     5 import javax.swing.*;
     6 
     7 public class Test_16_12 extends JFrame{
     8     
     9     public Test_16_12(){
    10         add(new JP());
    11     }
    12     public static void main(String[] args) {
    13         // TODO Auto-generated method stub
    14         Test_16_12 t1 = new Test_16_12();
    15         t1.setTitle("Test_16.12");
    16         t1.setLocationRelativeTo(null);
    17         t1.setSize(300,300);
    18         t1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    19         t1.setVisible(true);
    20     }
    21     
    22     static class JP extends JPanel{
    23         private int h =0;
    24         public JP(){
    25         Timer timer = new Timer(10,new TimerListener());
    26         timer.start();
    27         }
    28         public void paintComponent(Graphics g){
    29             super.paintComponent(g);
    30             
    31             int xCenter = getWidth()/2;
    32             int yCenter = getHeight()/2;
    33             int radius = (int)(Math.min(getWidth(), getHeight())*0.4);
    34             int x = xCenter - radius;
    35             int y = yCenter - radius;
    36             
    37             
    38             g.fillArc(x, y, 2*radius, 2*radius, 0+h, 30);
    39             g.fillArc(x, y, 2*radius, 2*radius, 90+h, 30);
    40             g.fillArc(x, y, 2*radius, 2*radius, 180+h, 30);
    41             g.fillArc(x, y, 2*radius, 2*radius, 270+h, 30);            
    42         }
    43         class TimerListener implements ActionListener
    44         {                
    45             @Override
    46             public void actionPerformed(ActionEvent arg0) {
    47                 // TODO Auto-generated method stub
    48                 h += 3;
    49                 repaint();
    50             }
    51         }
    52     }
    53 }
    Test_16_12.java

    需要注意的: Timer的创建应该放在JP的构造函数中

    效果图:下图实际上是动态的

  • 相关阅读:
    Java二叉树非递归实现
    iOS程序生命周期 AppDelegate
    pch 文件
    获取app崩溃信息的途径 iOS
    iOS Storyboard适配问题
    时间戳
    lable 以及cell的高度自适应
    时间戳 获得当前时间 -iOS
    GCD 多线程 ---的记录 iOS
    OC 常用方法记录
  • 原文地址:https://www.cnblogs.com/wanjiang/p/5645130.html
Copyright © 2011-2022 走看看