0

Look at the Last line of code, that Is where I specifically would like to add my JPanel array to a container. Thanks alot Guys or Gals!

Code:

private JFrame b = new JFrame("Lotus");
private JLabel currentP = new JLabel();
private int currentS;
private Container pieces = new Container();
private JButton exitt = new JButton("EXIT");
private ImageIcon B1=new ImageIcon("C:\\Users\\Brusty\\Downloads\\p1.jpg");  
private ImageIcon B2=new ImageIcon("C:\\Users\\Brusty\\Downloads\\p2.jpg"); 
LinkedList<Stack<Integer>> spotList = new LinkedList<Stack<Integer>>(); 

//Creation of Gamepiece labels
public void Labels(){

JLabel[] labelsP1 = new JLabel[10];
JLabel[] labelsP2 = new JLabel[10];

for(int i = 0 ; i < labelsP1.length ; i++){
    labelsP1[i] = new JLabel(B1); 
    for(int j = 0 ; j < labelsP2.length ; j++){
        labelsP2[j] = new JLabel(B2); 
}
    Container c = b.getContentPane();
    c.setLayout(new GridLayout(13,3)); 
    c.add(pieces); 
    pieces.add(labelsP1);
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
SuperNova
  • 15
  • 4

1 Answers1

1

Not sure I really see your problem. You just need to loop through the labelsP1 array and add the labels...

for (JLabel label : labelsP1) {
    pieces.add(label);
}
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • Ok,Thank you, I don't know exactly why buy calling pieces.add(labelsP1) leads to Eclipse giving me the error:The method add(Component) in the type Container is not applicable for the arguments (JLabel[]). Sorry if this question is a little noobish. – SuperNova Apr 05 '13 at 01:58
  • Basically, you're trying to pass the `add` method an array of components, when it's only expecting a single `Component` object. Lets say `add` expected `Apple` and you tried passing it an `Orange`, obviously, this isn't going to work. The two types of variables are incompatible. However, because the array contains `Component`s, you can pass each element to the `add` method – MadProgrammer Apr 05 '13 at 02:07
  • Awwwh! That makes alot of sense. – SuperNova Apr 05 '13 at 02:13