I just had a really quick look and my immediate impression is of good quality code. Variable & method names, plus relevant comments make it easy to see what's what. Lots of runtime tracing to confirm good behaviour (maybe an idea to use a simple Logging class rather than System.out so you turn them all on/off easily?).
My only area of question is re the lock (should be Lock!) class where you seem to have home-brewed a pile of functionality that's already available in a fully-designed fully-debugged bullet-proof form in the existing Java SE API? I'm not the best person to take that any further but maybe someone who's more of a Locks & Threading guru could comment?
But, in summary, there's nothing in this that screams "inexperienced" to me.
JamesCherrill
... trying to help
8,507 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29
JamesCherrill
... trying to help
8,507 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29
No, I wouldn't re-post the existing code now, but if, in the future, you have revised stuff to share...
JamesCherrill
... trying to help
8,507 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29
.. and a few notes on the GUI specifically:
You don't need all those this. qualifications on your variables and methods.
Your menus are perfectly sensible for this size of app, but as things grow you will start to get more & more complex - eg if you duplicate any menu items by adding a toolbar, or some right-click context menus. If you are considering going that way it's better to use Actions ( http://download.oracle.com/javase/tutorial/uiswing/misc/action.html ). Even if you don't but you do add more menus, the use of a single listener (this) with a load of if (source is A) else if (source is B) else if ... gets really untidy and hard to read. Things scale better with one listener per menu item, using an inner class. Personally I prefer the anonymous inner class version.
You have a number of methods that throw Exception rather than catching it. In general this isn't a good idea. When you get an E you want to display the stack trace, plus as many relevant variables as may help diagnose the problem. If you throw the E up to the calling method you lose much of the context in which the E was originally thrown, which makes it hard to understand. More seriously you lose the ability to have a finally clause that tidies up after the error.
If you want to signal a problem to a calling method you should still catch it where it happens, print everything relevant, then throw an application Exception up to the caller with a user-friendly text - maybe an example...
void myMethod throws Exception {
try {
do some file I/O stuff
} catch(IOException e) {
e.printStackTrace();
System,err.println(file details etc etc)
throw new Exception("There was an error reading the file - please check the file exists and you have permission to access it", e);
} finally {
tidy up (close files etc)
}
}
JamesCherrill
... trying to help
8,507 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29
Yes. There's no requirement for you to throw a new E if you have already caught the original one. The reason I included it was that the calling method probably needs to know that something has gone wrong, and maybe issue a user error message in some format appropriate to the user interface of the application. If you don't do something to tell the calling method there was a problem then it will continue executing and probably everything will fall apart in a horrible mess. If your method returns an Object, then you can signal the error by returning null (assuming that's not a valid return value) instead of throwing a new E.
JamesCherrill
... trying to help
8,507 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29