2013-10-04 5 views
0

지금까지 테스트 할 CustFrame 객체를 만들기 위해 CustFrame에 main 메소드를 코딩하려고합니다. 지금까지이 코드를 가지고 있었지만 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 
    } 

}

+1

'고객'을 위해 무엇을 했습니까? –

+0

이것은 바보입니다. 한 줄에 하나의 개체를 만든 다음 개체를 만드는 방법을 모르기 때문에 다음 행을 보았다고 말하는 stackoverflow에 게시 하시겠습니까? 'Customer'를 만든 것과 같은 방식으로'CustFrame'을 만듭니다. – nhgrif

+0

@nhgrif 어쩌면 그는 단지 코드를 가지고있을 것입니다. –

답변

0

Customer cust = new Customer(); 새로운 Customer 객체를 생성 cust 객체 계약자 CustFrame에 전달해야합니다. 그런 다음 이것을 사용하여 CustFrame 개체를 구성합니다. CustFrameCustomer 개체를 사용하는 생성자가 있는지 확인합니다. 따라서 다음과 같이하면 custFrame 객체를 만들 수 있습니다 : CsutFrame custframe = new CustFrame(cust);

+0

비평하기를 기꺼이 돕는 사람들이 아직도 있기를 기쁘게 생각합니다. – luijo

0

당신은

CustFrame custFrame = new CustFrame(cust);