当 Netbeans 扩展 JPanel 时,在引用自动生成类的实例时是否会产生问题,因为它使用继承而不是组合?
因为 Netbeans 将 JPanel 声明为private javax.swing.JPanel overview;
实例然后具有 JPanel 类型,所以它应该具有概览类型。
如何调用 setGroup 方法,同时将 Overview 保留为自动生成的 JPanel?我这样尝试:
主.java
private void groupsPropertyChange(java.beans.PropertyChangeEvent evt) {
String s = evt.getNewValue().toString();
LOG.fine("new group: " + s);
overview.setGroup(s);
}
使用 Overview.java:
public class Overview extends javax.swing.JPanel {
...
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
}
但得到这个编译错误:
init:
Deleting: /home/thufir/NetBeansProjects/SwingNNTP/build/built-jar.properties
deps-jar:
Updating property file: /home/thufir/NetBeansProjects/SwingNNTP/build/built-jar.properties
Compiling 1 source file to /home/thufir/NetBeansProjects/SwingNNTP/build/classes
warning: [options] bootstrap class path not set in conjunction with -source 1.5
/home/thufir/NetBeansProjects/SwingNNTP/src/net/bounceme/dur/nntp/view/Main.java:59: error: cannot find symbol
overview.setGroup(s);
symbol: method setGroup(String)
location: variable overview of type JPanel
1 error
1 warning
/home/thufir/NetBeansProjects/SwingNNTP/nbproject/build-impl.xml:628: The following error occurred while executing this line:
/home/thufir/NetBeansProjects/SwingNNTP/nbproject/build-impl.xml:285: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 1 second)