Tuesday, January 6, 2015

Program 2: Java Stopwatch

With the NetworkStatus application in a mostly working state, it’s time to shift gears to a separate application.  I like to build small, similar applications that will eventually use the same basic ideas.  The first application was designed to get a button working and responding to being pressed.  Program two is about threading.

And what better way to move to in to threading than my old favorite of the threading world, the Stop Watch.  StopWatch will be of similar design to NetworkStatus.  The thing would have several buttons allowing you to adjust the time, and display in the middle of the screen.  There should be a start and stop button.  So I guess the first thing is to pull up paint and create a generic mockup of the program design. 

I decided to go with a 3x4 grid layout simply because it’s different than the gridbag layout I went with earlier.  I’m still not impressed with Java FlowLayouts, and GUI design in general seems like a real pain.  But I’ve got to learn to work with what I have to work with.  Some systems just seem to be better suited for certain things than others. 


The number in location 0,1 and 2,1 will be independent of each other.  They will be separated by a colon.  The colon ends up being just a text field with the text size increased to make it look pretty.  Really, the 0,1 and 2,1 are text fields as well.  They will just be handled with some special code to make them operate properly.  It’s not complex code, and I’ve written the same thing in other languages before. See my C# example below.


Though after examining my old C# stop watch, I might put a reset button in the middle.  That could work out nicely.  So, half an hour into this project I have a reasonable (though ugly) facsimile of a StopWatch.  It is not fuctional, and I need about 200-300 more lines of code to make it work without threading.  But at least there’s been some progress made.  Maybe tomorrow, it will be counting. 


Probably not.  It will take all of tomorrow to get the buttons working properly.  

No comments:

Post a Comment