j_drawsin.java

来自「一个十分好的java基础学习的课件」· Java 代码 · 共 35 行

JAVA
35
字号
// ////////////////////////////////////////////////////////
// 
// J_DrawSin.java
// 

// ////////////////////////////////////////////////////////

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 + =
减小字号Ctrl + -
显示快捷键?