0% found this document useful (0 votes)
1K views

Java Applet Drawing Spiral

The Java program defines a Linespiral class that extends JApplet. The paint method draws a spiral of randomly colored lines starting from the center of the applet outward. It uses a for loop to increment the x and y coordinates of each line segment, creating a spiral pattern. After drawing, it displays the dimensions of the applet.

Uploaded by

yosefmajdalawi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Java Applet Drawing Spiral

The Java program defines a Linespiral class that extends JApplet. The paint method draws a spiral of randomly colored lines starting from the center of the applet outward. It uses a for loop to increment the x and y coordinates of each line segment, creating a spiral pattern. After drawing, it displays the dimensions of the applet.

Uploaded by

yosefmajdalawi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.awt.

*; //required for programs that draw


import javax.swing.*; //required for Swing applets
import java.util.Random;
public class Linespiral extends JApplet {

public void paint(Graphics g) {


super.paint(g);
Random r=new Random();
g.setColor(Color.red);

int k=1,x1=300,y1=300,x2=300,y2=305;

for (int i=1;i<=26;i++)


{g.setColor(new Color(r.nextInt(256),r.nextInt(256),r.nextInt(256)));
g.drawLine(x1,y1,x2,y2);
x1=x2;
y1=y2;
x2=x2-5*k;
k=k+1;
for (int m=1;m<=70000000;m++);
g.setColor(new Color(r.nextInt(256),r.nextInt(256),r.nextInt(256)));
g.drawLine(x1,y1,x2,y2);
x1=x2;
y1=y2;
y2=y2-5*k;
k=k+1;
for (int m=1;m<=70000000;m++);
g.setColor(new Color(r.nextInt(256),r.nextInt(256),r.nextInt(256)));
g.drawLine(x1,y1,x2,y2);
x1=x2;
y1=y2;
x2=x2+5*k;
k=k+1;
for (int m=1;m<=70000000;m++);
g.setColor(new Color(r.nextInt(256),r.nextInt(256),r.nextInt(256)));
g.drawLine(x1,y1,x2,y2);
x1=x2;
y1=y2;
y2=y2+5*k;
k=k+1;
for (int m=1;m<=70000000;m++);

}
Dimension appletSize = super.getSize();
int appletHeight = appletSize.height;
int appletWidth = appletSize.width;

g.drawString("This applet is " + appletHeight +


" pixels high by " + appletWidth + " pixels wide.",
15, appletHeight-10);

}
}

You might also like