CS 121 Lecture Notes - Lecture 24: Nicksplat

28 views5 pages

Document Summary

The paintcomponent method accepts a graphics object as a parameter, which represents the graphics context for a component. Graphics are drawn on the panel by making method calls to the panel"s graphics context (the page parameter). // demonstrates the use of graphical objects. import java. swing. import javax. awt. public class splat { // presents a collection of circles. public static void main(string[] args) { Jframe frame = new jframe(splat); frame. setdefaultcloseoperation(jframe. exit_on_close); frame. getcontentpane(). add(new splatpanel()); frame. pack(); frame. setvisible(true): output: This program simply draws a few filled circles. Each circle drawn is represented by its own object. The main method instantiates a splatpanel object & adds it to the frame. private circle circle1, circle2, circle3, circle4, circle5; // draws this panel by requesting that each circle draw itself. public void paintcomponent (graphics page) super. paintcomponent(page); circle1. draw(page); circle2. draw(page); circle3. draw(page); circle4. draw(page); circle5. draw(page); Holds as instance data 5 circle objects, which are instantiated by the constructor. Paintcomponent method draws the panel by calling the draw method of each circle.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions