+ 3

How I can switch data between two frames in java?

5th Dec 2016, 7:02 PM
martin.s
6 Respostas
+ 6
you mean get value from Jframe to another : frame2 f2 = new frame2(); f2.value2.setText(frame1.value1.getText()); f2.setVisible(true); ps: the values should be "public static"
5th Dec 2016, 7:29 PM
Mohammed Imad-Eddine BOUCENDA
Mohammed Imad-Eddine BOUCENDA - avatar
+ 5
If you don't want to use the public modifier you should use the getter and setter methods to access your variable from another class. For example class MyFrame extends JFrame { private int value = 777; //Some operations ... public void setValue(int v) { value=v; } public int getValue() { return value; } } You can do this with all variables you want. PS: The method of Med Imed-Eddine Boucenda is right, but the static modifier is not necessary in his method.
7th Jan 2017, 11:57 AM
FreakManMega
+ 1
ok Thanks but how can I handle it if I don't want to make the values public ,?
19th Dec 2016, 6:59 PM
martin.s
+ 1
can I handle it about a second class ?
19th Dec 2016, 6:59 PM
martin.s
0
@FreakManMega I do not understand your example
31st Jan 2017, 3:15 PM
martin.s
0
in a Dialog Form I set the variable in the class and when I want to use the variable in my Main Form I have to create a new object of this class and then the variable is null
31st Jan 2017, 3:17 PM
martin.s