编写一个java Applet, 计算3 6 9 12 ….. 99, 用蓝色输出

来源:百度知道 编辑:UC知道 时间:2024/06/28 11:03:39
有关java问题

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

public class three extends Applet
{
int[] i=new int[100/3];
public void init()
{
int o=0;
for(int j=3;j<100;j+=3)
{
i[o]=j;
o++;
}
}

public void paint(Graphics g)
{
g.setColor(Color.blue);
int y=0;
int x=0;
for(int p=0;p<i.length ;p++)
{
if(p%5==0)
{
y+=15;
x=0;
}
g.drawString(""+i[p],x+=18,y);
}
}
}
//同一目录的html中<body></body>之间加上:<applet code="three.class" width=300 height=500></applet>
就可以了