Java Email Project Notes...
These notes pertain to an email client server project done during a 2006 Java course.
[January 24th, 2006]
Okay, after my days of ranting (deleted to save some embarrassment), Java does have a simple way of ascertaining the current date/time. Yesterday I did this
Date d = new Date(); String today = d.toString(); //outputs Mon Jan 23 18:57:49 PST 2006
But today realized you could easily do this
String today = new Date().toString();
And there it is, the single line statement I'd been looking for.
Anyway, Here are some other examples that also get the current date/time in Java.
Use DateFormat to format date.
Date d = new Date(); DateFormat df = DateFormat.getDateTimeInstance(); String dateTime = df.format(d);
Tried something sorta kinda similiar using the Calendar class, but it returned a crazy long string.
Calendar c = Calendar.getInstance(); String today = c.toString(); //outputs (something crazy and sick)
Especially liked the SimpleDateFormat. Lead to an answer on how to create each email with it's own unique file name.
public String makeFileName() {
SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd-HHmmss");
Date d = new Date();
String result = sdf.format(d);
return result;
}
Will output “2006 January 20 13:42:28 AM” as “060120-134228”. Unique down to the second. Capitol H's return hours in 24hr format. Inserted dash to easily differentiate date from time.
For more information, see these links: DateFormat, SimpleDateFormat, SimpleDateFormat customization.
[January 24th, 2006]
Link to remember: listFiles. Looks like it could come in handy for reading in a list of files from a directory. Am only thinking out loud here, but let's say the email user has some saved, not yet sent, mail. Could use listFiles to read back in those saved files. Valuable on the server side as well.
[February 5th, 2006]
Have learned NetBeans doesn't allow me to run both the server and client apps. at the same time on one computer (or maybe it does and I don't know how). Took me 2 days to figure this out. Was running server, then changed client to main project and ran it, too, using loopback 127.0.0.1. Kept checking and rechecking thinking problem was in my code. Finally got bright idea to run them on 2 different machines. It all works great.
Another enlightenment in past few weeks, to get an element out of an ArrayList, use get() method.
myArrayList.get(index);
println method has a toString method, but to convert to a string yourself, add toString at end.
String myString = myArrayList.get(index).toString;
Unlike C# where this statement does the job
string myString = (string)myArrayList[index];
For more ArrayList info: java.sun
[February 9th, 2006]
Dude... HashSets, HashCodes and having to override equals() and hashCode() to compare if 2 objects are truly equal is some crazy mind blowing stuff.
[March 7th, 2006]
The File's listFiles() method was no great idea. Returns list of objects. Using list() ( myFolder.list() ) works better, returns string list of files in the folder. Less complicated accessing file names.
Made claim on one of my pages regarding how hardcoding the GUI wasn't as complicated as 1st thought. Whatever. Though the beginning is fairly simple, as soon as you start attempting to open frames within frames, or experiment with different layout managers, things get pretty crazy. Most the class has resorted to using Visual Studio (ala J#) for GUI making. And yes, it is superior. Visual Studio is a GUI creating masterpiece. But no, not me. I have to be special. Reasoning? This is a Java class and I want to walk away knowing I learned every bloody bit of Java I bloody well could! And yes, could use NetBean's new GUI maker... But again, being the special individual one must be, am sticking with orignal plan of hardcoding for the challenging learning experience. Next time, though, forget it.
[March 9th, 2006]
Regarding JTable's. If you want your column headings to appear, you must add a JScrollPane.
JTable table= new JTable(cells, columnHeadings); JScrollPane scroller = new JScrollPane(table); //don't forget to add scroller, not table, to content pane.
Maybe it's just me, but shouldn't column headings show up naturally without the extra work? Certainly save a guy the unneeded "where are they?!?!" frustration.
[March 18th, 2006]
Have done a ton of work the past couple weeks. Project's due in 2 days. Been crazy. This is the time I should've been keeping really good notes. Decided on displaying the users inbox as a JTable. I like the headers, resizable columns, even movable columns. Took a couple days, and this codetoad example, before it finally worked. Love the simple add and delete row functionality. Though have yet to figure out how to make each cell uneditable.
As probably already said somewhere, no longer had to follow SMTP. Instructor didn't really know how SMTP worked so he backed off that part and turned it into a more simple client server email project.
Proud of myself, stuck to thy Java hardcoding GUI guns. Could've bailed at any point and taken the easy road, but no, the much more frustrating 'road less travelled' was more 'fun'. This, in turn, meant a lot more time struggling with Java GUI concepts than writing functional code.
Haven't fully grasped Jdesktop and JInternalFrames. Instead choose to Create a seperate JFrame for each popup window. If that's wise or not, I don't know. Put the
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
only in the main frame. If it was in the others, when clicking close on them, whole application would shut down. Now only clicking close on main frame will shut down the application. Worked for me. Instructor was showing GUI making with Visual Studio ala J#, have been left to learn alot of this on my own. Though, to his credit, he did hand me a couple big books for help.
Left to figure out: 1) Making the message of the currently highlighted table selection show in the preview pane. 2) Figure out why delete() method doesn't work on the server side. Should delete message after it's been sent to client. Runs the statement, but doesn't delete. Using same code as on client. Works on client *confused*. Maybe will try moving message to a different folder after sending. Like "sent" folder.
Would liked to have done: A JTree with user name that branched to user's inbox and drafts folders. No more time nor brain energy.
[March 28th, 2006 ... Closure]
We'll put some sorta closure to this. Turned in project last week Monday. Didn't get to see each others projects. Who knows how it stacked up. Wouldn't say it's outstanding. Doubt I'll ever post the code. Some parts I'm rather proud of, others not.
Answer to a couple problems,
1) Used code found here to display message in preview pane of whichever email was currently highlighted.
2) A little research on the 'wouldn't delete' bug turned up the probable cause being an outstanding reference (writer) to the file preventing the delete and renaming.
That's pretty much it. And I did receive an 'A'.