gpt4 book ai didi

Java Class子类变量引用

转载 作者:行者123 更新时间:2023-11-30 06:36:31 25 4
gpt4 key购买 nike

我一直在类里面遇到“找不到符号”错误。父类(super class)明明声明了变量,子类却看不到。除了子类 RecordViewerJLabel 的新构造函数外,我没有收到任何错误。

 class RecordViewer extends JDialog{
private JButton next;
private JButton prev;
private JLabel label;
private int current;

public RecordViewer(CDinventoryItem [] array){
super();
current = 0;
final CDinventoryItem [] items = array;

label = new JLabel(items[getCurrent()]);

从我的 CDinventoryItem 类预定义 toString...

        @Override public String toString(){

// Decimal foramting for the inventory values
NumberFormat dformat = new DecimalFormat("#0.00");

// Formatting for the inventory output
StringBuilder ouput = new StringBuilder();
String New_Line = System.getProperty("line.separator");

ouput.append("The product number of my CD is: ").append(iPitemNumber).append (New_Line);
ouput.append("The title of the CD is: ").append(sPtitle).append (New_Line);
ouput.append("I have ").append(iPnumberofUnits).append(" units in stock.").append (New_Line);
ouput.append("The total value of my inventory on this product is: ").append(dformat.format(stockValue())).append (New_Line);
return ouput.toString();
}

最佳答案

这是标准的 Java JLabel 吗?您正在尝试传递 CDinventoryItem 类型的对象,而 JLabel 将没有构造函数来处理这种参数,除非它正在扩展 String 或 Icon 类。

关于Java Class子类变量引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4786846/

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