Trees will come on screen
//////////////////////////////////////////////
// //
// Trees.java - Displays a grove of trees //
// //
// Created by Divya H Jain //
// //
//////////////////////////////////////////////
import java.awt.*; //Include the appropriate
import java.applet.*; //Library functions
//Public class Trees. Inherits from object Applet.
//This Applet can be easily used in web pages.
public class Trees extends Applet {
/*-------------------------------------------\
| Method drawtree. |
|--------------------------------------------|
| This method is called to draw one tree to |
| the screen at a specific coordinate on the |
| screen. |
\-------------------------------------------*/
private void drawtree(Graphics g, int x, int y) {
//Set brown as the active color
Color Brown = new Color(162, 42, 42);
g.setColor(Brown);
//Draw the tree trunk
g.fillRect(x, y-100, 10, 100);
//Set green as the active color
Color TreeGreen = new Color(0, 200, 0);
g.setColor(TreeGreen);
//Draw the leaves on the tree with an oval
g.fillOval(x-50+5, y-50-100, 100, 100);
//Put a black border on the tree leaves to improve contrast.
g.setColor(Color.black);
g.drawOval(x-50+5, y-50-100, 100, 100);
}
/*-------------------------------------------\
| Method paint. |
|--------------------------------------------|
| This method called to redraw the screen. |
\-------------------------------------------*/
public void paint (Graphics g) {
//Set the background to be a grass color
Color DarkGreen = new Color(0, 128, 0);
setBackground(DarkGreen);
//Draw a grove of trees
drawtree(g, 200, 150);
drawtree(g, 300, 200);
drawtree(g, 90, 290);
drawtree(g, 300, 305);
drawtree(g, 140, 340);
// Draw a label and put a box around it.
g.setColor(Color.black);
g.drawString("A grove of trees", 100, 395);
g.drawRect(98, 385, 100, 12);
}
}
0 comments:
Post a Comment