java - why is .setColor(,,,) saying unable to find symbol in this program? -


when run program code g2.setcolor(fillcolor) has cannot find symbol error. legacy issue? improper code?

i typed code in verbatim page165 of book "big java" cay horstmann

import java.applet.applet; import java.awt.color; import java.awt.graphics; import java.awt.graphics2d; import java.awt.rectangle; import javax.swing.joptionpane;  /**  * applet lets user choose color specifying fractions of   * red, green, , blue.  */     public class colorapplet extends applet     {         public colorapplet()         {             string input;              //ask user red, green, blue values             input = joptionpane.showinputdialog("red: ");             float red = float.parsefloat(input);              input = joptionpane.showinputdialog("green: ");             float green = float.parsefloat(input);              input = joptionpane.showinputdialog("blue :");             float blue = float.parsefloat(input);              //creates color based on rgb inputted values             color fillcolor= new color(red, green, blue);         }          public void paint(graphics g)         {             graphics2d g2= (graphics2d)g;              g2.setcolor(fillcolor);              rectangle square = new rectangle((getwidth() - square_length)/2,              (getheight() - square_length)/2, square_length, square_length);              g2.fill(square);         }          private static final int square_length = 100;     } 

fillcolor not declared in paint method. in program fillcolor has scope in constructor color fillcolor= new color(red, green, blue);

can make instance variable make accessible like:

public class colorapplet extends applet {    color fillcolor;  // in constructor public colorapplet() { ... ...  fillcolor= new color(red, green, blue); } 

now can use fillcolor in paint method


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -