日期:2014-05-20 浏览次数:20792 次
由浏览器或 applet viewer
调用,通知此 applet 它应该开始执行。
package csdn.programbbs_620;
import java.applet.Applet;
import java.awt.*;
public class Cos extends Applet {
int x, y;
public void paint(Graphics g) {
for (x = 0; x <= 750; x += 1) {
g.drawString(".", x, 200);
if (x <= 385)
g.drawString(".", 360, x);
}
g.drawString("Y", 330, 20);
for (x = 360; x <= 370; x += 1) {
g.drawString(".", x - 10, 375 - x);
g.drawString(".", x, x - 355);
}
g.drawString("X", x, x - 550);
for (x = 740; x <= 750; x += 1) {
g.drawString("x", x, x - 550);
g.drawString(".", x, 950 - x);
}
for (x = 0; x <= 720; x += 1) {
double a = Math.cos(x * Math.PI / 180);
y = (int) (200 + 80 * a);
g.drawString(".", x, y);
}
}
public static void main(String[] args) {
Frame jf = new Frame();
jf.setLayout(new FlowLayout());
jf.add(new Cos());
jf.setVisible(true);
}
}