public class Ch1_3_2 extends Applet
{
int x,y;
public void start()
{
//画画之前,必须先取得画笔
Graphics g=getGraphics();
//画x轴、y轴
for(x=0;x<=750;x+=1)
{
g.drawString("·",x,200);
if(x<=385) g.drawString("·",360,x);
}
g.drawString("Y",330,20);
//画y轴箭头
for(x=360;x<=370;x+=1)
{
g.drawString("·",x-10,375-x);
g.drawString("·",x,x-355);
}
//画x轴箭头
g.drawString("X",735,230);
for(x=740;x<=750;x+=1)
{
g.drawString("·",x,x-550);
g.drawString("·",x,950-x);
}
//画cox()曲线
for(x=0;x<=720;x+=1)
{
double a=Math.cos(x*Math. PI/180+Math.PI);
y=(int)(200+80*a);//放大80倍并向下平移200个像素
g.drawString("·",x,y);
}
}
}
Ch1_3.html网页代码如下:
<html>
<head><title>余弦曲线测试</title></head>
</body>
<p>
<!--调用Ch1_3字节码文件 -->
<applet code=Ch1_3.class
<!--设置窗口大小 -->
width=900
height=600>
</applet>
</body>
</html>