Import java.awt. *; import java.util. *; import java.awt.graphics; import java.awt.event. *;
Public Class Grapplet Extends Applet Implements Runnable, MouseListener {Private Int delay = 20;
Private int nwindowwidth = 500; // Smooth window size private int alpha = 6; // Control display parameters
Private Double Beta = 1.9; // Controlling the parameters of the slope Private Double Hold = 10.0; // Slope threshold private INT NMAX = 40; // threshold, exceed this threshold, start modify the slope private int nmin = -40; private int bum = 0; // Control rising or falling 0 normal 1 rise 2 drop
Thread thread;
Private int [] nposxy; // Store the array of coordinate information, the array subscript is the X value, the corresponding unit is stored as a Y value private int noffset = 0; // offset
Boolean bpause = false; // Pause Sign Boolean bfirst = true; // First display
Private image offimg; // Declare the spare screen type private graphics offg; // Declare the standby screen drawing type
Static random rand = new random ();
Private int [] nrand = new int [nwindowwidth]; // Used to store the number, as well as smoothing
Public void init () {setBackground (color.black);
Addmouseristener (THIS); Try {Offimg = CreateImage (GetSize (). Width, getSize (). height); // Create a standby screen OFFG = Offimg.getgraphics (); // Get alternate screen drawing environment} catch (Exception E) {OFFG = NULL; ShowStatus ("Alternate Screen Initialization Failure!");} // Initialization Coordination Array Nposxy = New Int Int [GetSize (). Width]; for (INT X = 0; x Public void start () {thread = new thread (this); // Start thread.start (); noffset = nposxy.length;} Public void stop () {thread = null; // Stop thread nposxy = null; nrand = null; removemouseristener (this); // Delete mouse listening} public void run () {Thread current = Thread.currentThread (); while (thread == current) {try {Thread.currentThread () sleep (delay);.} catch (InterruptedException e) {} repaint (); if ( ! bpause) {if (noffset> = nposxy.Length) {for (int i = 0; i Double F (Double X) {Double Temp = 0.0; Temp = Smooth (); HOLD (TEMP); IF (Temp <= 0 || Temp> = getsize (). HEIGHT) BPAUSE = true; return temp;} Void Hold (double x) {// slope control if (x == nmax && bup == 0) for (int i = 0; i Public void Paint (GRAPHICS G) {// Hold (); // Control slope IF (bfirst) {OFFG.CLARRECT (0, 0, GetSize (). Width, getSize (); ht); offg.setcolor. Red); offg.drawline (0, nmax-10, getSize (). width, nmax-10); offg.drawline (0, nmin 10, getSize (). Width, nmin 10); Offg.SetColor (Color .green); for (int i = 0; i Public void mouseentered (MouseEvent E) {// mouse overlay bpause = true; // set pause} Public void mouseexited (mouseevent e) {bpause = false; // cancel pause} Public void mouseeleased (mouseevent e) {} Public void mousepressed (mouseevent e) {} Public void mouseclicked (mouseevent e) {} Public String getAppletInfo () {return "test drawing";}}