Docsity

CSI 5342 Project Report: PC Java Implementation - Prof. Paul C. Grabow, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
Noah Sloan
CSI 5342
23 August 2006
Project Report: Final Version
Summary
Assignment
Æ PC Java implementation
Accomplishments
Rabbit Board GUI Interface.
PC State Implementation.
Testing.
Protocol Modifications.
Testing
Documentation.
Process
Overview
The following are the broad strokes. For an example of implementing and
running an application using the framework, please refer to the Walkthrough
and Install-Build documents.
1. The key to implementing a protocol using the framework is the
ApplicationContext interface. All interaction between the framework and your
code is done through the application context. If you successfully implement
an application context (and context factory) then you have satisfied the
framework. See the walkthrough document for more details.
2. In order to implement the ApplicationContext interface, you will also need to
implement a MessageDecoder, which takes an array of bytes and converts it
into a Message object.
3. This means you will have to implement a Message class. To help you, there is
the AbstractMessage class. By sub-classing it, you only need to implement
the application specific parts of a Message such as the data you wish to pass
from MC to PC or vice-versa.
4. You will also need a MessageHandler implementation. Often, the message
handler is also implemented in the ApplicationContext. This may not be
desirable is the amount of code required to handle messages becomes very
large. The message handler simply defines the method by which the
framework hands your application incoming messages.
5. Finally, a ContextFactory must be implemented and specified in the
application.properties file. It is responsible for returning a new instance of the
MC/PC application context.
6. To run your application, you can construct an executable jar files as described
in the Install-Build Guide, or simply type java –cp .:swing-layout-
1.0.jar common.Run in the directory where your compiled class files
and the swing layout jar are located.
pf3

Partial preview of the text

Download CSI 5342 Project Report: PC Java Implementation - Prof. Paul C. Grabow and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

Noah Sloan CSI 5342 23 August 2006

Project Report: Final Version

Summary

Assignment

Æ PC Java implementation

Accomplishments

Rabbit Board GUI Interface. PC State Implementation. Testing. Protocol Modifications. Testing Documentation.

Process

Overview The following are the broad strokes. For an example of implementing and running an application using the framework, please refer to the Walkthrough and Install-Build documents.

  1. The key to implementing a protocol using the framework is the ApplicationContext interface. All interaction between the framework and your code is done through the application context. If you successfully implement an application context (and context factory) then you have satisfied the framework. See the walkthrough document for more details.
  2. In order to implement the ApplicationContext interface, you will also need to implement a MessageDecoder , which takes an array of bytes and converts it into a Message object.
  3. This means you will have to implement a Message class. To help you, there is the AbstractMessage class. By sub-classing it, you only need to implement the application specific parts of a Message such as the data you wish to pass from MC to PC or vice-versa.
  4. You will also need a MessageHandler implementation. Often, the message handler is also implemented in the ApplicationContext. This may not be desirable is the amount of code required to handle messages becomes very large. The message handler simply defines the method by which the framework hands your application incoming messages.
  5. Finally, a ContextFactory must be implemented and specified in the application.properties file. It is responsible for returning a new instance of the MC/PC application context.
  6. To run your application, you can construct an executable jar files as described in the Install-Build Guide, or simply type java –cp .:swing-layout- 1.0.jar common.Run in the directory where your compiled class files and the swing layout jar are located.
  1. We have to be careful with timeouts when using the state pattern in Java, because they must be run as another thread an thusly cannot be reliably killed if another event triggers first, so we do not kill them, but instead force them to check that no other event has occurred. For example, suppose that you created a thread that sleeps for 5 seconds, then changes the state. At the same time, if an event comes, then you change to a different state. Suppose the event arrives before the timeout, but then is interrupted, and the timeout occurs while the other thread is inactive, but is itself interrupted before it can change the state. Then original thread (for the non-timeout event) finished changing the state and shuts down the Timer for the timeout. However, since the timeout thread is already running, it can resume, and then change to the incorrect state! For more details on thread programming in Java, see http://java.sun.com/docs/books/tutorial/essential/threads/

Journal GUI

  1. Using NetBeans, created a new JPanel.
  2. Separated the drawing of the Rabbit Board interface into multiple jpg files.
  3. Used the jpgs as icons on multiple JButtons to recreate the interface as a Swing Application.
  4. For the lights, 2 different icons were generated, 1 brighter than the other. The brighter one was assigned as the JButton’s enabled icon, and the other as the disabled icon. By enabling/disabling the buttons, it appears that the lights go on and off.
  5. Added event listeners for mouse clicks on the real buttons. PC State Implementation
  6. Using the Tic-Tac-Toe project as a guide, a state machine following the MyProtocol specification was implemented.
  7. The class PCMyApplicationContext encapsulates the whole of the MyProtocol implementation.
  8. The class MyProtocolContextFactory was created and specified in the file ‘application.properties’ as the class responsible for the creation of PCMyApplicationContext.
  9. The class Run was created to instantiate an instance of PeripheralController , which reads the configuration file and loads the application.