pass Value from class to JFrame

Posted by MYE on Stack Overflow See other posts from Stack Overflow or by MYE
Published on 2011-01-07T06:23:39Z Indexed on 2011/01/07 10:53 UTC
Read the original article Hit count: 167

Filed under:
|

Hello everybody!

i have problem between pass value from Class to another JFrame

my code write follow MVC Model. Therefore i have 1 class is controller , one jframe is view and 1 class is model.

i have some handle process on controller to get value on it and i want this value to jframe but not pass by constructor . How can i pass value from class to jframe and when value be pass jframe will use it to handle.

Ex:

public class A{
private String str;
           public A(){

          }

           public void handle(){
               ViewFrame v = new ViewFrame();
               v.setVisible(true);
               v.pack().
               v.setSize(330,600);
               str = "Hello World";   //init value here
               v.getString(str);// pass value to jframe here.
           }
}

=======================

public class ViewFrame extends JFrame{
private String str;
      public ViewFrame (){
        System.out.println(str);
      }

     public String getString(String str){
        return  this.str = str;

     }


}

but it return null??

© Stack Overflow or respective owner

Related posts about java

Related posts about swing