Drawing program trouble

import java.awt.*;

import javax.swing.*;

import java.applet.*;

publicclass Drawextends Applet

{

Button erase =new Button("erase");

Button blue=new Button("Blue");

Button red=new Button("Red");

Button green=new Button("Green");

Button black=new Button("Black");

Button gray=new Button("Gray");

Button cyan=new Button("Cyan");

Button white=new Button("White");

Button magenta=new Button("Magenta");

DrawPanel canvas;

publicvoid init()

{

canvas =new DrawPanel(getImage(getCodeBase(),"halojesus.jpg"));

BorderLayout bord =new BorderLayout();

setLayout(bord);

add(canvas,"Center");

Panel commandPanel =new Panel();

commandPanel.add(erase);

commandPanel.add(blue);

commandPanel.add(red);

commandPanel.add(green);

commandPanel.add(black);

commandPanel.add(gray);

commandPanel.add(cyan);

commandPanel.add(white);

commandPanel.add(magenta);

add(commandPanel,"South");

}

publicboolean action(Event evt, Object obj)

{

if(evt.target == erase)

{

canvas.numPoints = -1;

canvas.repaint();

}

elseif(evt.target==blue)

screen.setColor(Color.blue));

elseif(evt.target==red)

screen.setColor(Color.red);

elseif(evt.target==green)

screen.setColor(Color.green);

elseif(evt.target==white)

screen.setColor(Color.white);

elseif(evt.target==gray)

screen.setColor(Color.gray);

elseif(evt.target==cyan)

screen.setColor(Color.cyan);

elseif(evt.target==magenta)

screen.setColor(Color.magenta);

elseif(evt.target==black)

screen.setColor(Color.black);

returntrue;

}

}

class DrawPanelextends Panel

{

Image picture;

int[] drawX =newint[1000];

int[] drawY =newint[1000];

int numPoints = -1;

publicvoid paint(Graphics screen)

{

screen.drawImage(picture,0,0,this);

screen.setColor(Color.black);

for(int i = 0;i<= numPoints;i++)

{

screen.fillOval(drawX[i]-3, drawY[i]-3,6,6);

}

}

publicvoid update(Graphics screen)

{

paint(screen);

}

publicboolean mouseDown(Event evt,int x,int y)

{

if(numPoints <1000)

{

numPoints++;

drawX[numPoints] = x;

drawY[numPoints] = y;

}

repaint();

returntrue;

}

publicboolean mouseDrag(Event evt,int x,int y)

{

mouseDown(evt, x, y);

returntrue;

}

DrawPanel(Image inputImage)

{

picture = inputImage;

}

}

The compiling errors I get are these:

Draw.java:44: cannot resolve symbol

symbol : variable screen

location: class Draw

screen.setColor(Color.blue);

^

Draw.java:46: cannot resolve symbol

symbol : variable screen

location: class Draw

screen.setColor(Color.red);

^

Draw.java:48: cannot resolve symbol

symbol : variable screen

location: class Draw

screen.setColor(Color.green);

^

Draw.java:50: cannot resolve symbol

symbol : variable screen

location: class Draw

screen.setColor(Color.white);

^

Draw.java:52: cannot resolve symbol

symbol : variable screen

location: class Draw

screen.setColor(Color.gray);

^

Draw.java:54: cannot resolve symbol

symbol : variable screen

location: class Draw

screen.setColor(Color.cyan);

^

Draw.java:56: cannot resolve symbol

symbol : variable screen

location: class Draw

screen.setColor(Color.magenta);

^

Draw.java:58: cannot resolve symbol

symbol : variable screen

location: class Draw

screen.setColor(Color.black);

^

8 errors

I know the reason for these errors: screen is in DrawPanel and I am trying to use it from Draw. What can I do about it, though? Thanks.

[7317 byte] By [baracudda0006a] at [2007-10-1 14:15:27]
# 1

I'd add a setColor(Color c) method to DrawPanel. DrawPanel can

keep a Color variable, and refer to that when painting. Of course,

this makes all the ovals the same color, which may not be what

you want.

If you intend for each oval to remember it's color,

you're going to have to keep all the colors in the order their

buttons were pressed. In this case, I'd suggest keeping

a collection of objects that know the oval's shape and color. To

paint, just run through that collection.

es5f2000a at 2007-7-10 17:42:25 > top of Java-index,Security,Cryptography...
# 2
ok ill try that
baracudda0006a at 2007-7-10 17:42:25 > top of Java-index,Security,Cryptography...