"Il y a peu de choses qui me soient impossibles..."
Michael Dunn wrote:by the look of it, all you've done is create the 'add' function of your address book.
an address book gui could be just a JTable with your current field identifiers as the column names,
or a JTabbedPane with 26 tabs (A to Z) etc. i.e. something to display everyone's info.
all you do with your add function is to save the info to a database, or, for simplicity, to a text file,
with a delimeter between the fields (~ or | etc - some character not likely to be part of name/address).
when the program starts it would read the text file, line by line and splitting at the delimeter, then add
that data to the address book gui
Stevens Miller wrote:I think Michael's got you on the right track, Antuan. Let me add the suggestion that, if you are new to Java and don't yet know how to read and write data to persistent storage (you know, "to the disk"), then you should set all that Java in your posting aside for an hour or two and just fiddle with basic I/O. For example, if you had this text stored in flatfile.txt:
You could read it with this method:
And get this output:
Now, that's got some stuff in it that you really do need to know, but I almost feel guilty posting it, because you don't want to do your I/O that way. There is nothing inherently wrong with what I've listed here, but it omits some important features that any real program would include. (See, for example, the BufferedInputStream class.) In fact, it really does its I/O in a way that very few real programs would use at all. For your application, a database is almost certainly what you want to use. Until you're ready for that, you might want to look at some of the other ways the Java API allows you to use persistent storage, as the choices are many, and you wouldn't want to find out later you had reinvented any wheels (trust me on this: I know what that's like). For example, have a look at the XMLEncoder and Properties objects.
As you look into persistence, you're also going to find out about the Serializable interface. I will trust more experienced heads to advise you on that one, but the short version is this: you don't want to use it for data-storage (because Java makes no promises about whether or not it will work from one version to the next). I mention it because it is probably impossible to do any reading about persistent storage without running into Serializable, so be warned in advance.
Hope that helps.
Antuan Sanders wrote:Correct, I started over and simply built the GUI for the app. I Wanted to get some advice before I repeated the same mistake.
Winston Gutkowski wrote:
Antuan Sanders wrote:Correct, I started over and simply built the GUI for the app. I Wanted to get some advice before I repeated the same mistake.
I hate to say, but I think the best advice I can give you is: resist the temptation to code.
You don't solve problems in Java by coding, you solve them by thinking.
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:Winston's "coding vs. thinking" dichotomy reminds me also of my days as a student of physics. In physics, there is a battle for supremacy between the experimenters (who actually try things in laboratories to see what will happen) and theoreticians (who scribble things on blackboards to see what will happen). Unlike physics, where lab gear costs money, you can experiment all you want to in Java. But, there is a difference between a genuine experiment and each of the following: guessing, procrastinating, misusing, and screwing around. I'd take Winston's advice as far as shoving my nose into a good book on Java, and keeping it there until I had one of those "Aha!" moments that makes you think you know how to do something that might actually be useful. Then I'd run to a keyboard, and experiment with what I thought I'd just learned. After I felt like I had some solid understanding of my new skill, I'd go back to that book and learn another one.
Paul Clapham wrote:Well, yeah, generally you aren't breaking new ground, in the sense that you aren't doing something which has never been done before. However it does happen that you're breaking new ground in the sense that you are doing something which YOU have never done before.
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:Which, I suppose, supports the notion that one learns to program by, at least in part, reading about it first.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
"Il y a peu de choses qui me soient impossibles..."
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |