|
|
|
02115 Java Programming |
Autumn 2011 |
Week plan #12
For the week 21. November - 25. November
Preparations for the week
Remember to study details of the simplesound project -
section 11.9 (pages 376 - 378) of the BK textbook. The
SoundPlayerGUI
class presents some constructs which
might be useful in your implementation of the Mandatory Assignment
Not only exception handling (as suggested on Week plan #11) can
be used as a means of turning back user interface independant
messages. Those messages at the end has to be shown as text
either in a command line interface or in a GUI, e.g. in a message
dialogue:
- Use exceptions as described on Week plan #11
- Introduce error codes, either negative integers or (better)
values from an enum class
- Make your own class MessageHandler equiped with
some public methods to be used when some class needs to turn
back test information, normal messages or error messages.
When one of your classes needs to turn back messages
it just declares it's own private instance of the
message handler and thus get access to the methods of
that class. This class can be combined with use of enum values
Use of auxiliary methods leads to simpler code.
When e.g. many buttons has to be added auxiliary methods should be
declared and used. The idea is introduced based on Code 11.14
of the textbook where two buttons are added to a panel. If many more
components should have been added then introduce an auxiliary method:
private JButton addButton(String text, JPanel toPanel)
{
JButton b = new JButton(text);
toPanel.add(b);
return b;
}
And then we just write these two lines of Java code:
smallerButton = addButton("Smaller", toolbar);
largerButton = addButton("Larger", toolbar);
to achieve the same as done in Code 11.14 using four lines of Java code:
smallerButton = new JButton("Smaller");
toolbar.add(smallerButton);
largerButton = new JButton("Larger";
toolbar.add(largerButton);
In our grading of the GUI's to achieve specific functionalities the
shorter and more readable the code the higher it will be evaluated.
Just because it's about GUI's don't forget to use the principles of
object oriented thinking and how to work out well-structured and
simple solutions instead of just doing copy and paste followed by
editing. Otherwise the result is much duplicated code
The lectures
No lectures
Exercises at the PC's
The exercise session of today starts at 17:00 and ends at 21:00.
The exercise sessions in this week and the next week are dedicated to
your work with the Mandatory Assignment. It's important to have
refactored the model part of the solution so the same model can
be used either with the command line interface or with the GUI
Jens Thyge Kristensen,
Email: jtk@imm.dtu.dk
Newest edition: 15. November
Previous editions:
- 8. April (just the heading and the footing)