In a single source file named App.java, define a public class named App that can be run as either a multithreaded Windows server or as a Windows client to process a telephone directory. Two other non-public classes must also be defined. One, named Person, will encapsulate the data and processing of a person. The other, named ServerThread, will define the processing of a server thread for each client.
The server (via its threads) will handle client requests to add, find, and delete Person objects maintained within a HashMap using the person's name as the key. It must store the HashMap to disk when it is shutdown and reload the HashMap from disk when it is restarted.
The client will provide a GUI front-end for adding, finding, and deleting Person objects.
Define a serializable Person class outside of the App class. It must only encapsulate name (String) and phone number (String). Code a single constructor to instantiate an object using values received for both instance variables. Provide simple "set" and "get" methods (setName(), getName(), etc.) to store and retrieve the value of each instance variable. Do NOT be concerned with editing the values of the instance variables.
Define the App class for a Windows program that will immediately ask the user to specify the processing mode (client or server). The technique for determining the processing mode is up to you (Choice, Checkbox, Buttons, etc.). Based upon the mode, processing is as follows:
Using a FileDialog, ask the user for the name and location of the telephone directory file. If the specified file has a length other than zero, read it as a HashMap. Otherwise, instantiate a new HashMap for the telephone directory.
Loop to accept client logins. When one occurs, construct a new ServerThread with references to its Socket and the HashMap. Then, call the thread's start() method to begin its processing.
When the Window is closed, destroy all threads and write the HashMap to disk.
During construction, establish an ObjectInputStream and an ObjectOutputStream for the socket.
The run() method must handle client requests to add a Person to, find a Person in, or delete a Person from the HashMap. Develop your own scheme for transaction codes but be sure to:
Send a String object to the client indicating the success or failure of an add or delete transaction. For example, "person added", "person already exists", "person deleted", or "person not found".
Send a Person object to the client for a find transaction. If the person was not found within the HashMap, send a Person object having null values for name and phone number. Otherwise, send the found Person object.
Synchronize code to prevent two threads from working with the HashMap at the same time.
Provide a destroy() method to kill the thread.
Provide a GUI with text fields for entering and displaying the person's name and phone number. Use buttons to trigger Add, Find, and Delete operations, and a text field or text area for displaying messages. The Delete button should only be enabled after a Find operation has succeeded. The choice of layout, colors, and fonts are up to you.
When Add is selected, verify that all data is present. If it is, construct a Person object, send it to the server as part of an add transaction, and read and display the server's reply. If not all data is present, send nothing to the server but display an error message.
When Find is selected, verify that the person's name is present. If it is, send the person's name to the server as part of a find transaction, read and display the server's reply, and enable the Delete button if the transaction was successful (note that after a successful find transaction, the person's name and phone number should appear on the screen). If the person's name is missing, send nothing to the server but display an error message.
When Delete is selected, verify that the person's name is present. If it is, send the person's name to the server as part of a delete transaction, read and display the server's reply, and disable the Delete button. If the person's name is missing, send nothing to the server but display an error message.
For now, it'll take time for us to read such a bunch of coding lines and your explanation... Well, but I'll try my best to reply you with the complete program within two or three days... I do like such kind of programming challenge(Of course, not from you)
Originally posted by Joe Ess:
That's a no-no, Ko Ko. Let's let Jon ask us specific questions so we can give him help without compromising his education.
Yeah, what Joe said is reasonable...
Jon, you should ask questions specific to the program... Actually I have already made your program compiled already... There were a lot, a lot of errors in the code... But it's not working properly yet... So just ask what you want to know... I'll be answering with the modified code in my hands...
Originally posted by jon ladd:
Ok i am trying to get my add button working I had it compiling but now it just keep blowing up and I have no idea. I redid the code form the first example, for the most part.
The first compiler error I see is:
C:\crap\App.java:509: orphaned case
Looks like you have an open brace following the case before FIND and you don't close it. No biggie. The 2 of the other 3 problems are missing semicolons. You have to pay attention to detail. And don't expect to write a ton of code and it will just work. Get something small to work and add to it. Helps narrow down where the problems are.
It looks like your program is originated from another program, coz I saw a lot of stuff dealing with Items, Shipping and so on... R u trying to change someone's program to make yours with different topic? Or is it from your instructor? It seems like the whole program flow should be changed... I saw a lot of logical errors in the program....