In this tutorial we will create a simple MSRE application that enables us to read and write data to a card. The difficulty level of this tutorial is medium. We suggest you complete the Supervisor Bean tutorial before attempting this one.
First you must create a new class that you develop into your application. Before you begin, make sure you have imported the LANDP Java Beans into the Visual Age environment.
Create a new class in the "LANDP Beans" project called "MSRESample" which we will develop into our application. This class should be a subclass of 'javax.swing.JFrame', and in a package called "msre".
In the next dialogue box that appears, import "com.ibm.landp", "com.ibm.landp.spv" and "com.ibm.landp.msre" packages, and use the "com.ibm.landp.msre.LandpMSREConst" interface.
Place a Supervisor, RmtReq and MagneticStripe bean on the workspace. If you can not remember how to do this, refer to the Supervisor Bean tutorial.
We must now add beans to our JFrame to allow us to read and write data. The following diagram shows the GUI we wish to create for this application.
By using the component palette, place the appropriate beans onto your JFrame and set the 'text' property of each bean so that it matches the above template. Note: If you can not remember how to do this, refer to the Supervisor Bean tutorial where we added beans to a JFrame, and set their text properties.
Now we have our Interface set up, we can start making connections between the visual beans and our LANDP beans
Connect the 'windowOpened' event of the JFrame to the 'register()' method of the RmtReq bean. This is so that we register the application with the Java Manager when it is run.
Connect the 'windowClosing' event of the JFrame to the 'unregister()' method of the RmtReq bean. This is so that we unregister the application with the Java Manager when it is closed.
Connect the 'actionPerformed' event of the 'Connect' Button to the 'connect' method of the Supervisor Bean as follows.
Now connect the 'actionPerformed' event of the 'Disconnect' Button to the 'disconnect()' method of the Supervisor Bean. Using the previous step as a guide.
Connect the 'Action Performed' event of the 'Write' button to the 'write' method of the MagneticStripeReader Bean as follows.
Notice that the line is dashed and incomplete. This is because 'writeTracks()' requires parameters and it is not complete until we supply these parameters.
Connect the 'Action Performed' event of the 'Read' button to the 'read' method of the MagneticStripeReader Bean. Use step 8(a) as a guide but this time use the check boxes.
Notice again that the line is dashed . This is because 'readMultiTracks()' requires parameters.
The connection should now be a solid line. To finish the application, we shall now add connections to display the data returned from a read operation.
Connect the 'normal result' event of the connection from the Read button to the readMultiTracks() method to the displayTrack1() method of the MagneticStripeReader Bean as follows.
Connect the 'normal result' of this new connection to the 'text' property of the 'Account Number' text field as follows.
Next connect the 'normal result' event of the connection from the Read button to the readMultiTracks() method to the displayTrack2() method of the MagneticStripeReader Bean.
Finally connect the 'normal result' of this new connection to the 'text' property of the 'Pin Number' text field in the same way as you did for track 1.
The application is now complete. From the menu bar at the top of the screen, select Bean->Save Bean to save your work.