查看代碼的最後一行,即我特別想將我的JPanel數組添加到容器的位置。非常感謝Guys或Gals!將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);
可能重複:http://stackoverflow.com/a/2510425/931721 – 2013-04-05 02:13:39