这是我的代码:
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++;
}
}
}
我的代码和他的差不多,为什么他的就能画出来,我的画不出来呢??
我一个人整了半天了,也没解决..都快崩溃了!!请高手们帮帮忙呀....
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++;
}
}
}
我的代码和他的差不多,为什么他的就能画出来,我的画不出来呢??
我一个人整了半天了,也没解决..都快崩溃了!!请高手们帮帮忙呀....
其实就是把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; }
}
}
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; }
}
}
真的很谢谢.第一次上CSDN,呵呵.感谢你们的照顾