Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions/Design Create an application (NO credit given for an applet) named MagazineView . We will be adding a graphical front-end (and making some modifications/additions) to

Instructions/Design

Create an application (NO credit given for an applet) named MagazineView. We will be adding a graphical front-end (and making some modifications/additions) to the non-GUI MagazineRackapplication presented in Chapter 12. MagazineView.java will have the standard GUI main() method we have seen in all our previous examples.

Here are the additions you will make to Chapter 12s MagazineList class:

1) Add an insert operation into the MagazineList class. Your insert() method will insert each magazine at the beginning of the list (this is a head insert).

Note: The add() method already included in MagazineList (Chapter 12) adds magazines to the END of the list (the tail of the list). This method will not change.

 MagazineList.java public class MagazineList { private MagazineNode list; //---------------------------------------------------------------- // Sets up an initially empty list of magazines. //---------------------------------------------------------------- public MagazineList() { list = null; } //---------------------------------------------------------------- // Sets up a list of magazine nodes, starting with magnode //---------------------------------------------------------------- public MagazineList(MagazineNode magnode) { list = magnode; } public MagazineList(String [] s) { for(int i=0;i 

here is what I got so far

class MagazineList { private MagazineNode list;

// ---------------------------------------------------------------- // Sets up an initially empty list of magazines. // ---------------------------------------------------------------- public MagazineList() { list = null; }

// ---------------------------------------------------------------- // Creates a new MagazineNode object and adds it to the // front of the linked list. // ---------------------------------------------------------------- public void add(MagazineList mag) { MagazineNode node = new MagazineNode(mag); MagazineNode current = list; if (current == null) { // add new node to head of list because there is no list list = node; list.next = current; } else { node.next = current; list = node; } } // ---------------------------------------------------------------- // Creates a new MagazineNode object and adds it in sorted // sorted order in the linked list. // ---------------------------------------------------------------- public void addSorted(MagazineList mag) { MagazineNode node = new MagazineNode(mag); MagazineNode current = list;

if (current == null || current.magazine.toString().compareToIgnoreCase(mag.toString()) >= 0) { // add new node to head of list: list = node; list.next = current; } else { // loop while not end of list and current is earlier in alphabet while (current.next != null && current.next.magazine.toString().compareToIgnoreCase(mag.toString()) < 0) { current = current.next; }

// we found the place to insert in alphabetic order: after current. node.next = current.next; current.next = node; } }

// ---------------------------------------------------------------- // Returns this list of magazines as a string. // ---------------------------------------------------------------- public String toString() { String result = "";

MagazineNode current = list;

while (current != null) { result += current.magazine + " "; current = current.next; }

return result; }

private class MagazineNode { public MagazineList magazine; public MagazineNode next;

// -------------------------------------------------------------- // Sets up the node // -------------------------------------------------------------- public MagazineNode(MagazineList mag) { magazine = mag; next = null; } } }

) Add a deleteAll() method that will delete all magazines from the list.

Hint: If the pointer to the beginning (head) of the list is null, the list is empty. This method only needs to be one line long.

Here are the specifications for the new MagazineViewPanel class:

Note: As we are not using any of the draw() methods, no need for paintComponent() to be defined.

3) The only line from the original MagazineRack class that you will use as is is the one that instantiates the MagazineList (named rack):

MagazineList rack = new MagazineList();

If anyone can get me a working code I would really appreciate it since it is due tomorrow and Chegg is my last resort to get this assignment done.

4) Provide an editable field of type TextField where a user can Insert Magazine; that is, enter a magazine title to be added to the magazine list (use the getText() method to get user input).

Hint: The getText() method of the TextField class returns a String. It is this String that will be used as an argument to insert() a new title into the list (in the same way that the add() method takes aString as its argument). You must call insert() for this assignment.

Note: In Chapter 12s MagazineRack code, all the magazine titles were hardcoded strings. In ourMagazineView application, the titles will be strings that were input from the user using a TextFieldand then stored in a variable. Remember the TextField 'fires' an event when the user hits the key.

5) Allow the user to display all the magazines in a TextArea by pressing a List Magazines Button. BothTextField and TextArea objects use the method setText() to show text in their fields.

Hint: The MagazineList class contains a toString() method that returns a String. The setText() method of the TextArea class takes a String as its argument.

Note: setting the TextArea to empty string "" essentially clears the TextArea object.

6) Allow the user to clear (set to null) the contents of the magazine list by pressing a Delete All Button.This is where you call the deleteAll() method.

Hint: Setting the reference to the first node to null will cause all the nodes in the list to be garbage collected.

7) FOR THOSE DOING EXTRA CREDIT: Program should not delete an already empty list. If user tries to clear an already empty list do nothing (use an if statement).

Here are some additional design thoughts:

8) You will need separate inner (listener) classes for all TextFields and Buttons you use. You DO NOT need a listener for the TextArea as it does NOT generate user input. These listeners are part of theMagazineViewPanel file. It is within these listener/inner classes that 'rack' (the MagazineList object) will call the insert, deleteAll, etc. methods.

9) Hint: I used the BorderLayout for my front-end design. I created a JPanel to which I added a JLabel, TextField and a JButton. I then added the this panel to the North region. I created another JPanel/JLabel/TextField/JButton that I added to South region. I added the TextArea to the Center region. See Chapter 6 for layout manager examples.

10) You must separate your implementation so that the Magazine and MagazineList classes are in separate file(s) from the MagazineView and MagazineViewPanel files that you use to implement your program.

Extra Credit:

Provide a Delete Magazine TextField where a user can enter a Magazine to be deleted from the Magazine list. The program will search for that magazine title and remove it from the list. Put this code into a method named delete() and add the method to the MagazineList class.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions