|
|
||
| You are here: | ||
|
SL Mastery aspect:
We've simplified it a bit so as to let you have more fun developing other fields, validation techniques and so on - we're nice like that. What HAS been added, astute students will note, is the reference to the Serializable interface. We can't show examples of these applications in a web page, you will have to download the source, import into your IDE to compile and run them.
All this is stuff you have seen before.
New lines >>>>>>>
New lines >>>>>>>
New method >>>>>>>
New method >>>>>>>
Open a data file and read the records into the array (in one go - remember that an array is an object too) The array may not have been full of records when saved. last points to the last record in the array. Everything OK, set the pointers as before.
There might not be any records at all. Deal with file problems.
Applications start with main methods. Main processing method, as ever. More buttons could be added here - edit record , delete record , save, quit . We've moved the operations into separate methods to simplify the processing. Same process as before.
These two methods are the same. I know, I know, you've seen all this before; tell you what I'll leave them out of the next example.
Phew! Notice how the examples are getting longer? Your code development will go easier when you do the design first and break the programming task down into smaller methods.
This example includes all the techniques that SL students will need to complete a dossier. However, there is much more to completing a dossier than just the coding.
In addition, other techniques such as sorting and searching can be added to a dossier when appropriate. |
On this page: [ VideoTape Class | VideoCollection Application ] This example continues from the VideoTape Class example we introduced in the section on records . The Class structure is as follows: public class VideoTape implements java.io.Serializable VideoTapeCollection Application The Application is similar to the Applet we saw before. However, Applets cannot write to the local file system so we use a GUI Application that has a main Class. A text-based console application would probably do as well and you can see an example on the JETS pages .
/** // labels for field data // control buttons // system messages display // Set up an array to hold the tape collection // Filename is fixed if ( last != -1 ) Exercise Editing a record should be fairly easy, add a button that allows you to collect new details from the display and put it into the array at the current position. Deleting a record is relatively complicated, I'd be inclined to leave it for now ;-) Saving would best be done by moving the code inside the windowClosing() method into its own saveRecords method. This can then be called from windowClosing and a new save Button - a good example of method re-use. Related: [ Java home | Previous: Files home | Next: RAF Files] |
A really simple approach. Allows the reading and writing of an entire array of object instances. For a comparison and example of Applications vs Applets see the page applications.html Other examples can be found in the book Computer Science, Java Enabled from::
|
|
|
|||
|
Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2009 Richard Jones, PO BOX 246, Cambridge, New Zealand; This page was last modified: May 31, 2009 |