jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes Component Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Component Arrays" Watch "Component Arrays" New topic

Component Arrays

Tetsuo Suzuki

Joined: Feb 21, 2002
Posts: 22
Ran into something a bit strange; if I have a component array it won't allow me to initialize each component outside of the constructor. An example of what I mean:


Is assigning the 'new' keyword here doing something executable that can't be in declaration?
Thanks much,
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Tetsuo,
You are not seeing something a little strange. You are seeing how java works!
An assignment (to any variable) can be done in two ways:
1) Along with declaration:

2) Inside any code block (defined by braces {}):

Java will not let you perform assignments outside code blocks with the exception of number 1 above.
[ March 14, 2002: Message edited by: Manfred Leonhardt ]
Colin Humber

Joined: Nov 05, 2001
Posts: 6
JLabel[] x={new JLabel("Label1"),
new JLabel("label2")};

Sun Certified Programmer for the Java 2 Platform.<br />Sun Certified Programmer for the Java 2 Platform, 1.4.<br />Sun Certified Web Component Developer<br />IBM Certified Specialist VisualAge for Java.<br />IBM Certified Solution Developer (OOAD w/ UML).
I agree. Here's the link: http://aspose.com/file-tools
subject: Component Arrays
It's not a secret anymore!