Technical University of Denmark DTU
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 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)