2013-12-08 63 views
0

我想從另一個JFrame更新JFrame。我有一個基本程序,它有兩個相同的組名,我想知道如何編寫程序,所以如果一個人改變了組名,它會自動改變另一個。如何從java中的另一個JFrame更新JFrame

在此先感謝

第一界面

Public String groupNam; 
private void groupNActionPerformed(java.awt.event.ActionEvent evt) { 
interface2 interface2 = new interface2();          
    groupNam = groupN.getText(); 
interface2.group.equals(groupNam); //interface2 is the class name of the other interface 
} 

第二界面

private void groupNameActionPerformed(java.awt.event.ActionEvent evt) {           
    groupName.getText().equals(groupNam); //calling the public string from interface 1 and placing it in groupName field 
} 

這是我嘗試但沒有奏效。

+0

向我們展示一些描述您嘗試解決方案的相關代碼。 – Tdorno

回答

3

你聽說過觀察者模式嗎?

這對你來說可能是正確的。

+0

[一個教程](http://www.javacodegeeks.com/2013/08/observer-design-pattern-in-java-example-tutorial.html) – Stone

+1

另外,他應該檢查出整個MVC模式。如果他不使用Observer模式與GUI進行通信,他可能也會犯其他錯誤。 (可能不使用控制器等) –