[3458] in java-interest
Object argument in action() for checkboxes
daemon@ATHENA.MIT.EDU (Suresh Srinivasan)
Mon Nov 13 19:13:09 1995
Date: Mon, 13 Nov 1995 15:50:31 -0500
From: suresh@thomtech.com (Suresh Srinivasan)
To: java-interest@java.sun.com
Hello:
I'm overriding the action() method in a Frame that has a Panel
with some Checkbox items that are part of a CheckboxGroup
as in:
p = new Panel();
cg = new CheckboxGroup();
mm = new Checkbox("Manual", cg, true);
ma = new Checkbox("Auto", cg, false);
p.add(mm);
p.add(ma);
In the action method for the Frame, I'm trying to detect the
selection of the checkbox items as in:
public boolean action(Event e, Object o) {
System.out.println("Event: " + e + " Object: " + o);
if (e.target instanceof Checkbox &&
("Manual".equals((String)o))) {
// ("Manual".equals(((Checkbox)(e.target)).getLabel()))) {
System.out.println("Manual checkbox selected");
}
}
The Object argument to this method is instantiated to a java.lang.Boolean
set to "true" instead of (as in the button object), the label for
the checkbox, i.e., "Manual". It produces a run time cast exception.
Here's the output of the first print:
Event: java.awt.Event[id=1001,x=118,y=50,target=java.awt.Checkbox[0,20,66x20,label=Auto,state=true],arg=true] Object: true
java.lang.ClassCastException: java.lang.Boolean
...
The second option (commented above) works. I was wondering if this is an
error.
Cheers!
--Suresh
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com