In this lab you will again finish a partially written Java GUI application that demonstrates the basic functions of a Queue. This project is similar to Lab04 but it implements a Queue class as a linked list rather than a circular array. Many features of the linked list itself are identical to those you encountered in Lab06, where you performed a similar revision of the Stack class. But this time, since you have now acquired some sophistication in these matters, you will be asked to write the complete source file that defines your new Queue class.
Now just in case you have forgotten what a queue does, recall that its rules for insertion and removal of items are as follows:
Again, these rules are sometimes summarized by saying that a queue is a FIFO ("First In, First Out") list. In contrast, a stack is called a LIFO ("Last In, First Out") list.
As usual, the GUI test framework has already been created and tested, and source files for the relevant application classes are provided to you. Your main task is to write a complete source file named Queue.java, which defines both the member data and methods for a Queue that stores its items in a linked list. You will have to make the Queue API (Application Programmer Interface, namely the set of public Queue methods that applications can use) conform exactly to specifications given below. Otherwise, you only need to make sure that your Queue does indeed store its data in a linked list (no arrays allowed this time).
However, for this lab you will be given a complete source file Node.java that represents the individual nodes in the linked list. This is to spare you the labor of implementing the same old Node methods that you needed for Lab06. Incidentally, this source file also includes a fully working paint() method which allows applications to render nodes graphically.
Now this last point just naturally leads up to your final challenge in this lab. This time you will be asked to implement a paint() method for your Queue, which the GUI application can use to render its Queue object in the main window. However, this task should not be too difficult if you make proper use of the paint() method that is already defined for the Node class.
After you have completed the Queue class implementation as described below, you will be able to compile all the files and run the project. For this lab, the paint() method that you will implement for the Queue class must explicitly display it as a linked list. You should recall that this is the way Lab06 rendered a linked-list Stack. Thus for an empty Queue (with no nodes present), you will see only two null links labeled Front and Rear respectively:

After inserting the names "Patricia", "Howard", "Martin", and "Jennifer" in that order, the queue should appear as shown below:

If you now clicked the Remove button to remove the front node ("Patricia"), you should see

The Queue will also be provided with a peek() method that allows an application to determine the frontmost data value without removing it. You should recall that a similar method was introduced for a Stack in Lab06. If you now clicked the Peek button, you should see the following:

Finally, clicking the Print All button generates a console display of the complete queue contents in the NetBeans IDE output window, as shown below:

To enable this last feature, the Queue class will be provided with a printAll() method similar to the one you implemented for the Stack in Lab06.
When you have built this project, you should test it using similar examples to make sure that all your Queue methods are working correctly.
To complete this project, follow the steps listed below:
| QueueDisplayFrame.java | DisplayPanel.java | ControlPanel.java | StatusPanel.java | Node.java |
You have been provided with a complete set of javadoc pages fpr the classes defined in these files. For a quick overview, QueueDisplayFrame is the class that contains the main() method for this project. The only task of main() is to create a toplevel application window, which is itself defined by this class. One special feature of this class is that it includes a single Queue object as part of its member data. The DisplayPanel class represents the central portion of the application window, which will graphically display the current state of the Queue object.
Of course the Node class defines a single node, the basic building block for a linked list. This class is fully implemented and ready to use in this project.
You should now proceed to implement the bodies of the methods listed above, so that they perform the following tasks:
Note: The special case of adding to an empty queue requires care, since in that case both the rear and front pointers will be affected...
Note: The special case of removing the last item from a Queue is also tricky, since both the rear and front pointers must be updated.
You should be able to ge a lot of help implementing this method if you start from the paint() method in the source file Stack.java, which was provided in Lab06 for the linked-list Stack. Basically, this method just sets up a loop that makes each node render itself at the appropriate starting point. (If you consult the Node class documentation or directly examine the paint() method in Node.java, you will find that it returns a Point object that represents the "tip" of its arrow to the next node. This technique makes it easy to render the entire linked list using just a few lines of code.)
If you get bogged down anywhere, it is likely to be in the details of the Front and Rear labels and their associated lines. For this task especially,it will help if you have one branch in your paint() method handle an empty Queue (in which case there will be no chain of nodes at all), and one to handle a nonempty queue. Of course there will be some tasks common to both branches, such as drawing the Front and Rear labels themselves, but most of the code will be different in the two branches. You should develop your code in stages, compiling and testing frequently as you go along. And of course, whenever you think you are at an impasse, get help from your lab instructor.