Connecting GUI and functionality

Functionality of an application - more or less the application kernel - usually is separated from the graphical user interface (GUI) in separate classes. In some cases it makes sense, to combine both in one class or to create inner classes within another class too.

Still there must be a connection between the two, application kernel and GUI, which can be built by using actions.

Actions are explained in general below. In the follwoing chapters some of the actions of FrmMain are explained in greater detail. Additional comments about the actions can be found in the source code.

Actions

Action classes are a design approach to make a central connection between GUI and functionality. With functions being coded as actions, respective functionality is kept in a central place and can be centrally combined with code dealing with availability and behaviour of the respective functions during certain states of the application.

Why actions make sense

Coding certain functionality as actions makes code easier to maintain, because code is stored at exactly one location while the resulting action and its appearance can be connected to several GUI elements such as a menu item and a tool bar button for instance.

What actions do

An action can be constructed with a certain name and icon. Components such as menu items or buttons automatically display an action's name and icon when it is associated with them. As well the action's state (enabled or not enabled) automatically is reflected in the component's display (dimmed or normally shown).

When selecting a component that has an action associated to it, this component automatically fires an action event that calls method actionPerformed of that action. An ActionEvent object is created automatically describing the event that led to calling the action.

In essence a big advantage of using actions aside of their easier maintenance is that no additional coding is required to support the mentioned interactions and dependencies.

How actions are designed in class FrmMain

In class FrmMain, the actions are designed as inner classes. With that the actions have access to FrmMain's fields and methods without FrmMain having to pass references to the actions explicitly. The actions defined so far have a lot to do with the documents shown in FrmMain so that access to jtpDocs is quite helpful.

In the following chapters we look into some of the actions of FrmMain in detail.