Java applent applets draw coordinate points using random numbers to generate a curve (with bug Version)

Source: Internet
Author: User



This is a bug version. When generating (x, y) points, I forgot to consider that X is getting bigger and bigger, that is, the value of X is increased along the square direction.


Import java. AWT .*;

Import java. Applet. Applet;

Import java. util. Random;


Public class j18draw extends Applet

{

Final int length = 50;

Final int min_x = 10;

Final int max_x = 450;

Final int min_y = 10;

Final int max_y = 290;


Int pointsx [];

Int pointsy [];



Public void Init ()

{

Pointsx = new int [length];

Pointsy = new int [length];

Random RDX = new random ();

Random rdy = new random ();


For (INT I = 0; I <length; ++ I)

{

Int temp = RDX. nextint (max_x + 1); // max_x + 1 is because the random number range generated by nextint (INT value) is [0, value-1]

Pointsx [I] = temp <min_x? Temp + 10: temp; // generate X,


Temp = rdy. nextint (max_y + 1 );

Pointsy [I] = temp <min_y? Temp + 10: temp;

}

}


Public void start ()

{

Repaint ();

}


Public void paint (Graphics g)

{

G. drawline (10,150,450,150); // horizontal axis

G. drawline (10,290, 10, 10); // vertical axis


For (INT I = 0; I <(length-1); ++ I)

{

// Connect two adjacent points

G. drawline (pointsx [I], pointsy [I], pointsx [I + 1], pointsy [I + 1]);

}

}

}



Bytes ------------------------------------------------------------------------------------------

Use in HTML

<HTML>

<Head>

<Title>

Java Applet draw Coordinate System

</Title>

</Head>


<Body>

<APPLET code = "j18draw. Class" width = 500 Height = 300>

</APPLET>


</Body>


</Html>


Shows the effect in the browser:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.