Hi!

I need to know how to make global object from a local place like a function.
And of course, they need to have unique names each time the function is run
Could I somehow pass the a String parameter of the function to the name of the new object?

Thnx :)

For something like this you would need a global map object that maps names with data, so your function could create the new object and add it with its name to the map which is the real global container of these objects. Then, create a function that allows you to do lookups by passing the name, getting the object back in return. You might want to implement this as a class, with accessor, destructor, and other such functions, so the global object would be an instance of this class.

Now, I can up with a simpler way of doing what I need, and that is create the objects, then copy them into an array. Then, when I need the new member, I'll copy the old array into the new one- but with one new member.

However, I cannot create a JButton array (my syntax is JButton[] buttons=new JButton()[2]; ) because apparently the syntax used for any other data type is not right for the JButton (the error message is: The type of the expression must be an array type but it resolved to JButton. My thought was that the JButton cannot create arrays, but I see no reason not to...)

Do you have any other way to do what I need (the map idea was very confusing)

The problem with the code you posted is the () after JButton. Remove them and it should compile.

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