0

查看最后一行代码,这是我特别想将 JPanel 数组添加到容器的地方。非常感谢伙计们或加尔斯!

代码:

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);
4

1 回答 1

1

不知道我真的看到你的问题。您只需要遍历labelsP1数组并添加标签...

for (JLabel label : labelsP1) {
    pieces.add(label);
}
于 2013-04-05T01:55:28.047 回答