import java.awt.*; import javaTools.*; public class SimplerChoice extends AppletTemplate { Slider vertControl, horizControl; Choice whichPic; public void begin() { whichPic = new Choice(); whichPic.addItem("Face"); whichPic.addItem("Tree"); horizControl = new Slider( 50, 0, 149); vertControl = new Slider( 50, 0, 149); add(horizControl); add(vertControl); add(whichPic); drawPicture(50, 50); } public void choiceMade( String chosen ) { drawPicture(horizControl.getValue(), vertControl.getValue()); } public void scroll( ) { drawPicture(horizControl.getValue(), vertControl.getValue()); } private void drawPicture(int x, int y){ pen.clearRect(); if (whichPic.getSelectedItem() == "Face") { drawSmiley( x, y); } else { drawTree( x, y); } } private void drawSmiley( int x, int y) { pen.frameOval(10+x, 10+y, 60, 60, "Green"); pen.frameOval(22+x, 25+y, 6, 10, "Blue"); pen.frameOval(52+x, 25+y, 6, 10, "Blue"); pen.fillOval(22+x, 30+y, 6, 5, "Blue"); pen.fillOval(52+x, 30+y, 6, 5, "Blue"); pen.fillRect(38+x, 38+y, 4, 4, "Yellow"); pen.frameArc(25+x, 50+y, 30, 10, 180, 180, "Red"); pen.fillArc(40+x, 55+y, 5, 11, 180, 180, "Red"); } void drawTree( int x,int y) { pen.fillRect(x,y,10,75,new Color(64,0,0)); pen.fillOval(x-10,y-35,20,20,new Color(0,127,0)); pen.fillOval(x-20,y-20,50,50,"Green"); pen.fillOval(x+5,y-30,25,60,"Green"); pen.fillOval(x-15,y-15,10,50,"Green"); pen.fillOval(x-25,y-5,20,30,"Green"); pen.fillOval(x-23,y-30,20,30,"Green"); } }