2015-04-07 17 views
0

我想製作一個tic tac toe遊戲,我有一個按鈕3 x 3的網格,但是我想在它們上方有一個顯示分數和玩家名稱的酒吧請幫助我對java很陌生,不知道從哪裏開始。Java - 在GridLayout上面定位標籤

import javax.swing.*; 
import java.awt.*; 

public class NoughtsCrosses extends JFrame { 
JPanel gamePanel = new JPanel(); 
JPanel scorePanel = new JPanel(); 
JButton button1 = new JButton(""); 
JButton button2 = new JButton(""); 
JButton button3 = new JButton(""); 
JButton button4 = new JButton(""); 
JButton button5 = new JButton(""); 
JButton button6 = new JButton(""); 
JButton button7 = new JButton(""); 
JButton button8 = new JButton(""); 
JButton button9 = new JButton(""); 
JLabel label = new JLabel("test"); 



public NoughtsCrosses(){ 
    super("Noughts & Crosses"); 
    setSize(400,400); 
    setResizable(false); 
    setDefaultCloseOperation(EXIT_ON_CLOSE); 

    gamePanel.setLayout(new GridLayout(3,3)); 

     gamePanel.add(button1); 
     gamePanel.add(button2); 
     gamePanel.add(button3); 
     gamePanel.add(button4); 
     gamePanel.add(button5); 
     gamePanel.add(button6); 
     gamePanel.add(button7); 
     gamePanel.add(button8); 
     gamePanel.add(button9); 

    add(gamePanel); 
    setVisible(true); 
} 



public static void main(String args[]){ 

    new NoughtsCrosses(); 

} 



} 
+0

這裏沒有任何代碼存在,你正在試圖做的是,Java文檔。你有什麼問題? – ChiefTwoPencils

+0

將單元格面板包裹在使用BorderLayout的另一個面板中,然後可以使用BorderLayout將另一個面板添加到面板的NORTH位置 – MadProgrammer

回答