2010-01-04 78 views
1

這種方法顯示在我的應用程序中的新窗口:Access的新框架方法

public void ShowNewCustomerView() { 
    if (NewCustomer == null) NewCustomer = new NewCustomerView(this); 
    NewCustomer.setVisible(true); 
} 

類NewCustomerView有這個方法:

public void ClearFields() { 
    txtAddress.setText(""); 
    txtCity.setText(""); 
    txtCompanyName.setText(""); 
    txtCustomerNumber.setText(""); 
    txtOrganisationNumber.setText(""); 
    txtPhoneNumber1.setText(""); 
    txtPhoneNumber2.setText(""); 
    txtPostalCode.setText(""); 
    txtReferenceName.setText(""); 
} 

我怎樣才能前行運行方法:

NewCustomer.setVisible(true); 

添加此:

NewCustomer.ClearFields(); 

...不起作用......這是爲什麼?

這是什麼錯誤,我得到: 找不到符號(方法ClearFields()) 類:javax.swing.JFrame中

但我創建NewCustomerView的新實例延伸的JFrame?對?

+0

它不工作?這些字段中是否有文字內容? – 2010-01-04 14:14:38

+0

更新後的帖子,看看爲什麼以上... – Johan 2010-01-04 14:17:07

+0

對不起,與編輯賽車,想做一個小編輯在你身上 - 所以顯然不檢查併發編輯... – Esko 2010-01-04 14:18:38

回答

1

從你的意見,我想你聲明NewCustomer這樣的:

JFrame NewCustomer; 

如果是這樣,請嘗試聲明:

NewCustomerView NewCustomer; 

public void ShowNewCustomerView() { 
    if (NewCustomer == null) NewCustomer = new NewCustomerView(this); 
    ((NewCustomerView)NewCustomer).ClearFields(); 
    NewCustomer.setVisible(true); 
} 
+0

這工作,我曾宣佈它作爲一個JFrame,謝謝! – Johan 2010-01-04 14:21:58

2

這聽起來像你定義新的框架爲:

JFrame frame = new NewCustomerView(); 

相反,你應該做的:

NewCustomerView frame = NewCustomerView(); 
1

以下錯誤消息的提示,這是怎麼回事:

Cannot find symbol (method ClearFields()) Class: javax.Swing.JFrame 

什麼消息說的是,有到ClearFields方法的調用在JFrame對象上。這很有意義,因爲JFrame對象上沒有ClearFields方法。

這似乎表明NewCustomerView對象被聲明爲JFrame而不是NewCustomerView

我要去猜測其聲明NewCustomer對象是這樣寫的行:

JFrame NewCustomer = new NewCustomerView(); 

那是什麼做的是處理新NewCustomerView對象爲JFrame - 因此,試圖在調用ClearFields方法,其中一個是試圖調用JFrame.ClearFields方法,該方法不存在。

嘗試,而不是下面,讓被聲明爲NewCustomerView對象被處理的對象:

NewCustomerView NewCustomer = new NewCustomerView(); 

另請注意,在Java中,變量名都寫有一個小寫字母,後面以每個字邊界的大寫字母表示,例如,在上例中,NewCustomer將寫爲newCustomer