16.12
2016-07-05 21:47
141 查看
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Test_16_12 extends JFrame{ public Test_16_12(){ add(new JP()); } public static void main(String[] args) { // TODO Auto-generated method stub Test_16_12 t1 = new Test_16_12(); t1.setTitle("Test_16.12"); t1.setLocationRelativeTo(null); t1.setSize(300,300); t1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); t1.setVisible(true); } static class JP extends JPanel{ private int h =0; public JP(){ Timer timer = new Timer(10,new TimerListener()); timer.start(); } public void paintComponent(Graphics g){ super.paintComponent(g); int xCenter = getWidth()/2; int yCenter = getHeight()/2; int radius = (int)(Math.min(getWidth(), getHeight())*0.4); int x = xCenter - radius; int y = yCenter - radius; g.fillArc(x, y, 2*radius, 2*radius, 0+h, 30); g.fillArc(x, y, 2*radius, 2*radius, 90+h, 30); g.fillArc(x, y, 2*radius, 2*radius, 180+h, 30); g.fillArc(x, y, 2*radius, 2*radius, 270+h, 30); } class TimerListener implements ActionListener { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub h += 3; repaint(); } } } }
Test_16_12.java
需要注意的: Timer的创建应该放在JP的构造函数中
效果图:下图实际上是动态的
相关文章推荐
- Android系统架构
- mysql_初入江湖_02_sql.date 和 util.date
- Qt学习笔记——初学简单笔记
- js之DOM深入学习总结
- 问题: Cannot change version of project facet Dynamic Web Module to 2.5.
- 3304 水果姐逛水果街Ⅰ
- [Leetcode]50. Pow(x, n)
- memcache扩展开启
- 工厂模式
- UFW防火墙的简单配置
- centos系统下完全分布式安装hadoop2.2.0
- Qt输出调试信息
- JAVA中的关键字
- 开源android-crop裁剪库的bug并修复
- 电商的秒杀与抢购--大并发处理
- javascript基础:DOM3操作表格和样式
- [无异常,才正常]java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
- java.lang.InterruptedException: sleep interrupted异常
- 模拟QQ页面上滑隐藏搜索控件的效果
- 【GDOI2013模拟1】屏保