Results 1 to 4 of 4
Thread: Initialize JLabel array and fill
- 01-31-2012, 04:54 AM #1
Member
- Join Date
- Jan 2012
- Location
- East Coast
- Posts
- 6
- Rep Power
- 0
Initialize JLabel array and fill
Hey guys,
I am trying to create an array of JLabel objects and fill them with one line of code.
However when I try this it is not seeing it as an array but rather a JLabel object.
Here is my code:
Thanks in advance,Java Code:JLabel JLabel[] = {new JLabel("Label 1"), new JLabel("Label 2"), new JLabel("Label 3"), new JLabel("Label 4")}; symbol : method getLength() location: class javax.swing.JLabel[] for (int i = 0; i < JLabel.getLength(); i++) { ^ 1 error
Nate
- 01-31-2012, 08:32 AM #2
Re: Initialize JLabel array and fill
Follow coding conventions. Variable (and also method) names start with a lowercase letter.
Also, never use an existing class name as an identifier. The compiler is interpreting JLabel as the class name javax.swing.JLabel -- not the array variable you declared with the same name.
And in future, COPY error messages that you need help with. This certainly isn't the error you got.dbJava Code:symbol : method getLength() location: class javax.swing.JLabel[]
edit: Additionally, arrays don't have a getLength() method. They have a length member. You need to go through some tutorials, programming by guesswork is never satisfying.Why do they call it rush hour when nothing moves? - Robin Williams
- 02-01-2012, 03:07 AM #3
Member
- Join Date
- Jan 2012
- Location
- East Coast
- Posts
- 6
- Rep Power
- 0
Re: Initialize JLabel array and fill
Thanks for the response,
I did change my variable name to a more appropriate variable name. As for the error message you were correct again. When I used myvar.length it let me compile. I am confused however; I was referencing Oracle's website (API's) java.util.Array and I found a getLength() modifier. That is why I was trying to use myvar.getLength(); I thought that returned my integer.
My question is: Is there any API that I can see the "array.length" and like attributes?
Thanks again,
Nate
- 02-01-2012, 04:33 AM #4
Re: Initialize JLabel array and fill
Read the specification:Is there any API that I can see the "array.length" and like attributes?
Arrays
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Can't fill the array with the object?
By Clerek in forum New To JavaReplies: 9Last Post: 02-21-2011, 12:31 AM -
How to initialize a two dimensional Array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:48 PM -
How to initialize an Array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:47 PM -
How to initialize array at runtime
By Java Tip in forum Java TipReplies: 0Last Post: 11-09-2007, 03:47 PM -
Initialize array at runtime
By javaplus in forum Java TipReplies: 2Last Post: 11-09-2007, 11:44 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks