我是新来的。我试图在javaApplet中绘制一个圆圈,但不知何故在输出中显示了3个圆圈。任何想法?JavaApplet额外的圆圈在屏幕上打印
import javax.swing.JApplet;
import java.util.*;
import java.awt.*;
public class Shapes extends JApplet
{
public void paint (Graphics page)
{
resize(400,300);
Random rand = new Random();
// Declare size constants
final int circleMax = 160,circleMin = 40; // circle max and min diameter
final int locMaxX = 360, locMaxY = 260;
int radiusSize = 0, locationx = 0,locationy = 0 ;
// Declare variables
radiusSize = (rand.nextInt(circleMax)+ circleMin);
locationx =20 ;//rand.nextInt(locMaxX)+ 20;
locationy =20 ;// rand.nextInt(locMaxY) + 20;
// Draw the circle 1
page.drawOval(locationx, locationy, radiusSize,radiusSize);
}
}
我测试了这一点,并修改了一些以添加更多形状,它完美地工作,谢谢。我唯一的问题是如何将窗口大小设置为400x300,因此在运行小程序时,它总是以此大小打开。这是我在我的第一个代码中尝试使用resize()的原因。 – Meeeeee
@adrian applet大小是在HTML代码中设置的,而不是在Java代码中设置的。 –