Results 1 to 11 of 11
  1. #1
    Grom is offline Member
    Join Date
    Aug 2008
    Posts
    20
    Rep Power
    0

    Default passing variables to another frame

    Hello Java Forums,

    I am making 'calculator' of a sort, and there is need for editing data.
    For that purpose I want to create a new small window, which sets itself visible when I click my edit button.

    2nd; I need smaller window to be focused, while the main window should be NOT focusable. Only when small window is 'disposed off' the main window gets focused back.

    First; how do I pass variables (String and doubles) to small form, and than retrieve new/or-not-new variables back to main form?

    Sorry for miscount, kind regards, Grom

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    I am sorry ,but nobody here is going to do all the work for you,everybody here are the people who only come to help and not work for somebody.Please provide the code where you are stuck in.Thanks

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    do I pass variables (String and doubles) to small form, and than retrieve new/or-not-new variables back to main form?
    That can be done by calling a method that returns a value.

  4. #4
    Grom is offline Member
    Join Date
    Aug 2008
    Posts
    20
    Rep Power
    0

    Default

    Hello Serjant,

    off topics:
    Ukraina, ha? Hello brother Slovan! I am from Slovenia

    on topics:
    Uh, huh, I never meant for others to write a code for me, I 'expected' example, yes, and than I have to do my coding. Anyway, here is what i have:

    So I have main frame and EditFrame. I open EditFrame from main frame with click on the button action:
    Java Code:
    EditFrame ef = new EditFrame();
    EditFrame.setVisible(true);
    On EditFrame I pre-created two variables, String and double:
    Java Code:
       //1    
         private String _name;
        public void SetEditingName(String name) {
            _name= name;
        }
        
        public String GetEditingName() {
            return _name;
        }
        
        
        //2    
            private double _number;
        public void SetEditingWieght(double number) {
            _number= number;
        }
        
        public double GetEditingWeight() {
            return _number;
        }
    so I can set those two variables from main frame. I send over to EditFrame string and double, from click on the action button on the main frame:
    Java Code:
    EditFrame ef = new EditFrame();
    ef.SetEditingName("myName");
    ef.SetEditingWieght(100);
    EditFrame.setVisible(true);
    On Edit Frame I have a button with action, that sets new value of variables:
    Java Code:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
             SetEditingName("Java");
             SetEditingWieght(101);     
    }

    Now, how do I call/get in main frame edited variables, which should be Java, 101, instead of MyName, 100?


    If I am not understandable, I can elaborate more.

    Kind regards, Grom

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    To call/get variables in another class (not all classes are Frames), you need to have a reference to that class object.
    One way to pass a reference is via a Constructor.
    Another is via a set.... method.

    Could you write a small program and post it here with println()s to show what is happening and what you would like to happen. Copy the output from the program and add your comments on where you'd like the results to be different.
    Last edited by Norm; 11-07-2008 at 04:08 PM.

  6. #6
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Hi,brother from Slovenia.
    Everybody here is brother,i live in Ukraine,8 years i lived in Israel and served 3 years in Israeli army,but it doesn't matter.Everybody is brother here.
    So,Grom,in EditFrame you have

    Java Code:
        //2    
            private double _number;
        public void SetEditingWieght(double number) {
            _number= number;
        }
    So paramter you should be also initialized in double so it should be 100.0
    Java Code:
    EditFrame ef = new EditFrame();
    ef.SetEditingName("myName");
    ef.SetEditingWieght(100.0);
    EditFrame.setVisible(true);
    Will be much obliged to you if you post all the output error and provide all your code,please,wanna see how you declared your variables.

  7. #7
    Grom is offline Member
    Join Date
    Aug 2008
    Posts
    20
    Rep Power
    0

    Default

    Hello brothers! Do we have sisters as well?

    ok, I am new to Java and this forum, but it seems, statistically, that my every post is not substantial. So, here goes another shoot at my goal:

    (Am I allowed to post links yet? No? O, ok)
    At this link (MyWebPage) ht tp: //www .beezgetz .com/Tour.aspx
    are five videos of myProgram made in C#.

    On third video (Truss Calculator) at 1 minute and 28 seconds, Edit Button is being clicked. Selected load (string, doubles) are send to smaller window. The load is changed, and sent back to main frame/window.

    On fourth video (Grid calculator) at 1 minute 33 seconds is same thing.

    It is this very program that I am trying to 'translate' to Java

    So,
    2nd; I need smaller window to be focused, while the main window should be NOT focusable. Only when small window is 'disposed off' the main window gets focused back.

    First; how do I pass variables (String and doubles) to small form, and than retrieve new/or-not-new variables back to main form?
    Am I now making sense?

    I am not getting any errors. Here is code from main frame Edit Button:
    Java Code:
     ClassGrid Gr = new ClassGrid();
     List<GridLoad> loadList = new ArrayList<GridLoad>();
     private DefaultListModel ListIzpis;
    
    
    private void EditLoadButActionPerformed(java.awt.event.ActionEvent evt) {                                            
    // TODO add your handling code here:
       
        
        if (jList1.getSelectedIndex() == -1) {
            
            statusMessageLabel.setText("Select Load if -1"); 
        }
        else {
             try {
                int i = jList1.getSelectedIndex();
                
                String name = loadList.get(i).GetLoadName();
                double weight = loadList.get(i).GetWeight();
                //
                EditGridLoadFrame EGLF = new EditGridLoadFrame();
                EGLF.SetEditingName(name);
                EGLF.SetEditingWieght(weight);
                
                EGLF.setVisible(true);//**************
                
            //    String s = EGLF.GetEditingName();
            //   double d = EGLF.GetEditingWeight();
                //************
    //            loadList.get(i).SetLoadName(EGLF.GetEditingName());
    //            loadList.get(i).SetWeight(EGLF.GetEditingWeight());
    //            loadList.set(i, );
                
    //            EGLF.dispose();
                ListIzpisBremen(); //populate jList1 with loads
        }
        catch (Exception e) {
            statusMessageLabel.setText("Select Load catch");        
        }
        }
        
    }  
    
    private void ListIzpisBremen() {
        
        jList1.removeAll();    
        ListIzpis = new DefaultListModel();
        int i = loadList.size();
        
        for (int r = 0; r < i; r++) {
            String st = loadList.get(r).GetLoadName();  
            double h = loadList.get(r).GetWeight();
            double x = loadList.get(r).GetLoadDistX();
            double y = loadList.get(r).GetLoadDistY();
            ListIzpis.addElement(st + ", kg: " + String.valueOf(h) 
                    + ", X: " + String.valueOf(x) + "  Y: " + String.valueOf(y));        
            
        }    
        
        jList1.setModel(ListIzpis);
        jList1.validate();
    }
    I don't know which part of code you want me to post. I could post link to project, so you can download the whole deal. (440 KB zipped).


    Thanks for bearing with me. Regards, Grom

  8. #8
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    I didn't notice sisters here,lol

    Ok,now it is more clear,add to the EditFrame method which will return the needed data for you,as i understood you want to make some calculations also with data which is passed from the main frame,so for example you have MainFrame class and there you have initialized variable called int i=10,and you want to use it in EditFrame so your method should have MainFrame paramter:

    Java Code:
    class EditFrame extends JFrame{
    .............................
    .............................
    public int makeCalc(MainFrame f){
         int result =f.i;
         return result;
    }
    Last edited by serjant; 11-08-2008 at 11:26 AM.

  9. #9
    Grom is offline Member
    Join Date
    Aug 2008
    Posts
    20
    Rep Power
    0

    Default

    Hello guys,


    Well, we were way off, here is what I needed:
    ht tp://ja va.sun.com/docs/books/tut orial/uiswing/components/dialog.html

    Thanks for your time! Grom

  10. #10
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Ah,so,then you shouldn't create another class for calling JOptionPane

  11. #11
    Grom is offline Member
    Join Date
    Aug 2008
    Posts
    20
    Rep Power
    0

    Default

    Ola, yes, you are right, I don't need class. It turns out to be quite simple:
    Java Code:
    String s = JOptionPane.showInputDialog(mainPanel, "Replace " + name) ;
                
                if ((s != null) && (s.length() > 0)) {
                            loadList.get(i).SetWeight(Double.valueOf(s)); // I change variable                        
                            return;
                        }
    Thanks again for bearing with me.
    Regards, Grom

Similar Threads

  1. Getting internal frame out
    By rad in forum New To Java
    Replies: 8
    Last Post: 08-11-2008, 02:33 AM
  2. Frame to other Frame
    By Aswq in forum New To Java
    Replies: 2
    Last Post: 07-19-2008, 04:27 PM
  3. close a frame..
    By tajinvillage in forum New To Java
    Replies: 5
    Last Post: 04-27-2008, 10:22 PM
  4. Replies: 0
    Last Post: 11-10-2007, 04:47 PM
  5. Frame Query
    By Daniel in forum AWT / Swing
    Replies: 1
    Last Post: 07-05-2007, 06:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •