That's way too much code. Since you're asking about manipulating a file, you should provide an SSCCE that shows only the code that's modifying the file. It doesn't even have to be the real file. Just code that turns file
Unless you have a very good reason to do so--like you're receiving data from or sending it to some other system that expects it in that format and you can't change it--the "parallel arrays" approach ignores one of the main features of OO programming. You should define a class, maybe called Employee, if that's what you're dealing with here, that has empnum, name, age, etc., and create an array of those Objects.
And the bits I have left are also bad.
addActionListener(this) is non-object-oriented programming, and the large block of if-elses is difficult to maintain.
Empty catch blocks are dangerous.
You probably don’t need those many fields; they can probably all be local variables in the constructor or initGUI method.
Anne Buena wrote: . . . . . .
You are going about this exercise quite in the wrong way. You should not even think of creating a GUI until you have got the logic working at the command line/a terminal. You should have the writing and reading done in one class, and the display in a different class. You need to make the GUI match the logic, whereas you would appear to be trying to squeeze the logic into the shape of the GUI.
Campbell Ritchie wrote:You are going about this exercise quite in the wrong way. You should not even think of creating a GUI until you have got the logic working at the command line/a terminal.
@Anne: What Campbell said is part of a larger paradigm called "division of responsibility", and usually involves understanding the problem.
There's absolutely no point in trying to write a program for, for example, a game, unless you understand the game itself.
The corollary to that is that you're usually much better off writing a "mill" (old computer term; but might be worth looking up) that actually does what you want before you write anything else. You can always tack on the fancy GUI stuff afterwards (if you designed it properly ).
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Anne, I can clearly remember having told you twice to use a temporary file instead of writing to the file in place. RandomAccessFile is for binary files only, and replacing content using it should only be done if you need to replace one piece of binary data with another piece of binary data of exactly the same size.