我目前正在编写一个类似于跳棋游戏的程序。我正在尝试使用frame.add();添加实例化面板的方法,它给我一个错误,说容器类型中的方法add(String,Component)不适用于参数(surroundpanel,String)。
我是Java的新手,非常感谢您提供的任何帮助。
由于
public class surround {
private static JFrame frame;
public surround(int size, int start) {
frame = new JFrame("Surround");
surroundpanel panel = new surroundpanel(size, start);
//Error is occurring here when trying to add panel
frame.add(panel, BorderLayout.NORTH);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
}
/******
//Declaring my panel
private JPanel panel;
//Instantiating my panel
panel = new JPanel();
public class surroundpanel {
private JButton[][] board;
private JButton newGame;
private JButton Start;
private JButton Quit;
private surroundgame game;
//private final static in BDSIZE = 10;
private JMenuItem newGameItem;
private JMenuItem quitItem;
private GridLayout gameBoard;
private JPanel panel;
private JPanel butPanel;
private JPanel boardPanel;
//Creating the JMenuItems/Menus/and Menu
private JMenuBar menus;
private JMenu fileMenu;
private Cell [][] gBoard;
/***********************************************************************
*
* The Constructor that generates the GUI
*
*/
public surroundpanel(int size, int start) {
game = new surroundgame(size, start);
boardPanel = new JPanel();
panel = new JPanel();
butPanel = new JPanel();
newGame = new JButton();
Start = new JButton();
Quit = new JButton();
//Assigning the newly created Swing Items values
fileMenu = new JMenu("File");
quitItem = new JMenuItem("Quit");
newGameItem = new JMenuItem("New Game");
menus = new JMenuBar();
gameBoard = new GridLayout(game.getSizeRow(), game.getSizeCol());
boardPanel.setLayout(gameBoard);
ButtonListener listener = new ButtonListener();
Quit.addActionListener(listener);
Start.addActionListener(listener);
newGame.addActionListener(listener);