Results 1 to 5 of 5
  1. #1
    Artemia is offline Member
    Join Date
    May 2015
    Location
    Netherlands
    Posts
    39
    Rep Power
    0

    Default GUI Efficiency Question

    So a while back I made a small program to generate and save passwords because I could never think of good ones.
    it's just a small program but it still has a few windows that you can go through, like a main where you can see the passwords, if you click a button another window opens where you can generate a new one and another button to edit an existing password.
    I made it as an exercise using swing components.

    the way I have it set up now is that each time a new window opens the old one completely closes/terminates and another frame opens, I did it like this because it was more clearly organized in my head like that.
    afterwards I got to thinking though, and here is what I'd like to know...

    is it more efficient, either when writing code or while running the program, to have only 1 frame but adjust and refresh the size and contents of the frame instead of terminating and opening a new frame every time?
    and why or why not?


    it probably doesn't really make a difference either way because it's just a tiny tiny program, but I'd like to know as a reference for if I ever make a super huge program :P

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: GUI Efficiency Question

    Are you aware of CardLayout?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: GUI Efficiency Question

    It all depends on what the application does really. I have also made programs with multiple frames, but rather than completely destroying them I only made existing ones invisible. An example is a level editor for a game; it had a main menu where you can access different tools, for example the editor screen itself. The editor would open in its own frame and the main menu frame would be set to invisible. Closing the editor would make the editor invisible and the main menu visible again. In specific cases I could make it such that both frames would be visible at the same time, if need be.

    A CardLayout can work perfectly fine in many cases. I like them when I make a wizard-type GUI where you go through multiple steps to input data for example.

    if you have a frame with a classic border layout and you want to swap out a specific section of it (say the panel that is in the LINE_END position) then just plain removal, addition and revalidate is really all you need.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    Artemia is offline Member
    Join Date
    May 2015
    Location
    Netherlands
    Posts
    39
    Rep Power
    0

    Default Re: GUI Efficiency Question

    I am aware of the cardlayout but I wanted new windows to pop-up when certain buttons were clicked so I chose not to use it.
    the invisibility thing is a nice idea, though, hadn't thought of it like that.

    though to go back to the original question, you're saying it doesn't really matter which way I do it?
    that it's dependent on what kind of application I'm making and how I want it to function, correct?

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: GUI Efficiency Question

    Of course it matters - the end result needs to work the way you want it to and needs to be user friendly. So test a method you think is good and if it doesn't work, just scrap it and try something else.

    The benefit of high level toolkits such as Swing is that you can get a lot done with little code, so completely scrapping a particular feature and redoing it is not so much time and effort.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. efficiency question
    By stuckonjava in forum New To Java
    Replies: 6
    Last Post: 04-25-2012, 02:55 AM
  2. URLConnection Efficiency
    By Lil_Aziz1 in forum New To Java
    Replies: 22
    Last Post: 08-19-2010, 06:27 PM
  3. Replies: 7
    Last Post: 07-29-2010, 11:25 AM
  4. An Efficiency Question
    By Revenna in forum Java 2D
    Replies: 0
    Last Post: 06-25-2010, 07:22 AM
  5. method efficiency
    By TheWave in forum Advanced Java
    Replies: 0
    Last Post: 02-13-2008, 04:11 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
  •