Java正在抱怨!找不到符號= new
cannot find symbol
symbol : constructor Bar()
location: class Bar
JPanel panel = new Bar();
^
問題:爲什麼我得到這個錯誤?......一切似乎都是正確的。
這是編碼:
public class JFrameWithPanel
{
public static void main(String[] args)
{
JPanel panel = new Bar();
}
}
酒吧()是
public class Bar extends JPanel
{
public Bar(final JFrame frame)
{
super(new BorderLayout());
String[] tests = { "A+ Certification", "Network+ Certification", "Security+ Certification", "CIT Full Test Package" };
JComboBox comboBox = new JComboBox(tests);
TextArea text = new TextArea(5, 10);
add(new JLabel("Welcome to the CIT Test Program "));
add(new JLabel("Please select which Test Package from the list below."));
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenu editMenu = new JMenu("Edit");
JMenu helpMenu = new JMenu("Help");
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(helpMenu);
JMenuItem newMenu = new JMenuItem("New (Ctrl+N)");
JMenuItem openMenu = new JMenuItem("Open (Ctrl+O)");
JMenuItem saveMenu = new JMenuItem("Save (Ctrl+S)");
JMenuItem exitMenu = new JMenuItem("Exit (Ctrl+W)");
JMenuItem cutMenu = new JMenuItem("Cut (Ctrl+X)");
JMenuItem copyMenu = new JMenuItem("Copy (Ctrl+C)");
JMenuItem pasteMenu = new JMenuItem("Paste (Ctrl+V)");
JMenuItem infoMenu = new JMenuItem("Help (Ctrl+H)");
fileMenu.add(newMenu);
fileMenu.add(openMenu);
fileMenu.add(saveMenu);
fileMenu.add(exitMenu);
editMenu.add(cutMenu);
editMenu.add(copyMenu);
editMenu.add(pasteMenu);
helpMenu.add(infoMenu);
this.add(comboBox, BorderLayout.NORTH);
this.add(text, BorderLayout.SOUTH);
frame.setJMenuBar(menuBar);
add(new JButton("Select")
{
{
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
JOptionPane.showMessageDialog(frame, "IT WORKS!");
}
});
}
});
}
}
我沒有明白。請解釋 – 2010-06-17 06:54:08
JPanel panel = new Bar(new JFrame()); ......但是你需要更多的東西才能使它工作(雖然這會讓它編譯)。你仍然需要使框架可見等... – TofuBeer 2010-06-17 07:00:06
好吧,工程。現在我將開始添加代碼以使框架可見並設置大小,因爲這個新的Frame()並不完全具有變量名稱 – 2010-06-17 07:11:41