1 // Program 11.6: A nicer sine wave
2 import java.applet.Applet;
3 import java.awt.Graphics;
5 public class SineApplet2 extends Applet {
7 public void paint(Graphics g) {
12 for (i = 0; i < size().width; i++) {
14 g.drawLine(i, j1 ,i+1, j2);
20 // Given the xpoint we're given calculate the Cartesian equivalent
21 private int yvalue(int ivalue) {
30 x = (ivalue * (xmax - xmin)/(size().width - 1)) + xmin;
32 // Take the sine of that x
35 // Scale y into window coordinates
36 jvalue = (int) ((y - ymin)*(size().height - 1)/
39 /* Switch jvalue from Cartesian coordinates
40 to computer graphics coordinates */
41 jvalue = size().height - jvalue;