我敢肯定我錯過了一些明顯的東西,但我對Java相當陌生。java需要一個子對象來更改父項中的數據
無論如何,我需要該子對象來更新父項中的變量以顯示進度信息。
package XXX
{
class aaa
{
//has Main()
//instantiates an instance of bbb and runs it.
bbb myForm = new bbb();
myForm.setVisible(true);
}
class bbb
{
public JTextField jProgressField = new JTextField();
//builds a form with buttons that also shows jProgressField.
//when you push the "go" button, it instantiates CCC object and tells it to do stuff
ccc doStuff = new ccc();
doStuff.goAndConquer();
}
class ccc
{
protected goAndConquery()
{
//blah blah blah
//processes a file
//needs to update ccc with progress information that will still be there to be read when ccc.goAndConquer ends and goes out of scope
}
}
}
全部包裝。
三個文件中的三個類。
代碼工作和東西發生......但是...我需要在處理髮生時(進度條和正在運行的日誌)用ccc中的數據更新表單(bbb的一個實例)。 如何發送數據流回「父」或調用實例/對象?
從本質上說,在CCC,我要做到這一點(多次,因爲它貫穿正在處理的文件)
myParentWhoCreatedMeAndCalledMe.jProgressField = myParentWhoCreatedMeAndCalledMe.jProgressField + "next line of status information";
請給我們提供完整的代碼。它不可讀。 – Piotrowy
我同意@Piotrowy,有點 - 我想看你的[mcve],而不是你的「完整的代碼」。如果您遇到嚴重的問題並需要認真的幫助,請發佈嚴重的**真實**代碼,而不是種類不同的代碼。拍攝時,你的代碼甚至不顯示繼承,而你的問題使得它看起來像你甚至可能會誤用繼承。 –
我可能會濫用繼承。我不知道。 –