| Lab | Assigned | Design Due (In class) 10 AM |
Implement (In Lab) Wednesday |
Demo (In Lab) Wednesday |
Lab Due (In lab) Wednesday |
|||||
|---|---|---|---|---|---|---|---|---|---|---|
| 28 | Jan | 29 | Jan | 5 | Feb | 5 | Feb | |||
In this part of your lab, you will take your solution from Part A and construct a GUI to support your object's API.
PropertyChangeSupport to
notify interested software components about other components' updates.
kwic.gui. You'll have to make a gui subdirectory
in the kwic directory and put the appropriate
package directive at the top of your class files for the GUI.
The sample solution as provided is much more than you need to do to get credit for this lab. Your GUI must provide reasonable access to the API of KWIC. You need only provide one mechanism for each method. If you provide more, along the lines of the sample solutuion, you can earn extra credit.
JDE->Project->Options->and then under
Compile and Run. From there,
change the CLASSPATH and click on State and then save for future
sessions.
How should Word implement that interface? Three words: delegate, delegate, delegate.
Thus, it may be more reasonable for your GUI to arrange to have the Words sorted. You can do this by implementing the QuickSort described in CS101 . Alterntaively, you could create a TreeSet instance on our GUI side, put the Words into there, and then when you iterate over them they will be sorted.
jf then here's how to create or
recreate it:
jf.getContentPane().removeAll()
The menu bar and its contents are not affected by this method call, and they
will stay the way you set them up when you constructed your JFrame.
jf.getContentPane().add(mainPanel).
jf. validate().
jf.setVisible(true).
j, each of which is an
extension of AbstractButton , this is done as follows (spacing below
to show grouping):
j.addActionListener(
new ActionListener() { // anonymous inner class
// implements ActionListener
public void actionPerformed(ActionEvent e) {
// Do what you want in response to
// this AbstractButton "push"
// Ideally, you should be able to ignore "e"
// because this is the only button associated with
// this anonymous action
}
}
);
c, this can be done as follows:
c.addMouseListener(
new MouseAdapter() { // anonymous inner class
// extends MouseAdapter
public void MouseClicked(MouseEvent e) {
// Do what you want in response to
// this mouse click
// Ideally, you should be able to ignore "e"
// because this is the only button associated with
// this anonymous action
// But look at e if you care which button was
// clicked, how many times, etc
}
}
);
PropertyChangeSupport is like publish/subscribe or subject/observer.
It is conventional for the object that is publishing or changing itself
to own the PropertyChangeSupport object. Our KWIC object has
an accessor to retrieve that object (let's suppose it's the instance var
pcs) .
Then, inside KWIC, when something changes, you can broadcast that fact to all interested parties (in this case, your GUI class), by
pcs.firePropertyChange("Name of Thing", oldvalue, newvalue);
The "Name of Thing" is the name of the property that other parties might
listen for changes. For example, "Word Deleted" or "Phrase Delete". The
other paramters are Object types that could reflect the change in value.
You may or may not need actual values there; if nothing is needed, you
can supply null
If kwicPCS is the instance of the PropertyChangeSupport object,
then your GUI (or other interested parties) advertize
their interest by:
kwicPCS.addPropertyChangeListener(
"Name of Thing",
new PropertyChangeListener() { // anonymous, inner class
// implements PropertyChangeListener
public void propertyChange(PropertyChangeEvent e) {
// Deal with this event how you like
// You can probalby ignore e
}
}
);
kwic.gui package.
To do a screenshot, arrange the screen as you wish and then hit
Print Scrn, which is shift of a button near the top of your
keyboard typically. This copies the image into a buffer. Then, open
the Paint program from Start->Programs->Accessories and paste the image
into Paint's canvas. Then print that canvas as usual.
Be sure to include screenshots of extra-credit features.