Java Homework... Too many windows (GUI)

1 answer Last reply
More about java homework windows
  1. Look at: public static void main(String[] args)

    Then look at your constructor...
    Then read up on the Java API for JFrame & its setDefaultCloseOperation() method.
    - http://docs.oracle.com/javase/6/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation%28int%29

    Actually that was a really good example.
    - I did not see it on the first two passes, I had to read it three times (I'm executing it in my head, I don't have NetBeans installed atm).

    Every time you make a new object using: new MyList<Integer>();, new MyList<String>();, new MyList();, etc. the constructor is called.

    You have the static constant JFrame.EXIT_ON_CLOSE hard coded in your constructor, instead of accepting a parameter and your class extends JFrame.

    I would suggest overloading your constructor to accept an additional parameter (e.g. int setDefaultCloseOperation), that if set to one of the JFrame.CONSTANTS passes that to the call for the first two static calls.

    Basically, you don't want JFrame.EXIT_ON_CLOSE for all three, and it's hard coded into your non-overloaded constructor.
    - This is easy to fix, as you can migrate the code into a better constructor very easily, and have the constructor with parameter just call it's overloaded self, passing the hard coded JFrame.EXIT_ON_CLOSE for the window that you want to close the app.
Ask a new question

Read More

Programming Integer Java Apps