java写一个会动的圆_JAVA实现一个圆形的移动,画出来的圆形移动,我的圆它不动呀...
展開全部
import?java.awt.Graphics;
import?java.awt.Image;
import?javax.swing.JFrame;
public?class?JoinDemo?extends?JFrame?{
public?static?void?main(String[]?args)?{
new?JoinDemo();
}
private?int?x?=?100,?y?=?100,?r?=?100;
public?JoinDemo()?{
this.setTitle("小圖形");
this.setSize(800,?600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
new?UpdateThread().start();
}
public?void?paint(Graphics?g)?{
Image?image?=?createImage(getWidth(),?getHeight());
Graphics?gg?=?image.getGraphics();
bufferedPaint(gg);
gg.dispose();
g.drawImage(image,?0,?0,?null);
}
private?void?bufferedPaint(Graphics?gg)?{
gg.fillOval(x,?y,?r,?r);
}
class?UpdateThread?extends?Thread?{
public?void?run()?{
for?(int?j?=?0;?j?<=?240;?j++)?{
y++;
repaint();
sleep(10);
}
}
private?void?sleep(int?millis)?{
try?{
Thread.sleep(millis);
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
}
}
}
說明:
第一:存為JoinDemo.java
第二:加入了一個緩沖,62616964757a686964616fe4b893e5b19e31333332616464以免畫面閃爍。
總結
以上是生活随笔為你收集整理的java写一个会动的圆_JAVA实现一个圆形的移动,画出来的圆形移动,我的圆它不动呀...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt 3D的研究(三):显示3D模型
- 下一篇: Mac安装tomcat