Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Drawing a flower

1,383 views
Skip to first unread message

Theresa McDonagh

unread,
Sep 22, 1999, 3:00:00 AM9/22/99
to
I am trying to draw a flower as one of my first java projects and cannot
seem to get the hang of it. It would be great to see some examples of code
and how it looks on the screen, just something to orient me so I can get off
the ground before I get further behind in my schoolwork.


Dennis Clarke

unread,
Sep 22, 1999, 3:00:00 AM9/22/99
to

Well ... if you want a simple approach that seems to work relatively well, just
write a program that extends the Applet class and handles the paint method
only. This way you can draw your paint area and throw lines and pixels on there
with reckless abandon. For example :

import java.applet.Applet;
import java.awt.*;

// Plot a simple flower shape on an applet ...
public class flower extends Applet {
public void paint (Graphics page){
float r,g,b;
int x1, y1, x2, y2;

setSize (640,480);
setBackground (Color.black);
// create a subtle color of green ...
Color c = new Color ( (float) 0.0, (float) 0.4, (float) 0.0);
page.setColor (c);

// now draw some sort of subtle grid that we can comment out
later
for ( y2 = 0; y2 < 480; y2 = y2 + 10){
page.drawLine ( 1, y2, 639, y2);
} // end draw horizontal lines

for ( x2 = 0; x2 < 640; x2 = x2 + 10){
page.drawLine ( x2, 1, x2, 479);
} // end draw vertical lines

// Now draw a red border
c = new Color ( (float) 0.6, (float) 0.0, (float) 0.0);
page.setColor (c);
page.drawRect (0,0,639,479);

// draw the flower yourself

page.drawString ("A flower", 10, 440);
} // method paint
} // class flower

You will need some html as well ...

<html>
<head>
<title> A Flower </title>
</head>
<body bgcolor="#000000" text="#C0C0C0">
<center>
Simple graphics flower ...
<br>
<hr>
<br>
<applet code="flower.class" width=640 height=480>
</applet>
</center>
</body>
</html>


If you compile the above with javac -verbose flower.java then you can run

appletviewer flower.html and you should be off to the races ... humble though
they may be ...

Dennis Clarke
dcl...@interlog.com

0 new messages