Question: Write a Swing component Head that extends JPanel whose method paintComponent draws a simple human head. This doesn't need to look fancy so you can

Write a Swing component Head that extends JPanel whose method paintComponent draws a simple human head. This doesn't need to look fancy so you can just use basic ellipses and rectangles, but of course those who are interested can try out some niftier shapes in java.awt.geom. This component should have one JCheckBox instance labelled Hat. If this checkbox is selected, the head is drawn with a hat on, otherwise the bare head is drawn without a hat. Write an inner ItemListener class to listen to the item events of the checkbox so that whenever the user changes the state of the checkbox, the component is repainted. In the paintComponent method, draw the hat if the checkbox is currently selected, and otherwise, well... just dont draw the hat. Simple as that. (Note that in general, you should never do any drawing in the listener methods. Just call repaint and let the paintComponent method draw the component as it currently looks like.)

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!