Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an event-driven program Forest . Program should display a Forest that consist of trees, each tree of a random color. Frame size should be

Write an event-driven program Forest . Program should display a Forest that consist of trees, each tree of a random color. Frame size should be 800 by 600 . Use BorderLayout with a button Draw Forest on the bottom of the frame. Program Forest must include a method paintTree that paints a single tree having the color treeColor and located at coordinates x and y . The header of the method should be: public void paintTree (Graphics g, int x, int y, Color treeColor) Each tree should be of a random color . Y coordinate is also calculated randomly. The distance between trees should be defined as a constant between Trees = 50. When you calculate x coordinate try to display all the trees inside the frame. Very important requirement: use a loop/ repetition statement to create the Forest. I have the template here : import java.awt.*; import javax.swing.*; //Add import statement to use events //Add import statement to create random numbers public class Forest extends JFrame implements ActionListener { // Declare the variables and other components you will need for your project public static void main(String[] args) { Forest frame = new Forest(); frame.setSize(750, 850); frame.createGUI(); frame.setVisible(true); } /* The createGUI method is used to instantiate the components you declared above, lay them out in the window, and add any event listeners you may need. For this program you will need to use a BorderLayout.*/ private void createGUI() { setDefaultCloseOperation(EXIT_ON_CLOSE); Container window = getContentPane(); // add the rest of your GUI elements below this line } /*Method that builds a tree with random color, x and y coordinates * This method should build only one tree */ public void paintTree(Graphics g, int x, int y, Color treeColor){ // instructions to draw a tree }//end paintTree //paint the forest public void paint(Graphics g) { super.paint(g); /*add your code here to make method calls to your tree painting method*/ } /*Use this method to make your program react to the button presses */ public void actionPerformed(ActionEvent e) { // statements } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions