请大家帮忙看看下面的代码,编译可以通过,运行时却有很多问题
请大家帮忙看看下面的代码,编译可以通过,运行时却有很多问题
我是菜鸟,谢谢指点!!
import java.awt.*;
import javax.swing.*;
class FallChar
{
public int x,y,v;
public String s;
public void FallChar()
{ x=(int)Math.random()*400;
x=10*(Math.round(x/10f));
y=-(int)Math.random()*100;
v=(int)Math.random()*10;
s=""+(char)(int)(Math.random()*26+65); //Get a Random char between A~Z
}
public void fall()
{ y+=v;
if(y>300+24)
{ y=-(int)Math.random()*100;
x=(int)Math.random()*400;
x=10*(Math.round(x/10f));
}
}
}
public class Matrix extends javax.swing.JApplet implements Runnable
{
FallChar[] fc=new FallChar[256];
Thread runner;
public void init()
{
}
public void start()
{ if(runner==null)
runner=new Thread(this);
runner.start();
}
public void paint(Graphics g)
{ Graphics2D gg=(Graphics2D)g;
gg.setColor(Color.black);
gg.fillRect(0,0,400,300);
gg.setColor(Color.green);
gg.drawString("http://goomoo.uuoo.com",10,20);
System.out.println("http://goomoo.uuoo.com");
gg.drawString(fc[0].s,10,50);
for(int i=0;i<fc.length;i++)
{ g.drawString(fc[i].s,fc[i].x,fc[i].y);
}
}
public void run()
{
while(true)
{
for(int i=0;i<fc.length;i++)
{ fc[i].fall();
System.out.print(""+fc[i].y);
}
this.repaint();
try
{ runner.sleep(100);
}
catch(InterruptedException e){};
}
}
}