Swing:将数据从JFrame传递到另一个

时间:2013-05-08 10:18:20

标签: java swing jframe

我的程序中有两个表单,一个是基本的应用程序表单,它显示应用程序何时启动,第二个是用于向数据库添加实体的表单。它直观地工作:在默认表单中,您单击add按钮,第二个表单显示,您填写一些文本区域并单击done按钮。

我的问题,如何将数据从第二种形式传递到第一种形式?

1 个答案:

答案 0 :(得分: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