Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 1 Lnai 6321

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215879X, 978-3642158797

More Books

Students also viewed these Databases questions