0

我正在尝试在 CustFrame 中编写一个 main 方法来创建一个 CustFrame 对象来测试它。到目前为止,我得到了这段代码,但我在 CustFrame 的最后一行代码中存货。

import java.awt.Frame;
import java.awt.Label;

public class CustFrame extends Frame {
    Label custNameLbl = new Label();
    Label shipToLbl1 = new Label();
    Label shipToLbl2 = new Label();
    Label contactInfo = new Label();

    public CustFrame(Customer cust) {
        custNameLbl.setBounds(62, 65, 176, 23);
        shipToLbl1.setBounds(62, 170, 176, 23);
        shipToLbl2.setBounds(62, 175, 176, 23);
        contactInfo.setBounds(62, 230, 176, 23);
        custNameLbl.setText("Test Text");
        shipToLbl1.setText("Test Text");
        shipToLbl2.setText("Test Text");
        contactInfo.setText("Test Text");
        this.add(custNameLbl);
        this.add(shipToLbl1);
        this.add(shipToLbl2);
        this.add(contactInfo);

        this.setSize(300, 282);
        this.setLayout(null);
        this.setVisible(true);
    }
    public static void main(String[] args){
        Customer cust = new Customer();
        CustFrame
    }

}

4

2 回答 2

0

您需要将cust对象传递给CustFrame承包商

CustFrame custFrame = new CustFrame(cust);
于 2013-10-04T02:15:53.393 回答
0

Customer cust = new Customer();创建一个新对象Customer。然后,您将使用它来构造您的CustFrame对象。请注意如何CustFrame有一个接受Customer对象的构造函数。因此,您可以通过这样做来创建一个 custFrame 对象:CsutFrame custframe = new CustFrame(cust);

于 2013-10-04T02:16:56.957 回答