CSC 220 Advanced Programming Techniques
Spring 2004

Homework Hw2 due: Friday April 30, by noon - FIRM!

Place all code in your directory public_html/Swing/Hw2
and make sure the permissions are set so I can read it, on the directory as well as the files in the directory.
To test permissions, go to your page in a browser, www.cs.smith.edu/~220b-xx/Swing/Hw2, and make sure you can click on each file and not get an Access Forbidden message.

Your Swing application will be a JFrame that has a Menu that can generate up to six different JInternalFrames that appear inside the JFrame. One of them opens when the application opens and is different than the other five.
  1. Start by creating a class called Hw1Solution in a file Hw1Solution.java. This class should contain main. Make sure you have this file in your public_html/Swing/Hw1 directory.
  2. You will create a Swing Application that starts out as a JFrame
    1. containing a JDesktopPane with an open JInternalFrame on the JDesktopPane. I'm going to call this MainFrame.
    2. MainFrame is not closable.
    3. MainFrame contains a menu with two options. They are
    4. Large - when selected, MainFrame is increased from size 300,300 to 500,500
    5. Normal - when selected, MainFrame has size 300,300
  3. the JFrame containing the JDesktopPane also contains a menu:
    1. The menu must contain 5 items of your choice.
    2. The sixth item is a "close" item that causes the whole JFrame to close.
    3. When an item (that is not close) is clicked, there are 2 possibilities that you must cover:
      1. the menuitem was never clicked, so a new, closable, JInternalFrame is created and placed on the desktop, with no overlap with MainFrame. Also, it may overlap other JInternalFrames, but not completely.
      2. the menuitem was clicked before. In that case, make sure the corresponding JInternalFrame is visible and is moved to the front of the stack of JInternalFrames. (It may have been closed by the user, but it should still exist. You can set this up by calling setDefaultCloseOperation() and passing it the right argument).
  4. MainFrame, contains
    1. a JList inside a JSrollPane. When you create this JList, use your own class that is an extension of DefaultListModel. This will make your ListModel mutable, meaning items can be added or removed. The JList should be set up so only a single item can be selected at a time.
    2. a JButton, called "Delete Selection". When it is pressed, the item selected in the list is removed. You'll have to use the appropriate listeners for this.
      1. Each of the other JInternalFrames should also contain a JList that are subsets of the big JList. For extra credit, if you are hardcore, when one of the sub-JList items is selected, it is added to MainFrame's JList, only if it is not already there.
      2. Each of the other JInternalFrames contains a menu with two items.
        1. The first one has the same name as the Menuitem that generates the JInternalFrame (from the main menu on the JFrame). When it is clicked, it should print out a message with its name, using to System.out.println(). For extra credit you can get it to do more.
        2. The second menuitem is "close", and when clicked causes the JInternalFrame to close.
    The ListSelection
  5. Helpful java Swing programs:
    1. ListDemo.java
    2. InternalFrameDemo.java
      You will also need its companion file MyInternalFrame.java
    3. ListSelectionDemo.java
    4. lab2 files and Tutorials