Assignment: Write a Java Applet which draws a spiral, much like the one below. Your spiral will be created by drawing a series of lines. You must use a for loop



Yüklə 88,63 Kb.
tarix07.11.2018
ölçüsü88,63 Kb.
#78518

JAVA APPLETS ARE NOT PART OF THE AP SUBSET… But they are pretty cool and worth writing at least one.




A Java applet is a basically just a Java program that a browser enabled with Java can run. An applet is typically embedded inside a web page.


Assignment:

Write a Java Applet which draws a spiral, much like the one below. Your spiral will be created by drawing a series of lines. You must use a for loop -or- while loop to create the drawing.

To get started…
1) Open BlueJ
2) Create a new class of type APPLET, and cut and paste the following code in.
3) To run the applet, right click and select RUN APPLET.
Note: Java's coordinate system has the point (0,0) in the top-left corner. Positive x values are to the right and positive y values are down. All pixel values are integers; there are no partial or fractional pixels. http://digitaldawn1.tripod.com/section9/f9-1.gif

/**


* >>>>> JAVA APPLETS ARE NOT PART OF THE AP SUBSET <<<<<

* But they are pretty cool and worth writing at least one.

*

* Assignment: Create a Java Applet which draws a spiral.



*/

import javax.swing.JApplet;

import java.awt.*; // import Graphics, Graphics2D, and Rectangle

public class Spiral extends JApplet

{

public void paint (Graphics g)



{

g.setColor(Color.black);

/**

* Here is an example of how to draw a line from (300,200) to (400,300)



*

* You will need to replace this code with a while-loop or for-loop

* which draws a spiral. Think about drawing lines which increase in

* length each time you draw a new line.

*/

int x = 300;



int y = 200;

int i = 100;

g.drawLine(x,y,x+i,y+i); //(from x, from y, to x+i, to y+i)

} // end of paint



}

After you finish the basic spiral above try to produce another spiral of you own creation. Below is an example of a triangular spiral. Your spiral does not have to look like the one below. Make up your own!



Yüklə 88,63 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə