package defaulte;
import java.applet.Applet;
import java.awt.*;
public class Cos extends Applet {
int x, y;
public void start() {
Graphics g = getGraphics();
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);
}
}
}
------解决方案--------------------
另外你那个 start() 方法出错了。你在api里可以查找到start的定义
由浏览器或 applet viewer
调用,通知此 applet 它应该开始执行。
所以在这边不能使用 start()方法,这边给你全部的代码
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);
}
}