import javabook.*; import dmusican.*; import basicio.*; /** * Class to containing methods to handle an email inbox. * The ideas here are based on another project by Jeff Ondich. * * @author Dave Musicant * @version 1.0 */ class BasicInbox { private String inboxFilename; /* Since the same main window may be used by many methods of this class, it makes sense to have these objects as data members of the class. */ private MainWindow mainWindow; private OutputBox outputBox; private InputBox inputBox; private PasswordBox passwordBox; /** * Constructor. Here's where we will actually create the javabook * objects that we will use. * * @param The filename where the inbox will be kept */ public BasicInbox(String filename) { mainWindow = new MainWindow(); mainWindow.setVisible(true); mainWindow.toFront(); outputBox = new OutputBox(mainWindow); outputBox.show(); inputBox = new InputBox(mainWindow); passwordBox = new PasswordBox(mainWindow); inboxFilename = filename; } /** * Asks the user for name and password so that inbox can be brought * down from the server. */ public void getInbox() { String username = inputBox.getString("Enter username:"); String password = passwordBox.getString("Enter password:"); outputBox.printLine("Please wait, getting Inbox..."); MailTools.getInbox(username,password,inboxFilename); outputBox.printLine("Inbox received!"); } /** * Counts the number of lines in the inbox. */ public void countLines() { String s; int lineCount = 0; outputBox.printLine("Please wait, counting lines..."); BasicInput inputFile = new BasicInput(inboxFilename); while (inputFile.ready()) { s = inputFile.readLine(); lineCount++; } outputBox.printLine("The number of lines is: " + lineCount); inputFile.close(); } /** * Prints each line beginning with "From:", "To:", and "Subject:", * the number of messages in the file, the total number of lines * in the file, and the average number of lines per message * (including header lines). */ public void summarizeInbox() { /* This is the method that you need to write! This is currently a _stub_, which means that the method is included in here for testing purposes but it doesn't actually do anything useful. */ outputBox.printLine("Method summarizeInbox()."); } }