Java Reference
In-Depth Information
1.3
A note on code formatting
The following notational conventions are used to address frequent questions from
attendants of courses which the author gave on Swing programming. Some fre-
quently occurring problems are addressed in Appendix B.
In the code listings we sometimes use comments to make the block structure
appear more clearly. Comments are added after the closing braces. This is not
always done but is used if many blocks are nested or there is a lengthy code
segment in a block. Here is an example:
for ( int i=0;i<N;i++){
for ( int j=0;j<N;j++){
if (j < i){
// many statements
}// if
}// for j
}// for i
When calling a method of a graphic component we sometimes unnecessarily add
the key word this to make clear to which component the method belongs. Here
is an example:
public MyPanel(){ // constructor of graphical component
JLabel myLabel = new JLabel("Test"); // another component
this .add(myLabel);
// add the label to this panel
this .setSize(200,200);
// set the size of this panel
// not of the label
}
1.4
A note for teachers
This topic is based on material that the author has used in various courses on
graphical interfaces. Students are assumed to know the basic concepts of Java,
such as classes, inheritance and range of variables. The courses are usually run
before the first large programming project is to be performed. Using a model-view-
control approach has greatly improved the quality of the resulting programs.
For a three-day intensive course Chapters 2 to 8 are appropriate. If additional
features are needed in a follow-up project, the students can easily find them in
the remaining chapters. In a one-week intensive course one can cover Chap-
ters 10 to 14 in addition or include some chapters on more elaborate topics if
needed.
Search WWH ::




Custom Search