COMP 310
|
HW03: Composition-based Ballworld |
YOUR HW03 SVN REPOSITORY MUST BE AT THE ROOT OF YOUR SVN FOLDERS AND BE CALLED "HW03"!
GUI:
JComboBox is a generic parameterized class, so you will need to declare it like this: JComboBox<TDropListItem> where TDropListItem (you can use whatever name you prefer instead) is the type of entity stored in the JComboBox. You will need to thus parameterize your GUI class as MyGUI<TDropListItem>. The Controller will use IStrategyFac as the generic type when constructing the GUI because that is the type of item to be stored in the JComboBox.
JComboBox.addItem(x) will add the item x to the end of the list while JComboBox.insertAt(x, 0) will add the item x to the beginning of the list.
Be sure to retrieve the selected item (the factory!), not the selected index or text.
Tool-tips: Use the setToolTipText method to set the pop-up tool tip (or set property in Jigloo GUI editor).
Be sure to always check if the text field's text is null before proceeding.
Be sure to always check if the return value from a lambda command is null, which means that an error occurred.
Demo control panel layout is 3 panels and a button in a Flow layout. Each sub-panel is a Grid layout with 1 column and 2 or 4 rows. Students need not replicate this component layout exactly, but it should be something reasonable, i.e. not everything in a row.
Model:
You will need to modify the dynamic class loading code to handle strategies. Can you make the loader more generic so it can be used in more situations without modification? Please see the web page in the Java Resources on dynamic class loading.
Since the IStrategyFac.make() method is assumed to return a valid IUpdateStrategy, then if an error occurs you need to return some valid strategy, e.g. a StraightStrategy. Think very carefully about where this correction would take place. Here's really cute thing to use:
/** * A factory for a beeping error strategy that beeps the speaker every 25 updates. * Either use the _errorStrategyFac variable directly if you need a factory that makes an error strategy, * or call _errorStrategyFac.make() to create an instance of a beeping error strategy. */ private IStrategyFac _errorStrategyFac = new IStrategyFac(){ @Override /** * Make the beeping error strategy * @return An instance of a beeping error strategy */ public IUpdateStrategy make() { return new IUpdateStrategy() { private int count = 0; // update counter @Override /** * Beep the speaker every 25 updates */ public void updateState(Ball context) { if(25 < count++){ java.awt.Toolkit.getDefaultToolkit().beep(); count = 0; } } }; } };
If you use a utility method like"fixName" to save typing by the user, be sure to reconstruct the "fully qualified" class name, which includes the package name.
For those people who have way too much time on their hands and want to try something really nuts, try making this. Warning: This application is quite challenging, though it does technically only use techniques you've already seen. Talk to the instructor for guidance if you want to tackle this project.
© 2017 by Stephen Wong