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.
- 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.
- You will create a Swing Application that starts out as a JFrame
- containing a JDesktopPane with
an open JInternalFrame on the JDesktopPane. I'm going to call this MainFrame.
- MainFrame is not closable.
- MainFrame contains a menu with two options.
They are
- Large - when selected, MainFrame is increased from size 300,300 to 500,500
- Normal - when selected, MainFrame has size 300,300
- the JFrame containing the JDesktopPane also contains a menu:
- The menu must contain 5 items of your choice.
- The sixth item is a "close" item that causes the whole JFrame to close.
- When an item (that is not close) is clicked, there are 2 possibilities that you must cover:
- 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.
- 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).
-
MainFrame, contains
- 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.
- 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.
- 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.
- Each of the other JInternalFrames contains a menu with two items.
- 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.
- The second menuitem is "close", and when clicked causes the JInternalFrame to close.
The ListSelection
- Helpful java Swing programs:
- ListDemo.java
- InternalFrameDemo.java
You will also need its companion file MyInternalFrame.java
- ListSelectionDemo.java
- lab2 files and Tutorials