gpt4 book ai didi

java - 找不到符号 = 新

转载 作者:行者123 更新时间:2023-11-29 08:17:51 26 4
gpt4 key购买 nike

Java 在提示!

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();
}
}

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!");

}
});
}
});

}
}

最佳答案

问题是您有一个需要 JFrame 的构造函数:

public Bar(final JFrame frame)

但你关心的是不带参数地调用它:

JPanel panel = new Bar();

您需要向 Bar 传递一个 JFrame 实例。

关于java - 找不到符号 = 新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3059447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com