Previous lesson: 19.1 PersistenceCourse contents Other types of persistence You have seen how object serialization provides a relatively straightforward mechanism for saving the contents of one or more objects to a disk file. This section briefly mentions a few other ways in which data of various sorts can be saved to files. Saving individual...
Previous lesson: 18.4 Setting the look and feelCourse contents Persistence Many applications are only of limited use if they are not able to save their state each time they run. Persistence enables you to store information to disk and to read it back at a later time. In this section you will learn: How to save data to a disk fileHow to read s...
Previous lesson: 18.3 Creating a toolbarCourse contents Setting the look and feel AdministratorFrame constructor, immediately after the call to super(): // Set to native look & feeltry { UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName());} catch (Exception e) { e.printStackTrace(); // If unable just carry on with d...
Previous lesson: 18.2 Creating a menu barCourse contents Creating a toolbar Whereas the menu bar provides selectable options for all an application's functions, a toolbar provides a strip consisting typically of icons for the most frequently used facilities. Oracle provides a downloadable set of toolbar icons that you can use in applicat...
Previous lesson: 18.1 Finishing off the User InterfaceCourse contents Creating a menu bar A menu bar is constructed separately from the rest of the graphical layouts and components and once defined is attached to the frame. There are three classes used in combination in building a menu-bar: JMenuBar: an object of this class defines the menu-b...
Previous lesson: 17.5 Handling the Add buttonCourse contents Finishing off the User Interface This section puts the finishing touches to the graphical part of the application by creating a read-only table for the zoo's visitors, defining a menu-bar and toolbar, and by making the application adopt the running system's look-and-feel. In this section ...
Previous lesson: 17.4 Removing an existing animalCourse contents Handling the Add button All that remains now is to write some code for the Add button to enable the user to switch from "change" mode back into "add" mode. Go to the Design view of AnimalPanel and double-click the Add button to generate its addButtonActionPerformed() method. All...
Previous lesson: 17.3 Modifying AdministratorFrameCourse contents Removing an existing animal When you built the form for AnimalPanel you included a Remove button. Before writing the code so that it removes the selected animal (after asking for confirmation) you will change the status of the button so that it is only enabled (i.e., available ...
Previous lesson: 17.2 Defining a selection tree of animalsCourse contents Modifying AdministratorFrame The frame now needs to show AnimalPanel inside a new tab of the JTabbedPane: package virtualzoo.ui;import virtualzoo.core.*;import java.awt.*;import javax.swing.*;public class AdministratorFrame extends JFrame { private ZooKeeperEditor zooKe...
Previous lesson: 17.1 More User Interface DevelopmentsCourse contents Defining a selection tree of animals The left-hand section of the screen shows a scrollable tree of all of the animals in the zoo, categorised by the animal's type. The natural component to use for this is a JTree nested inside a JScrollPane. The AnimalTree class Creat...
Previous lesson: 6.9 Handling the Add buttonCourse contents More User Interface Developments This section continues the previous one to develop some additional interacting graphical components and panels. In this section you will learn: How to develop some additional types of interacting components and panelsHow to prepare the core system for...
Previous lesson: 16.8 Removing an existing zookeeperCourse contents Handling the Add button All that remains now is to write some code for the Add button to enable the user to switch from "change" mode back into "add" mode. Go to the Design view of ZooKeeperPanel and double-click the Add button to generate its addButtonActionPerformed() method. All...
Previous lesson: 16.7 Modifying existing zookeeper detailsCourse contents Removing an existing zookeeper When you built the form for ZooKeeperPanel you included a Remove button. Before writing the code so that it removes the selected zookeeper (after asking for confirmation) you will change the status of the button so that it is only enabled ...
Previous lesson: 16.6 Updating ZooKeeperList automaticallyCourse contents Modifying existing zookeeper details Now that you have completed the code necessary to add new zookeepers you need to enable their details to be changed. What you will do is detect whenever the user selects one of the names in ZooKeeperList and pass that selected ZooKee...
Previous lesson: 16.5 The AdministratorFrame classCourse contents Updating ZooKeeperList automatically The ZooKeeperList object needs some way of being notified whenever a change to the collection of zookeeper objects held by the administrator changes, in order that it can update its model and thus be reflected in the list of items displayed....
Previous lesson: 16.4 The ZooKeeperPanel classCourse contents The AdministratorFrame class The frame now only needs to show ZooKeeperPanel inside a tab of a JTabbedPane. Create a class in virtualzoo.ui called AdministratorFrame: package virtualzoo.ui;import java.awt.*;import javax.swing.*;public class AdministratorFrame extends JFrame { publi...
Previous lesson: 16.3 Validating form inputCourse contents The ZooKeeperPanel class If you look at again at Figure 16.1 at the beginning of this section you will see that the two classes you have developed so far, ZooKeeperList and ZooKeeperEditor, are set as the left and right components inside a JSplitPane, underneath which is a panel containing ...
Previous lesson: 16.2 Defining a selection list of zookeepersCourse contents Validating form input In Section 7 you learned how Java exceptions can be used to indicate an error of some kind. You also learned that there are two types of exceptions, checked and unchecked: Use checked exceptions for errors from which you or the user can recoverUse unc...
Previous lesson: 16.1 Developing a user interfaceCourse contents Defining a selection list of zookeepers The left-hand section of the screen will show a scrollable list of all of the zoo keepers working at the zoo, and the natural component to use for this is a JList nested inside a JScrollPane. The JList class is a UI list-box component capable of...
Previous lesson 15.3 Modify the other core system classesCourse contents Developing a user interface Now that you have some familiarity with the various graphical components which are available you need to know how to get them to interact with each other to achieve your application's goals. In this section you will learn: How to go about developing...