users@glassfish.java.net

Problem with Java program for images..

From: <glassfish_at_javadesktop.org>
Date: Sun, 05 Aug 2007 16:22:14 PDT

The program has to have three checkboxes, and when you click the first one, image #1 will appear, and so on. But I'm having problems with it. This is what we have so far:

(keep in mind I'm still learning basic Java stuff, so if you see rookie mistakes, be kind )

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);

add (g1);
add (g2); add (g3);
}


public boolean action (Event e, Object o){
if (e.target instanceof Checkbox)
if (g1.getState() == true )
figuraa = getImage(getDocumentBase(), "figura1.jpg");
else if (g2.getState() == true)
figurab = getImage(getDocumentBase(), "figura2.jpg");
else if (g3.getState() == true)
figurac = getImage(getDocumentBase(), "figura3.jpg");


Como hacer un programa en Java para imagenes?
El programa debe ser 3 checkboxes o cuadritos para clikear, que al apretarlo te salga una foto. La que le corresponde a cada cuadro. Hemos tratado y todo nos da error. Esto es lo que tenemos hasta ahora:

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);

add (g1);
add (g2); add (g3);
}


public boolean action (Event e, Object o){
if (e.target instanceof Checkbox)
if (g1.getState() == true )
figuraa = getImage(getDocumentBase(), "figura1.jpg");
else if (g2.getState() == true)
figurab = getImage(getDocumentBase(),

Detalles adicionales

hace 7 minutos
, "figura2.jpg");
else if (g3.getState() == true)
figurac = getImage(getDocumentBase(), "figura3.jpg");


return true;
}
}
[Message sent by forum member 'jcd29' (jcd29)]

http://forums.java.net/jive/thread.jspa?messageID=229529