javaapplet画正弦
时间: 2023-10-30 17:07:31 浏览: 46
以下是一个简单的 Java Applet 代码,可以绘制正弦曲线:
```java
import java.applet.Applet;
import java.awt.*;
public class SinCurve extends Applet {
public void paint(Graphics g) {
int width = getWidth();
int height = getHeight();
// 设置画笔颜色
g.setColor(Color.blue);
// 绘制坐标轴
g.drawLine(0, height / 2, width, height / 2);
g.drawLine(width / 2, 0, width / 2, height);
// 绘制正弦曲线
g.setColor(Color.red);
for (int x = 0; x < width; x++) {
double y = 50 * Math.sin((x - (width / 2)) * 2 * Math.PI / 180);
g.drawLine(x, (int) (height / 2 - y), x + 1, (int) (height / 2 - y));
}
}
}
```
在 HTML 文件中,可以使用以下代码将 Applet 嵌入到网页中:
```html
<applet code="SinCurve.class" width="600" height="400"></applet>
```
注意:由于 Applet 技术已经被浏览器淘汰,你可能需要在使用此代码时进行额外的配置和调整。