Section 1 – "README" Information

Author: Will Landstrom

Date: 07/14/2002

Re: CSCI315 Project#2 (Java Beans)

Classes:

MGMain.java

MGMainBeanInfo.java

MGCheckerEvent.java

MGCheckerListener.java

QuestionPositionEditor.java

MGVeto.java

Abstract/Overview of Project:

This application serves as a basic rendition of the old TV Game Show "The MatchGame". This program will present a Swing GUI interface to the user that will allow the user to select questions (in the form of JButtons) and then select matching answers (also in the form of JButtons). The program is designed to allow the user to select (via a JOptionPane Dialog) from two subject categories – Musical Compositions/Composers and Movies/Actors. Upon selecting the MGMain Bean from the Bean ToolBox and dropping the Bean into the BeanBox the user will be prompted to select either the Music or Movies category. Internally the MGMain program will then use the Music or Movies subject data (that is originally stored in 2 separate arrays) and use this information in order to build the GUI interface. Initially the "question" JButtons are placed on the left side of the GUI and the "answer" JButtons are placed on the right side of the GUI. The user has the option of switching the position of the question/answer buttons by changing the "questionPosition" property from "Left" to "Right" and visa-versa. This functionality is handled via a Customized Bean Editor (QuestionPositionEditor.java). The user may also restart the game at any time (as long as they are not currently "between" questions and answers" (IE: if the user clicks a question JButton then they must first click an answer JButton before restarting the game)). The user also has the option of changing the title of the GUI (via the "textTitle" property) without any restrictions (IE: it is a simple Bean property). The user can also change the "resetTitle" property (which is associated with a JLabel). However, this property can be associated with a PropertyChangeListener and/or a VetoableChangeListener (that is the purpose of MGVeto.java) that will prevent the user from changing this property if they enter a string that is > 15 characters. The user is restricted to a maximum of 20 guesses. This functionality is handled via a customized event handler (MGCheckerEvent.java and MGCheckerListener.java) that will present a warning JOptionPane GUI to the user upon their 15th guess (that they are nearing their maximum number of guesses) and will terminate the game upon their 20th guess. Finally, the MGMain Bean has an associated BeanInfo class (MGMainBeanInfo.java) that restricts the properties presented to the user to the 3 mentioned above along with associating the MGMain Bean with an Icon ("MGICONx.gif" where "x" will dependant upon the iconKind variable).

How the test this Bean:

1 – Access the MGMain.jar file from the beandata.zip file that is available from this site and copy it into your Bean jars directory - OR compile all classes listed above (or use the *.class files from the Beandata.zip file mentioned in Section 4 of this document)

2 – Use a Manifest file that lists MGMain.class and MGVeto.class as Beans

(see file MGMain.mft)

3 – Create a JAR file that contains all classes resulting from the javac compilation along with the MGICON*.gif and *.jpg files (see file MGM.bat as an example)

4 – Start the java BeanBox

5 – Select MGMain from the Bean ToolBox

6 – Select your subject (Music or Movies)

7 – Click mouse to drop MGMain into BeanBox

8 – Drop a MGVeto Bean into BeanBox

9 – Click on MGMain GUI in order to give it the focus

10 – Click Editè Eventsè propertyChangeè propertyChange

11- Select MGVeto, select propertyChange and click OK

12 - Click on MGMain GUI in order to give it the focus

13 - Click Editè Eventsè vetoableChangeè vetoableChange

14 - Select MGVeto, select vetoableChange and click OK

15 – You can now start "playing the game". The user can click question buttons and then match these questions by clicking on answer buttons. After the user clicks a question button an icon is associated with the button in order to help the user remember what question button he/she just clicked. After clicking an answer button labels at the bottom of the GUI keep tallies of both the total number of guesses and total number of correct answers. There is also a textfield at the bottom of the GUI that the program uses to convey informational messages to the user.

The user can start a new game (by clicking on the "Restart Game" button), can change the title of the game (on the top left of the GUI) by changing the textTitle property, can change the "Restart Game" title by changing the resetTitle property (this is the property that is being monitored by the MGVeto Bean in order to ensure that the user does not enter a new resetTitle value that is > 15 characters), and can flip-flop the positions the question/answer buttons by changing the questionPosition property (this property is generated by the customized editor program) with the restriction that the program will disallow flipping the question/answer buttons in "mid-question" (IE: if the user has just clicked a question button then they must click an answer button before flipping the question/answer buttons). Every time the user clicks a question button a customized event is fired that checks the total number of times the user has clicked a question button (IE: total number of guesses). This customized event handler will show an warning JOptionPane warning message upon the user’s 15th guess and will terminate the game upon the user’s 20th guess.

Complexity of project:

I specifically set out to give this project some "complexity" in two basic ways. The application itself (aside from the Bean aspect) is reasonablt complex in that it handles a good deal of somewhat involved logic (it uses a number of Hashtables/Vectors/arrays, it creates the Swing GUI in a random order (by adding the answer JButtons in a an order determined by a random number routine, allows the user to control the appearance of certain aspects of the GUI (IE: the subject category, "flipping" the question/answer JButtons, restarting the game, etc. I needed to add a good deal of logic in order to implement the "flip-flop" button functionality because the current "state" of the game needed to be preserved (IE: the Hashtables/Vectors/arrays all needed to "flip-flopped" in order to enable the application to "remember" the current state of the game). I believe that I touched on most of the basic elements of the Bean architecture. I coded simple properties, properties that can be "listened to" and "vetoed", coded a custome event handler, coded a custom Property Editor, and coded a BeanInfo class that restricted the properties that the user has access to along with associating the Bean with an Icon.

 

 

Section 2 – Object Model

 

Section 3 – PRE/POST Conditions and JAVADOC output

Click on the following HyperLink to access output from JAVADOC including class/method descriptions and PRE/POST conditions.

MGindex.html

Section 4 – *.java, *.class, *.jpg, *.gif files in zip format

Click on the following HyperLink to access all files needed to execute the application.

beandata.zip