我的代码中出现了这个编译错误:
方法 add(UComponent comp, KopiAlignment constraints); 对于 DBlock 类型是模棱两可的...
我想创建 UBlock 接口以对现有类 DBlock 进行抽象
这是代码:
界面 UBlock :
public interface UBlock extends UComponent, BlockListener {
public void add(UComponent comp, KopiAlignment constraints);
}
DBlock 类:
public class DBlock extends JPanel implements UBlock {
public void add(UComponent comp, KopiAlignment constraints) {
}
}
我在另一个类中调用 add 方法:
private DBlock blockView;
blockView.add(displays[i], new KopiAlignment(chartPos + leftOffset, i + 1, 1, false));
当我从 DBlock 中删除 UBlock 的实现时,错误不再存在,这是被调用的方法:
/**
* Adds the specified component to the end of this container.
* Also notifies the layout manager to add the component to
* this container's layout using the specified constraints object.
* This is a convenience method for {@link #addImpl}.
* <p>
* Note: If a component has been added to a container that
* has been displayed, <code>validate</code> must be
* called on that container to display the new component.
* If multiple components are being added, you can improve
* efficiency by calling <code>validate</code> only once,
* after all the components have been added.
*
* @param comp the component to be added
* @param constraints an object expressing
* layout contraints for this component
* @exception NullPointerException if {@code comp} is {@code null}
* @see #addImpl
* @see #validate
* @see javax.swing.JComponent#revalidate()
* @see LayoutManager
* @since JDK1.1
*/
public void add(Component comp, Object constraints) {
addImpl(comp, constraints, -1);
}
那么我该如何解决这个问题呢?