Question: Final Product: Description 1. Create a Smiley class a. The class needs to extend JPanel b. The constructor for this class should have 4 parameters.

Final Product:

Final Product: Description 1. Create a Smiley class a. The class needs

Description

1.

Create a Smiley

class

a.

The class needs to extend JPanel

b.

The constructor for this

class should have 4 parameters. Each parameter should

be a color. One for the outline, one for the skin, one for the smile and one for

the eyes.

c.

Use the paintComponent method to draw the sm

iley using the colors from the

constructor

i.

The smiley must be drawn

2.

Create a SmileyGrid class

a.

This class needs to extend JFrame

b.

Use

a GridLayout to divide the frame into a 3 by 3 grid

c.

Use a loop to create an instance of the Smiley class for each square in

the grid,

using random colors for each instance

Code so far:

Grid Code:

import java.awt.*; import java.awt.event.*; import javax.swing.*;

/** * Displays a grid of Smiley objects * * @author * @version 1.0 */ public class SmileyGrid extends JFrame implements ActionListener { public static void main(String[] args) { SmileyGrid myGrid = new SmileyGrid(); myGrid.setSize(800, 800); myGrid.createGUI(); myGrid.setVisible(true); }

public SmileyGrid() {

}

private void createGUI() { setDefaultCloseOperation(EXIT_ON_CLOSE);

} public void actionPerformed(ActionEvent ae) {

} }

Smiley Code:

import java.awt.*; import javax.swing.*;

/** * Draws a single smiley face * * @author * @version 1.0 */ public class Smiley extends JPanel { // Smiley constructor takes parameters for 4 colors that will be used to draw the smiley public Smiley(Color outline, Color face, Color smile, Color eyes) {

} // Use this method to draw the smiley face on the panel public void paintComponent(Graphics g) { super.paintComponent(g); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!