pButtonarray [x] [row].putClientProperty ("x", new Integer (x));

I'm using a version of java that doesn't have method overloading for putClentProperty
so i have to type new Integer as seen above, and this all works perfectly

now I'm trying to assign a boolean to the array

like so

pButtonarray [x] [row].putClientProperty ("Boolean", new boolean (false));

but i get this error

Invalid ClassType which refers to boolean

What is the correct way to assign a boolean as a client property?

Try new Boolean(false). Notice the capital letter. boolean is a primitive type, while Boolean is an object.

I'm using a version of java that doesn't have method overloading for putClentProperty...

just for the record (many people read these posts) it's not putClientProperty that has changed. Before Java 1.5 you had to convert between int and Integer explicitly (ditto boolean and Boolean etc). From 1.5 Java introduced "auto boxing/unboxing" that identifies many situations (like this one) and automatically converts between int and Integer (etc) when required. This is just one of many significant enhancements to the language in 1.5

@sheppy:
Your post is ringing alarm bells in my head! Can I ask why you are storing a Boolean in client properties? Row/col numbers made sense as the obvious way to identify which button was pressed. But the Boolean implies you are storing state information in the button itself, which sounds like a violation of the good design principle of separating GUI from application logic.

@sheppy:
Your post is ringing alarm bells in my head! Can I ask why you are storing a Boolean in client properties? Row/col numbers made sense as the obvious way to identify which button was pressed. But the Boolean implies you are storing state information in the button itself, which sounds like a violation of the good design principle of separating GUI from application logic.

well, I have to make a grid with 10 random blockes in it, that when you click on one of the 10 random blocks, it turns red, and i just want the program to see if it is one of the red blocks, then it reads true, else false, just a simple program and i think its just fine

and thanks for the Boolean, works perfect now im having problems reading client property,

so i have in action listener

JButton btn = (JButton) e.getSource ();

if (btn.getClientProperty ("red") == true)
            {
            }

but i get this error

The type of the left sub-expression, "java.lang.Object", is not compatible with the type of the right sub-expression, "boolean".

Edited 3 Years Ago by pyTony: fixed formatting

You need to cast the result of the getClientProperty to the appropriate class, eg
(Boolean) getCli....
then, if you are on a version before 1.5, you need to get the boolean value from the Boolean object.

You need to cast the result of the getClientProperty to the appropriate class, eg
(Boolean) getCli....
then, if you are on a version before 1.5, you need to get the boolean value from the Boolean object.

I'm so stuck,

I dont understand both of the things your saying

so I had this

JButton btn = (JButton) e.getSource ();
if (btn.getClientProperty ("red") == true)
{
}

and now from reading your post i changed it to this

Boolean red = (Boolean) e.getSource ();
if (red.getClientProperty ("red") == true)
{
}

and i get this error

No method named "getClientProperty" was found in type "java.lang.Boolean".

You do realize what e.getSource() returns? Read the method description again, because changing it to what you did makes no sense at all.

You do realize what e.getSource() returns? Read the method description again, because changing it to what you did makes no sense at all.

Ok, so I finally figured it out, this is what i did

boolean red = ((Boolean) btn.getClientProperty ("red")).booleanValue ();

thanks alot for all your help, just had to search about casting

This question has already been answered. Start a new discussion instead.