Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
Like Tree2Likes

Thread: GUI questions google won't answer

  1. #21
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: GUI questions google won't answer

    In order the break the link between controller and GUI (at least from the GUI perspective) you need a listener.
    So:
    Java Code:
    public interface MyGUIListener {
       void loadThingsIDisplay(some search criteria?);
       void getThing(int id);
    }
    These define the sort of interaction the GUI expects to have to do with the (non-GUI) outside world. That would be implemented by the Controller.
    The GUI, which is just a normal class, not extending any JFrame or such, then accepts listeners. In most cases it will be just the one, but I suppose in hefty system you would want to break down the responsibilities a bit to avoid monster classes.

    When the GUI needs a search it will then call loadThingsIDisplay() on its listener. That would be in a SwingWorker thread.

    The Controller then does its work getting the info and hands the List<Things> back to the GUI via, presumably, a displayThings() method.

    In this structure the Controller (at least the parts of the Controller immediately in contact with it) has access to the GUI pretty directly.

    Does that make sense? It is late on a Monday...:)
    Fubarable likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  2. #22
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: GUI questions google won't answer

    Quote Originally Posted by Tolls View Post
    Does that make sense? It is late on a Monday...:)
    Yep that makes perfect sense. As always, thanks!

  3. #23
    ObedMarsh is offline Member
    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0

    Default Re: GUI questions google won't answer

    I appreciate everyones input, so many thanks!
    I ended up with a main program which builds a controller object, nothing more.
    Controller has the gui as a field value and then builds it in it's constructor. It also has inner classes which assigns listeneres to components in the GUI class, using corresponding methods I made in the GUI.
    The controller also stores an arraylist of <abstract superclass> objects, which it can use to list information on accounts in an uneditable text area in the GUI. This proved possible by simply giving the superclass as many field values as possible and simply manipulating extended classes(specific accounts) by "nullifying" those values or making them unobtainable for the particular types.
    The superclass(logical) has statis methods, to fx check if a value user enters in the input fields of the gui, are correct and the right syntax etc. These are used in the controller and in other non static methods. Fx I made a saveAccount() method, which saves all created account objects in a folder called "Accounts/<subfolder for customer>/<account number>.dat", another method searches for a <customer> account files and gets an array of <superclass> objects which is then displayed through the GUI. Overall the setup seems to work, not sure what an experienced programmer would say (probably alot xD ) but I'm satisfied for now.

    It seems to work quite decently anyways.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. What is the Right Answer :
    By sachin218 in forum New To Java
    Replies: 2
    Last Post: 11-04-2012, 03:41 AM
  2. google map
    By karyoker in forum New To Java
    Replies: 2
    Last Post: 07-29-2012, 06:36 AM
  3. Compare true Answer /Player answer
    By Eilime in forum New To Java
    Replies: 1
    Last Post: 04-24-2011, 09:51 PM
  4. Could anyway answer me this?
    By Jojomofoman in forum New To Java
    Replies: 14
    Last Post: 12-17-2010, 12:14 AM
  5. Help me answer a few questions
    By namlunxxx in forum XML
    Replies: 3
    Last Post: 06-16-2010, 06:26 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
  •