CS 121 Lecture 36: Drawing With Loops & Conditionals

28 views5 pages

Document Summary

Conditionals & loops greatly enhance our ability to generate interesting graphics: ex: the bullseye program draws a target. The drawing actually occurs in the bullseyepanel class uses an if statement to alternate the colors between black & white. Each ring is actually drawn as a filled circle (an oval of equal width & length). B/c we draw the circles on top of each other, the inner circles cover the inner part of the larger circles, creating a ring effect. At the end, a final red circle is drawn for the bull"s-eye. // creates and displays the program frame. import javax. swing. jframe; public class bullseye public static void main(string[] args) Jframe frame = new jframe(bullseye); frame. getcontentpane(). add(new bullseyepanel()); frame. setdefaultcloseoperation(jframe. exit_on_close); frame. pack(); frame. setvisible(true); import javax. swing. jpanel; import java. awt. public class bullseyepanel extends jpanel { private final int max_width = 300, num_rings = 5, // sets up the bullseye panel. public bullseyepanel () setbackground (color. cyan); setpreferredsize (new dimension(300,300));

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents