In this part I will show how to define the repository and controller Java classes for our Pet class. This part assumes you have completed Part 3 of this series of articles. In the previous part we defined a Pet class and made it suitable to become a database table. We now need a repository class that forms the data access mechanism....
Normally when installing NetBeans, and most other IDEs, you need to already have a Java Development Kit (JDK) installed on your device. It is sometimes useful to be able to install NetBeans together with the latest JDK for the following reasons: > To make installation easier and more convenient.> To use the latest JDK that won't interfere wit...
Method delegation in Java In this article I will show how you can delegate a method call from one Java object to another. Let's start with a simple Employee class that contains a method to perform some work: public class Employee { public void performSomeWork() { System.out.println("I am performing some work); }} Now suppose we have a Business clas...
Using the static keyword in Java to increment an object index number In this article I will show how to use Java's static keyword to increment a unique index number for object instances. We will start by creating a simple class called Employee comprising fields only for name and address. These fields will be normal instance variables: public class ...
Previous lesson: 20.3 JavaBeansCourse contents Networking Two of the main ways of programming networking applications in Java is through sockets and Remote Method Invocation (RMI): Sockets Java supports connection to other hosts through the use of sockets. You can use the Socket class (in package java.net) to connect to a remote host b...
Previous lesson: 20.2 GraphicsCourse contents JavaBeans A JavaBean is a reusable component that is written to conform to certain conventions. Although they don't have to be, JavaBeans are often graphical in nature and in fact all the Swing graphical components are JavaBeans. This enables them to be used within builder tools such as NetBeans. ...
Previous lesson: 20.1 Other Java featuresCourse contents Graphics There are facilities to draw graphics by overriding the paint() method of the component classes. Create a new class in virtualzoo.ui called PenguinPicture: package virtualzoo.ui;import java.awt.*;import javax.swing.*;public class PenguinPicture extends JPanel { @Override public void ...
Previous lesson: 19.2 Other types of persistenceCourse contents Other Java features The desktop application developed in this course used many, but not all, of the major facilities of the Java language. This final section provides a brief look at some of the other useful features. In this section you will learn: How you can distribute your ap...
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...