查看最后一行代码,我特意想将我的JPanel数组添加到容器中。非常感谢Guys或Gals!
代码:
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);
答案 0 :(得分:1)
不确定我是否真的看到了您的问题。您只需循环遍历labelsP1
数组并添加标签...
for (JLabel label : labelsP1) {
pieces.add(label);
}