Java Programming Help on Email Client Simulation
Computer Programming
Email client simulation
You are to produce a simulation of an email client (something like a very basic version of Microsoft Outlook or Mozilla Thunderbird). It is a simulation in the sense that it cannot send or receive emails, although it should be able to manage and create them.
You are provided with some basic code, see pages 10 – 17.
EmailManager.java:
This is what the Email Manager GUI looks like when run (this frame is not resizable and the X button is disabled – the user must click the Exit button to quit):
ReadMessage.java:
When the user enters a valid message ID into the text field and clicks the Read Message button the following GUI appears (with the Email Manager GUI still displayed on screen). It is also not resizable but the X button disposes of it:
If the user enters a priority between 1 and 5 into the text field and clicks the Update button, the message is given the desired priority value.
MessageData.java:
You are also supplied with the MessageData.java class which holds the email messages as static data. You do NOT need to fully understand this class, but note that it provides number of public static methods which you may use, including:
public static String getMessage(String id) …
public static int getPriority(String id) …
public static String getRecipient(String id) …
public static String getSender(String id) …
public static String getSubject(String id) …
public static void setPriority(String id, int priority) …
For instance the getSubject method is used in the actionPerformed method of ReadMessage.java to obtain the subject of the message with the given identifier (it returns null if there is no such item in the data).
Using EmailManager.java and ReadMessage.java as examples, you are to write two JFrames, LabelMessages.java and NewMessage.java, and complete the functionality for the Email Manager GUI:
- LabelMessages.java should allow the user to:
-
- Enter a message ID and click a button to mark that message with a label (see Stage 3 & Stage 6 below for more details). If the message ID is valid, the message should have the label added and a list of all the messages with that label should be displayed in a text area; otherwise a suitable error message should be displayed.
- Click a button to remove the label from all the messages and clear the text area.
- NewMessage.java should allow the user to enter a message ID, subject and recipient in text fields and a new message in a text area. If the message ID does not already exist, the message is added to the data in MessageData.java, with the sender set to the DEFAULT_EMAIL address (this is one of the static variables in MessageData.java); otherwise a suitable error message should be displayed.
There are a number of stages to the development and not all students will manage all the deliverables. Each stage will be awarded the marks up to the maximum allocated ONLY when handed in AND accompanied by a relevant section in the final report.
Additional help will be provided in lectures, tutorials and the second workbook for some of the later deliverables.
- Stage 1 Understanding the code (max 10%, inclusive of report)
- java should be rewritten with lines of comment explaining exactly how all the code works, e.g.
// import the classes of the abstract windows toolkit and swing to enable us to use //components like buttons
import java.awt.*;
import javax.swing.*;
Stage 2 First GUIs (max 10%, inclusive of report)
- java and NewMessage.java should be designed and the code written in prototype form WITHOUT functionality (just the GUI appearance).
Stage 3 A working basic version (a further max 20%, inclusive of report)Implement the system whose GUIs you designed in stage 2.
LabelMessages.java: Note that at this stage the labelling system just needs to be a prototype version which can apply labels to whichever messages the user desires. The image below shows a possible design for Label Messages GUI:
- Here the user types in a message ID and a label. If the message ID is valid, the GUI displays a list of all the messages with that label. If the message ID is not valid, the GUI gives a suitable error message.Another possibility would be a drop-down list of labels.Once the labelling system is working the labels should also appear in the Email Manager GUI as below
- Stage 4 Improving your code (a further max 20%, inclusive of report)Design white box testing of your system (as defined in the Java workbook) and provide evidence of both the functionality of your program and the testing results.Also adapt the code to include a larger selection of messages in MessageData.java and at least one of the following:
- error handling for bad input;
- automatic updating of the message list in the Email Manager after the Read Message, Label Messages and New Message GUIs have completed their task;
- the attaching of images to email addresses so that in the Read Message GUI a picture of the sender is displayed.
Stage 5 Saving the message data externally (a further max 20%, inclusive of report) more details will be provided later.
Stage 6 Innovations (a further max 20%, inclusive of report), for example:
-
- When listing the messages, include the facility to view all the messages from a selected sender (e.g. using a JCombobox).
- Enhance the labelling facility – for example, a fully functioning labelling system, like the one that gmail provides, provides facilities for the user to create and delete labels. It also allows many-to-many relationships between messages and labels (i.e. each label can be attached to several messages, and, much harder to implement, each message can have more than one label).
- Combine the four GUIs into one single GUI (like Outlook or Thunderbird).
- Implement a search facility which allows the user to search for a given string in the messages.
- Implement threaded message viewing so that when reading a message, the Read Message GUI displays all messages in that conversation (i.e. all the messages with the same subject, disregarding the “Re:” prefix).
- For Deliverable A you should present your commented ReadMessage.java and the GUIs for LabelMessages.java and NewMessage.java (stages 1 & 2). This should be uploaded before midnight 30th November 2014. You will demonstrate your upload to your lab tutor on the following Monday.
- FINAL DELIVERABLETo cover as much of stages 1 – 6 as you have completed:A zip file containing working code in the form of a zipped NetBeans project folder, together with any resource files you have used (such as images or sound files). You are free to use NetBeans the GUI builder of NetBeans.The written part (excluding code listings) should be no more than 2,000 words. If you go over the word limit, use an appendix for your remaining words. There should be no more than 5 screen shots. If you have more than 5 screen shots, those over the limit should go into an appendix. A written report containing the evidence of all completed stages, which should include:
- Introduction
- A description of how you designed and developed the final code
- Suitable screen shots of the program in operation
- Details of any faults and failures, including a discussion of the white box testing results.
- Conclusions and reflection. For the reflection you should write at least 400 words, answer either (a) or (b) from the following:
- What did I actually achieve with this element of learning? Which were the most difficult parts, and why were they difficult for me? Which were the most straightforward parts, and why did I find these easy?
- What have I got out of doing this element of the course? How have I developed my knowledge and skills? How do I see the payoff from doing this element of the course helping me in the longer term?
- Appendices should contain:
- The commented version of ReadMessage.java that you submitted for interim deliverable A
- Test table and results as detailed in the Testing section of the workbook – this should be updated from the version you submitted for interim deliverable C to cover any changes you have made to the code since then
- Your program listing.
- Any screen shots over the five that are in the main report.
- The main report should be 2000 words, any words over should be in an appendix.
This final deliverable is to be submitted to the coursework upload system BEFORE THE COURSEWORK DEADLINE.
- Grading CriteriaThis is a staged assessment. You cannot get marks for a particular stage unless you have made a reasonable attempt at all of the previous stages.Typical grading:0-10% Only stage 1 (Understanding the code) reached. 11-20% Only stage 2 (First GUIs) reached.
21-40% Only stage 3 (A working basic version) reached.
OR further stages reached but the report is missing several sections.
OR further stages reached but the code cannot be run by your tutor (see page 3).
41-60% Only stage 4 (Improving your code) reached.
OR further stages reached but the report is missing a section.
OR further stages reached but the code contains runtime errors.
61-80% Only stage 5 (Saving the message data externally) reached.
81-100% All stages including stage 6 (Innovations) reached.
Assessment Criteria
Marks are awarded for:
- The functionality of the programme.
- Does the system do what it is supposed to do (according to the specification above)?
- Usability:
-
- Is your system straightforward and easy to use?
- Is it obvious to the user what to do?
- Are all messages clear and unambiguous?
- Is the bad input data handled appropriately?
- Is the output formatted appropriately?
- Does the system crash or throw uncaught exceptions?
- Saving Data Externally:
- Reads an external file
- Saves to an external file
- Quality of the Java code:
- Inclusion of meaningful comments.
- Use of sensible naming standards.
- Clear code layout and formatting.
- Quality and completeness of the report:
- Is the design documentation clear and concise?
- ?
- Have you included evidence of appropriate testing?
- Have you discussed any faults or failures?
- Have you reflected on the development process?
- EmailManager.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;
public class EmailManager extends JFrame
implements ActionListener {
private JButton list = new JButton(“List Messages”);
private JButton read = new JButton(“Read Message”);
private JTextField idTextField = new JTextField(2);
private JButton label = new JButton(“Label Messages”);
private JButton newMessage = new JButton(“New Message”);
private JButton quit = new JButton(“Exit”);
private JTextArea textArea = new JTextArea();
private JScrollPane scrollPane = new JScrollPane(textArea);
public static void main(String[] args) {
new EmailManager();
}
public EmailManager() {
setLayout(new BorderLayout());
setSize(600, 300);
setResizable(false);
setTitle(“Email Manager”);
// close application only by clicking the quit button
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
JPanel top = new JPanel();
top.add(list);
list.addActionListener(this);
top.add(read);
read.addActionListener(this);
top.add(idTextField);
top.add(label);
label.addActionListener(this);
top.add(newMessage);
newMessage.addActionListener(this);
top.add(quit);
quit.addActionListener(this);
add(“North”, top);
textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setPreferredSize(new Dimension(560, 200));
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(560, 200));
JPanel middle = new JPanel();
middle.add(scrollPane);
add(“Center”, middle);
textArea.setText(MessageData.listAll());
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == list) {
textArea.setText(MessageData.listAll());
} else if (e.getSource() == read) {
new ReadMessage(idTextField.getText());
} else if (e.getSource() == quit) {
MessageData.close();
System.exit(0);
}
}
}
- MessageData.javaimport java.util.*; public class MessageData {
private static final String DEFAULT_EMAIL = “Chris@redwich.ac.uk”;
private static final String DEFAULT_SUBJECT = “no subject”;
private static class Item {
Item(String t, String m) {
subject = DEFAULT_SUBJECT;
from = DEFAULT_EMAIL;
to = t;
message = m;
}
Item(String s, String t, String m) {
from = DEFAULT_EMAIL;
subject = s;
to = t;
message = m;
}
Item(String f, String s, String t, String m) {
from = f;
subject = s;
to = t;
message = m;
}
Item(String f, String s, String t, String m, int p) {
from = f;
subject = s;
to = t;
message = m;
priority = p;
}
// instance variables
private String subject;
private String from;
private String to;
private String message;
private String label = “”;
private int priority;
public String toString() {
return ” ” + pad(stars(priority), 8) + ” ” + pad(from, 30) + ” ” + pad(label, 6) + ” ” + subject;
}
private String pad(String string, int width) {
width -= string.length();
for (int i = 0; i < width; ++i) {
string += ” “;
}
return string;
}
}
// with a Map you use put to insert a key, value pair
// and get(key) to retrieve the value associated with a key
// You don’t need to understand how this works!
private static Map<String, Item> library = new TreeMap<String, Item>();
static {
// if you want to have extra library items, put them in here
// use the same style – keys should be 2 digit Strings
library.put(“01”, new Item(“Chris@redwich.ac.uk”, “Hello”,
“Kate@redwich.ac.uk”, “How is the course going?”, 2));
library.put(“02”, new Item(“Kate@redwich.ac.uk”, “Re: Hello”,
“Chris@redwich.ac.uk”, “> How is the course going?\n\nBrilliant, thanks. The students are all fantastic and are going to get top marks in their coursework.”, 2));
library.put(“03”, new Item(“A.Friend@hmail.com”, “Coffee”,
“Chris@redwich.ac.uk”, “You’re working too hard – fancy meeting for coffee?.”, 5));
library.put(“04”, new Item(“Chris@redwich.ac.uk”, “Exam”,
“Asif@redwich.ac.uk”, “I have nearly finished writing the exam – I hope the students have revised hard.”, 4));
library.put(“05”, new Item(“A.Student@redwich.ac.uk”, “Timetable”,
“Chris@redwich.ac.uk”, “help!!! my timetable is rubbish – i cant understand it!!! what r u going to do?”, 0));
library.put(“06”, new Item(“Chris@redwich.ac.uk”, “Re: Timetable”,
“A.Student@redwich.ac.uk”, “All sorted.”, 0));
library.put(“07”, new Item(“A.Student@redwich.ac.uk”, “Re: Timetable”,
“Chris@redwich.ac.uk”, “thx :)”, 0));
}
private static String listHeader() {
String output = “Id Priority From Label Subject\n”;
output += “== ======== ==== ===== =======\n”;
return output;
}
public static String listAll() {
String output = listHeader();
Iterator iterator = library.keySet().iterator();
while (iterator.hasNext()) {
String id = (String) iterator.next();
Item item = library.get(id);
output += id + item + “\n”;
}
return output;
}
static String listLabelled(String label) {
String output = listHeader();
Iterator iterator = library.keySet().iterator();
while (iterator.hasNext()) {
String id = (String) iterator.next();
Item item = library.get(id);
if (!item.label.equals(label)) {
continue;
}
output += id + item + “\n”;
}
return output;
}
public static String getSubject(String id) {
Item item = library.get(id);
if (item == null) {
return null; // null means no such item
} else {
return item.subject;
}
}
public static String getSender(String id) {
Item item = library.get(id);
if (item == null) {
return null; // null means no such item
} else {
return item.from;
}
}
public static int getPriority(String id) {
Item item = library.get(id);
if (item == null) {
return -1; // negative quantity means no such item
} else {
return item.priority;
}
}
public static void setPriority(String id, int priority) {
Item item = library.get(id);
if (item != null) {
item.priority = priority;
}
}
static String getMessage(String id) {
Item item = library.get(id);
if (item == null) {
return null; // null means no such item
} else {
return item.message;
}
}
static String getRecipient(String id) {
Item item = library.get(id);
if (item == null) {
return null; // null means no such item
} else {
return item.to;
}
}
static String setLabel(String id, String label) {
Item item = library.get(id);
if (item == null) {
return null; // null means no such item
} else {
item.label = label;
}
return listLabelled(label);
}
public static String stars(int rating) {
String stars = “”;
for (int i = 0; i < rating; ++i) {
stars += “*”;
}
return stars;
}
public static void close() {
// Does nothing for this static version.
// Write a statement to close the database when you are using one
- ReadMessage.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;
public class ReadMessage extends JFrame
implements ActionListener {
private String id;
private JTextField priority = new JTextField(2);
private JButton update = new JButton(“Update”);
private JButton close = new JButton(“Close”);
private JTextArea textArea = new JTextArea();
private JScrollPane scrollPane = new JScrollPane(textArea);
public ReadMessage(String id) {
this.id = id;
setLayout(new BorderLayout());
setSize(500, 250);
setResizable(false);
setTitle(“Message Details”);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel top = new JPanel();
top.add(new JLabel(“Enter Priority (1-5):”));
top.add(priority);
top.add(update);
update.addActionListener(this);
top.add(close);
close.addActionListener(this);
add(“North”, top);
textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setPreferredSize(new Dimension(450, 150));
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(450, 150));
JPanel middle = new JPanel();
middle.add(scrollPane);
add(“Center”, middle);
displayMessage();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == update) {
int priorityValue = Integer.parseInt(priority.getText());
MessageData.setPriority(id, priorityValue);
displayMessage();
} else if (e.getSource() == close) {
dispose();
}
}
private void displayMessage() {
String subject = MessageData.getSubject(id);
if (subject == null) {
textArea.setText(“No such message”);
} else {
textArea.setText(“Subject: ” + subject);
textArea.setText(“From: ” + MessageData.getSender(id));
textArea.append(“\nTo: ” + MessageData.getRecipient(id));
textArea.append(“\nPriority: ” + MessageData.stars(MessageData.getPriority(id)));
textArea.append(“\n\n” + MessageData.getMessage(id));
}
}
}
- To get java progeamming assignment help, please contact to our live chat adviser
- The functionality of the programme.