INTRODUCTION
The objects from the standard java.awt packages are called Graphical User Interface (GUI) objects, and they are used to handle the user interface aspect of programs. The style of programming used with the GUI objects is called event driven programming. An event occurs when a user interacts with a GUI object. For example, when a button is clicked, an event occurs. In event driven programs, objects are programmed to respond to the events by defining event handling methods. In the development of patient registration system interface
as shown in the four figures below, the following packages were used; javax.swing, java.awt, and java.awt.event.
INTERFACE
The figure 1 below is a patient registration form which is used to register a patient. The user of the registration form is a data entry clerk at a hospital.
Figure 1: A sample of non filled form
The development of the Java source code which displays the figure 1 has exposed me in discovering much about JButtons, JRadioButtons, JLabels, JTextFields, JComboBoxe, layout managers; especially GridBagLayout and handling event methods.
LABEL
It is a displayed line of text on an interface. For example, the label; Name of patient in the diagram 1 above is a label. Labels are used for a variety of purposes: to display captions for other controls such as text fields or combo boxes, to display informational messages, or to show the results of a calculation or a database lookup. Name of patient was constructed by using a JLabel constructor, specifying the coordinates of the label as (1,1), setting the GridBagConstraints to the EAST of the mainPanel> JLabel constructors and methods were used. Similar procedures were done to all the remaining labels (date of birth, home address, sex, hospital, diagnosis, treatment, Rhesus factor and appointment) but each label had a different cordinate.
TEXT FIELDS
A text field is a box that the user can type text in. The input boxes of the labels, for instance, text field for the label; name of patient was constructed by using JTextField constructor and methods. Length and cordinates of the field were specified. The GridBagConstraints were anchored to the WEST of the mainPanel and the text field was added to the mainPanel by using add method. Similar procedures were applied to the other text fields of the remaining labels but the difference was on the cordinates of each text field.
Figure 2 showing combo box with list o values
COMBO BOX
A combo box is a combination of a text field and a drop-down list from which the user can choose a value. The combo box with a label sex has male and female as values from which user can select value. The user must pick one of the values from the list as shown in figure 3. The JComboBox class was used to create combo boxes. Constructors and methods of this class were used.
Figure 3: A sample of filled form
After entering the details of patient were entered in the text fields and clicking the appropriate buttons.
RADIO BUTTONS
Buttons under Treatment and Rhesus Factor
Radio buttons travel in groups, and a user can select only one radio button in each group at a time. When a radio button is clicked to select it, whatever radio button was previously selected is automatically deselected. Compare radio buttons under treatment in figures 1 and 2.
To come up with radio buttons, two classes were used. Radio buttons were created with the JRadioButton class, by constructors and methods. Then a group for the buttons was created with the ButtonGroup class. After that, the radio buttons were added to a panel and to a button group.
The position of the radio buttons were set by using cordinates and the GridBagConstraints to the EAST of the main panel.
APPOINTMENT CHECKBOX
A check box is a control that the user can click to either check or uncheck. Check box in the interface above was used to let the user specify Yes or No to an appointment of a patient with a doctor.
JBUTTONS
The three JButtons namely save, clear and exit button were created by using JButton constructor. The buttons had the different x-values but the same y-values (cordinates) for positioning the buttons and GridBagLayout constraints were set to the west of the mainPanel.
The three JButtons namely save, clear and exit button were created by using JButton constructor. The buttons had the different x-values but the same y-values (cordinates) for positioning the buttons and GridBagLayout constraints were set to the west of the mainPanel.
- CLEAR BUTTON
This button is used to make corrections when data is entered incorrectly. It was constructed by JButton constructor. When this button is clicked, an event is sent to a listener that is registered with the button as an ActionListener. In particular, evt.getActionCommand() returns a string, giving the command associated with the button.
- EXIT BUTTON
When this button is clicked, the patient registration interface disappears. It was constructed by JButton constructor. When this button is clicked, an event is sent to a listener that is registered with the button as an ActionListener. In particular, evt.getActionCommand() returns a string, giving the command associated with the button.
- APPLY BUTTON
This button is clicked whenever the details that have been typed are to be kept in a database. Figure 3 below shows the results after clicking the save button in the diagram 2 above. The save button was constructed by JButton constructor. When the user clicked on the save button, the button generated an event of type ActionEvent. ActionListener has one method, “public void actionPerformed(ActionEvent evt)”, which was called to notify the object of an action event. When actionPerformed(evt) is called by the button, the parameter, evt, contains information about the event. In particular, evt.getActionCommand() returns a String giving the command associated with the save button.
Finally details of the patient are stored in a database known as details of registered patient as shown in figure 4 below.
Figure 4: Sample of saved details of a patient
Reference
Bailey, D.A., & Bailey, D.W. (2000). Java elements: Principles of programming in java.
New York: McGraw Hill-Companies, Inc.
Java All-In One Desk Reference for Dummies (2nd Ed.), John Willey & Sons
Thomas, C. (2001). An introduction to object oriented programming with Java (2nd ed.).
New York: Thomas Casson.
No comments:
Post a Comment