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...
Previous lesson: 15.2 Making ZooAdministrator a singleton classCourse contents Modify the other core system classes Using the approach given above, it is the intention that the user interface classes only communicate with the core system through the ZooAdministrator class. At the moment there is nothing to prevent a user interface class ...
Previous lesson: 15.1 Access modifiers and visibilityCourse contents Making ZooAdministrator a singleton class You have previously learned that to instantiate an object of any class you use the new keyword to invoke a class's constructor. For example, to instantiate some animals you may have done this: Animal leo = new Lion("Leo", Gender.MALE...
Previous lesson: 14.17 JOptionPaneCourse contents Access modifiers and visibility Access modifiers enable you to protect and control parts of your application from inappropriate use by other parts or other applications. A singleton class is one where no more than one instance of that class can exist. In this section you will learn: An ov...
Previous lesson: 14.16 JDialogCourse contents JOptionPane The JOptionPane class provides a simple way of displaying standard dialogs that show informational, warning or error messages through its static convenience methods. Change the ShowDialogButtonListener inner class as follows: private class ShowDialogButtonListener implements ActionList...
Previous lesson: 14.15 JTabbedPaneCourse contents JDialog The JDialog class displays a separate window which is "owned" by an application's frame. You can either add your own components to a dialog or use a simple pre-built one through the JOptionPane class. There follows an ActionListener inner class that builds and displays a JDialog consisting o...
Previous lesson: 14.14 JSplitPaneCourse contents JTabbedPane The JTabbedPane class displays separate titled "tabs", each of which allows the user to switch between by clicking on a tab: JPanel panelOne = new JPanel();panelOne.add(new JLabel("This is the first panel"));JPanel panelTwo = new JPanel();panelTwo.add(new JLabel("This is the second ...
Previous lesson: 14.13 JTreeCourse contents JSplitPane The JSplitPane class displays two components next to each other with a user moveable dividing bar between them. Usually, the components on either side of the divider will be panels, each containing one of more other components: // Panel to go on the left or the topJPanel panelOne = new JP...
Previous lesson: 14.12 JTableCourse contents JTree The JTree class displays items which are structured in a hierarchy. Each item is known as a node, and each node can contain other nodes as its "children". Like JList and JTable, the JTree uses an associated model object (a TreeModel) to provide its data. However, in many cases it is easier to...
Previous lesson: 14.11 JListCourse contents JTable Whereas the JList class displayed a list of items in a single column, the JTable class is capable of showing items that each have several columns. You need to attach a TableModel object (which references the item data) to the JTable. The most common way of doing this is to subclass the Abstra...
Previous lesson: 14.10 JSpinnerCourse contents JList The JList class displays a selection of a number of items, from which one or more may be selected. It is possible to pass an array of objects into the JList constructor, and it is usual to nest the list inside a JScrollPane: String[] options = {"Red", "Green", "Blue"};JList list = ne...
Previous lesson: 14.9 JSliderCourse contents JSpinner The JSpinner class enables the user to "spin" through a range of items using small up and down arrow buttons: JSpinner spinner = new JSpinner();panel.add(spinner); By default, the spinner allows the spinning through an unbounded range of integer values, defaulting to zero. You can use the ...
Previous lesson: 14.8 JComboBoxCourse contents JSlider The JSlider class allows the user to select a value, from within a range of values, by moving a sliding knob: JSlider slider = new JSlider();panel.add(slider); By default, the allowable range of values is from 0 to 100, with the knob pre-selected at 50. The default slider will look like t...