【文件属性】:
文件名称:java 小球*落体
文件大小:1KB
文件格式:JAVA
更新时间:2013-01-18 05:10:00
java *落体
小球的*落体运动!
import java.awt.*;
import javax.swing.*;
public class TextBall extends JFrame{
public TextBall(){
super("the ball moving");
setSize(130,500);
setVisible(true);
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.white);
g.fillRect(20,40,50,430);
g.setColor(Color.green);
g.fillOval(40,40,50,50);
int x1=40;
int x2=0;
while(true)
{
while(x1<410)
{
g.setColor(Color.white);
g.fillOval(40,x1,50,50);
g.fillRect(40,40,70,430);
g.setColor(Color.green);
g.fillOval(40,x1+x2,50,50);
x2++;
x1=x1+x2;
try{
Thread.sleep(50);
}catch(Exception e){}
}
while(x1>40&&x2!=0)
{
g.setColor(Color.white);
g.fillOval(40,x1,50,50);
g.fillRect(40,40,70,430);
g.setColor(Color.yellow);
g.fillOval(40,x1-x2,50,50);
x2--;
x1=x1-x2;
try{
Thread.sleep(50);
}catch(Exception e){}
}
}
}
public static void main(String []args){
JFrame.setDefaultLookAndFeelDecorated(true);
TextBall s1=new TextBall();
}
}