📄 j_drawsin.java.bak
字号:
// ////////////////////////////////////////////////////////
//
// J_DrawSin.java
//
// Created by Jun-Hai Yong, on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
// Display the two-dimensional curve:
// y=sin(x), x=[0, 2pi]
// on a web page.
// ////////////////////////////////////////////////////////
// Using this example, please explicitly refer to the book:
// Jun-Hai Yong. Programming in Java.
// Beijing: Tsinghua University Press, 2004.
// 使用本例子,请注明引用:
// 雍俊海. Java 程序设计. 北京: 清华大学出版社, 2004.
// Please note that the author and publisher make no
// warranty of any kind on the examples provided.
// ////////////////////////////////////////////////////////
import java.awt.Graphics;
import java.applet.Applet;
// ////////////////////////////////////////////////////////
// Display y=sin(x)
public class J_DrawSin extends Applet
{
public void paint(Graphics g)
{
super.paint( g ); // Call system's method.
double d, tx;
int x, y, x0, y0;
d= Math.PI/100; // The curve is divided into 200 segments
x0=y0=0;
for (tx= 0, x= 20; tx<= 2*Math.PI; tx+=d, x++)
{ // Draw the curve
y= 120-(int)(Math.sin(tx)*50+60); // Scaling, translation and symmetry
if (x>20)
g.drawLine(x0, y0, x, y);
x0= x;
y0= y;
} // End of the loop: for
g.drawString("y=sin(x)", 10, 70);
} // End of method: paint
} // End of class: J_DrawSin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -