这是我的代码:
import java.awt.*; 
import java.applet.Applet; public class No extends Applet
{
public void print(Graphics g)
{
int x,y,w,h,red,green,blue;
x=0;
y=0;
w=super.getWidth();
h=super.getHeight();
while (super.getWidth()/2-x>10)
{
red=(int)(Math.random()*255);
green=(int)(Math.random()*255);
blue=(int)(Math.random()*255);
g.setColor(new Color(red,green,blue));
g.drawOval(x,y,w,h);
h-=20;
w-=20;
x+=10;
y+=10;

}
}
}
用appletviewer运行后没任何效果.这是我同学的代码:
import java.awt.*;
import java.awt.Graphics;
import java.applet.Applet;
public class dlx extends Applet
{
public void paint(Graphics g)
{
int m=0,red,green,blue;
for(int i=240;i<=450;i++)
{
i=i+9;

red=(int)(Math.random()*255);
green=(int)(Math.random()*255);
blue=(int)(Math.random()*255);
g.setColor(new Color(red,green,blue));

g.drawOval(i,i,450-20*m,350-20*m); m++;
}
}
}
我的代码和他的差不多,为什么他的就能画出来,我的画不出来呢??
我一个人整了半天了,也没解决..都快崩溃了!!请高手们帮帮忙呀....

解决方案 »

  1.   

    你的方法是print,没有覆盖父类的方法。Applet不会调用的。
    其实就是把print 改成paint就好了。public class No extends Applet
    {
    @Override
    public void paint(Graphics g)
    {
    int x, y, w, h, red, green, blue;
    x = 0;
    y = 0;
    w = super.getWidth();
    h = super.getHeight();
    while (super.getWidth() / 2 - x > 10)
    {
    red = (int) (Math.random() * 255);
    green = (int) (Math.random() * 255);
    blue = (int) (Math.random() * 255);
    g.setColor(new Color(red, green, blue));
    g.drawOval(x, y, w, h);
    h -= 20;
    w -= 20;
    x += 10;
    y += 10; }
    }
    }
      

  2.   

    没什么大的错误,是你不小心把paint方法的关键字写错了,改过来可以了!要看清楚哦,是paint不是print哦!
      

  3.   

    你要把你画圆的的方法放到paint中呀,不然不会重绘你当然看不到啦,建议你先看到它的原理这来改吧.如果还有问题给我留言我帮你解决吧
      

  4.   

    没什么大的错误,是你不小心把paint方法的关键字写错了,改过来可以了!要看清楚哦,是paint不是print哦!
    import java.awt.*; 
    import java.applet.Applet; public class No extends Applet 

    public void paint(Graphics g) 

    int x,y,w,h,red,green,blue; 
    x=0; 
    y=0; 
    w=super.getWidth(); 
    h=super.getHeight(); 
    while (super.getWidth()/2-x>10) 

    red=(int)(Math.random()*255); 
    green=(int)(Math.random()*255); 
    blue=(int)(Math.random()*255); 
    g.setColor(new Color(red,green,blue)); 
    g.drawOval(x,y,w,h); 
    h-=20; 
    w-=20; 
    x+=10; 
    y+=10; } 


      

  5.   

    谢谢你们的解答!!!!
    真的很谢谢.第一次上CSDN,呵呵.感谢你们的照顾