Results 1 to 6 of 6
  1. #1
    binaryburnout is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default A GUI implementation question

    Honestly I'm not sure how to phrase this but I will do my best to properly describe my question.

    I want to create a simple application that utilizes a GUI and am unsure on how to go about creating the GUI without making the GUI do all the actual work. I will let the code do the talking for me...
    Java Code:
    public class Foo {
    
       public Foo() {
       // constructor code here
       }
    
       public int addOne(int i) {
          return (i+=1);
       }
    
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                new GUI();
             }
          });
       }
    }
    If inside of the GUI I have a simple button with a listener and instead of making the GUI methods do the arithmetic is it possible to create an instance of Foo that would call addOne without creating a massive memory leak by creating an infinite set of Foo and GUI classes?

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

    Default Re: A GUI implementation question

    Why would Foo and GUI cause a "massive memory leak"? And are you missing the GUI class's code?

  3. #3
    binaryburnout is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: A GUI implementation question

    Well I guess my question is, when I start the application Foo has the main method. Is the main method only called on initiation of the application or on every instance of the Foo class? Come to think of it I guess there is no reason to create a memory leak unless inside the constructor of Foo I created a new implementation of GUI and the same inside the GUI class constructor.

    I didn't feel it was necessary to code out a GUI file for this question but if it would help to get an accurate answer I can post a simple example.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default Re: A GUI implementation question

    Quote Originally Posted by binaryburnout View Post
    Is the main method only called on initiation of the application or on every instance of the Foo class?
    Why don't you throw in a print statement to find out? Or better yet, step through the program with a debugger to figure out what it's doing.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    binaryburnout is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: A GUI implementation question

    That would only be to logical. Any IDE with a debugger that you recommend? I am currently just using a text editor and a console to program/compile/run my Java code.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default Re: A GUI implementation question

    Quote Originally Posted by binaryburnout View Post
    That would only be to logical. Any IDE with a debugger that you recommend? I am currently just using a text editor and a console to program/compile/run my Java code.
    Well, for these purposes, simple print lines will do the trick. I'm actually a huge supporter of using a basic text editor and the console to compile and run.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Queue Implementation
    By Ryanmc56 in forum New To Java
    Replies: 4
    Last Post: 08-01-2011, 06:12 PM
  2. AI implementation
    By vxaviern in forum Advanced Java
    Replies: 2
    Last Post: 11-18-2010, 09:02 AM
  3. Question on Multiple Listeners implementation
    By StormyWaters in forum AWT / Swing
    Replies: 14
    Last Post: 06-11-2010, 08:28 PM
  4. Question about linked implementation
    By bdario1 in forum New To Java
    Replies: 5
    Last Post: 04-23-2010, 11:00 AM
  5. array-based implementation question
    By intelli in forum New To Java
    Replies: 1
    Last Post: 04-18-2009, 05:18 PM

Tags for this Thread

Posting Permissions

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