English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have to make three checkboxes appear, and when I click one, a picture will appear, when I click checkbox 2, figure 2 will appear, and same for #3. Can't get it to work, don't know what I'm doing wrong. This is what I have for now:

import java.awt.*;
import java.applet.*;

public class prueba extends Applet {
Image figuraa; Image figurab; Image figurac;
Checkbox g1, g2, g3; CheckboxGroup g;
public void init(){

figuraa = getImage(getDocumentBase(), "figura1.jpg");
figurab = getImage(getDocumentBase(), "figura2.jpg");
figurac = getImage(getDocumentBase(), "figura3.jpg");
g1 = new Checkbox ("Tylenol", g, false);
g2 = new Checkbox ("Perro", g, false);
g3 = new Checkbox ("Cafe", g, false);
}

public boolean action (Event e, Object o){

if (e.target instanceof Checkbox)
if (g1.getState() == true )
g.drawImage (figuraa,1,1,this);
else if (g2.getState() == true)
g.drawImage (figurab,1,1,this);
else if (g3.getState() == true)

2007-07-24 12:51:01 · 1 answers · asked by jc_duque_h 1 in Computers & Internet Programming & Design

1 answers

The "g" variable you are calling "drawImage()" on is NOT the graphics context, it is your CheckboxGroup! To avoid confusion, change the CheckboxGroup variable name to "group" vice "g", and then in your action() method get the graphics context:

public boolean action(Event e, Object o){

Graphics g = getGraphics();
//rest of code remains same

}

Also note, you took me wayyyy back, using the old (and deprecated) event model from Java 1.0. I recommend using the AWT 1.1 event model (see the tutorials at http://java.sun.com).

2007-07-24 14:01:45 · answer #1 · answered by vincentgl 5 · 0 0

fedest.com, questions and answers