sgenoves116
asked on
How to assign and use objects in an array?
I want to create 20 JLabel objects and in my loop, use the setText and setIcon methods to set object(s). What am I doing wrong?
Here's the error I get:
E:\tech\java\gui>javac Button1.java -d .
Button1.java:54: cannot resolve symbol
symbol : class JLable
location: class Button1
lab[i] = new JLable();
^
1 error
Here's a code exerpt:
try {
JLabel[] lab = new JLabel[20];
// instantiate and populate a collections object
Collections colls = vs.collectionsInfo();
//loop through colections object in order to get the individual collection objects (c0)
for (int i=0; i < colls.size(); i++)
{
lab[i] = new JLable(); // LINE 54
Collection c0 = colls.at(i);
String state = c0.getStateMeaning();
if (state.equals ("offline"))
{
lab[i].setText("online coll");
lab[i].setIcon(online);
panel.add(lab[i]);
}
}
} catch (com.verity.k2.K2Exception e){
System.out.print(e);}
Here's the error I get:
E:\tech\java\gui>javac Button1.java -d .
Button1.java:54: cannot resolve symbol
symbol : class JLable
location: class Button1
lab[i] = new JLable();
^
1 error
Here's a code exerpt:
try {
JLabel[] lab = new JLabel[20];
// instantiate and populate a collections object
Collections colls = vs.collectionsInfo();
//loop through colections object in order to get the individual collection objects (c0)
for (int i=0; i < colls.size(); i++)
{
lab[i] = new JLable(); // LINE 54
Collection c0 = colls.at(i);
String state = c0.getStateMeaning();
if (state.equals ("offline"))
{
lab[i].setText("online coll");
lab[i].setIcon(online);
panel.add(lab[i]);
}
}
} catch (com.verity.k2.K2Exception
System.out.print(e);}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.