2013-05-08 92 views
0

我在我的程序中有兩種形式,一種是基本的應用程序形式,它顯示應用何時啓動,另一種形式是向數據庫添加實體的形式。它直觀地工作:在默認窗體中單擊add按鈕,第二個窗體顯示,在其中填充一些文本區域並單擊done按鈕。Swing:將數據從JFrame傳遞到另一個

我的問題,如何將數據從第二種形式傳遞給第一種?

+0

參見[多個JFrames,好/壞習慣的用?(http://stackoverflow.com/a/9554657/418556) '表2' 應該是一個模式'JDialog'。這大約每8小時就會出現一次。 – 2013-05-08 11:15:15

回答

1
method 1 : 
1 : create 1 form 
2 : add all fields for entering fields and also the fields from the confirmation form 
3 : hide the confirmation fields 
4 : when user clicks submit , hide the fields of first form , show the fields of second form 

thus you all the data in one form only and you can handle the data as you want 

ohk then lets try this 

create a form 1 
create a form 2 
create a bean class having all the fields from form 1 
now create a simple main class calling form 1 
when user submits the form 1 , take all the values from form1 , create an object of the bean , store the values in the bean object , thus you are still in the main class 
after setting the values in the bean , call the form 2 frame , and set the fields in form 2 by using the same object of the bean class 
+0

是的,這是非常好的方法,但它不是應用程序複雜性的原因 – 2013-05-08 10:22:57

+0

好的,我會嘗試,這將需要我一些時間 – 2013-05-08 10:38:08

+0

@downvoter:謹慎解釋?? – 2013-05-08 11:22:11

相關問題