Results 1 to 4 of 4
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,064
    Rep Power
    8

    Default A design problem

    I have the following design problem and do not know how to resolve it:
    -class A contains a couple of JPanels and by clicking on each of them generates a dialog to set the content of that panel;
    -the dialog class B (extends JDialog) has a couple of textfields to set and has a OK (and Chancel) button.

    Of course in class A one finds:
    B b = new B(); and I can get whatever content of the object b (from out A) by, for instance: b.textfield.getText; etc.

    My question:
    how do I find out in class A when the client pushes the OK button of object b (at that very moment want to change the
    content of a particular panel)?

  2. #2
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,064
    Rep Power
    8

    Default Re: A design problem

    Sure class B has a actionlistener for the OK button.....
    if I just could read out that actionlistener (when it fires)
    from within class A......

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,064
    Rep Power
    8

    Default Re: A design problem

    Could this by a way of getting it done:
    -a method of class B build up all of that dialog and returns it as in a return statement.
    -in class A I only add the OK/ CHANCEL buttons to it.....
    would that be weird?

  4. #4
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,064
    Rep Power
    8

    Default Re: A design problem

    So here is what I came up with:
    -I took the two buttons of the panel which the method CreateDialog(rm) at class B
    creates.
    -I wrote a second method (at class A) which expands the previous and added the two buttons
    with its listeners...
    Now I have the OK button available to update the panels at class A!

    That's not considered good programing? But it works!
    Any profesional suggestions are welcome.




    Java Code:
    public JPanel expandsSingleroomDialog(String rm)  {
               JPanel extrapanel = new JPanel();
               extrapanel.add(sroomdialog.CreateDialog(rm));
               
               JPanel buttonpannel = new JPanel();
               JButton okButton = new JButton("OK");
               okButton.setActionCommand("OK");
               JButton chancelButton = new JButton("CHANCEL");
               chancelButton.setActionCommand("CH");
               okButton.addActionListener(blistener);
               chancelButton.addActionListener(blistener);
    
               buttonpannel.add(okButton);
               buttonpannel.add(chancelButton);
               
               extrapanel.add( buttonpannel);
    
               return extrapanel;
          }

Similar Threads

  1. Problem design issue
    By coyne20 in forum New To Java
    Replies: 3
    Last Post: 10-26-2012, 09:11 PM
  2. class design/interaction problem
    By wotupduck in forum New To Java
    Replies: 4
    Last Post: 03-20-2011, 05:54 AM
  3. Design Problem
    By crystalClear in forum Advanced Java
    Replies: 3
    Last Post: 02-09-2011, 12:02 PM
  4. Netbeans 6.8 GUI design problem
    By newbiejava in forum NetBeans
    Replies: 0
    Last Post: 01-14-2010, 02:02 AM
  5. Java Design Problem
    By hencre in forum Advanced Java
    Replies: 2
    Last Post: 02-25-2009, 07:08 AM

Posting Permissions

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