SDSU CS 596 Java Programming
Fall Semester, 1998
Errata
To Lecture Notes Index
© 1998, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 04-Jan-99

Contents of Doc 37, Errata


Doc 37, Errata Slide # 2
This document contains errors and corrections to lecture documents for CS 596 Java Programming. The on-line documents have been modified to correct the errors. Thanks to Gayathri Menon for providing a list of errors in the original on-line documents.

Doc 37, Errata Slide # 3

Doc 15 Slide 23


Output was incorrect

OriginalOutput
import
 sdsu.io.*;
import java.io.*;
class  ReadingFileExample

Corrected VersionOutput
import
 java.io.*;
import sdsu.io.*;
class  ReadingFileExample

Doc 37, Errata Slide # 4

Doc 16 Slide 7

Incorrect variable name used.

Original

      String  macFile  =  ":home:ma:whitney:cs596:grades";
      String currentPlatformFile
           =  gradeFile.replace( ':', File.separatorChar );

Corrected Version

      String  macFile  =  ":home:ma:whitney:cs596:grades";
      String currentPlatformFile
           = macFile.replace( ':', File.separatorChar );

Doc 37, Errata Slide # 5

Doc 21, Slide 13

The following class was missing from the slide:

class ChangeValue extends Thread {
   ExampleFromTheBook myData;
   
   public ChangeValue( ExampleFromTheBook data ) {
      myData = data;
   }
   
   public void run() {
      for ( int  k = 0; k < 5; k++ ) {
         myData.value = k;
         myData.volatileValue = k;
         Thread.yield( );
      }
   }
}


Doc 37, Errata Slide # 6

Doc 22 Slide 7


The constructor in the class ArrayStack was given the incorrect name.

Original

public class ArrayStack implements Stack {
   private float[] elements;
   private int topOfStack = -1;
   
   public Stack( int stackSize )  {
      elements = new float[ stackSize ];
   }

Corrected Version

public class ArrayStack implements Stack {
   private float[] elements;
   private int topOfStack = -1;
   
   public ArrayStack( int stackSize )  {
      elements = new float[ stackSize ];
   }

Doc 37, Errata Slide # 7

Doc 22 Slide 7


Corrected a typo, added parenthesis to a call to constructor of ArrayStack.

Original

   public SynchonizedStack() {
      this( new ArrayStack );
   }

Corrected Version

   public SynchonizedStack() {
      this( new ArrayStack() );
   }

Doc 37, Errata Slide # 8

Adding Components to BorderLayout

class  HelloLabel  extends  Frame {
   public HelloLabel( ) {
      setSize( 100, 100 );
      setLocation( left, top);
      Label hello = new Label( "Hello World" );
      add( hello, BorderLayout.CENTER  );
      show();
   }
}

There are four variations on the format of the add() method to add components to a BorderLayout. In the example above, we can use:

   add( hello, "Center" );
   add("Center", hello);
   add( BorderLayout.CENTER, hello);
   add( hello, BorderLayout.CENTER);

Using BorderLayout.CENTER makes any typos a compile error, while using "Center" makes any typos a run-time error. The former is safer. The on-line API documentation strongly advises that one use the form:

   add( Component, Object)

over the form:

   add( String, Component )
Changes were made to the following Docs and slides to reflect the prefered way to add a component to a BorderLayout
Doc
Slides
24
7, 13, 14, 15, 16, 23
27
2
29
7, 11, 14, 15
30
17, 19


Doc 37, Errata Slide # 9

resize() and setSize()


resize() was replaced with setSize() in the following docs and slides

Doc
Slides
25
8, 11
28
3, 7, 17
31
37


Doc 37, Errata Slide # 10

Doc 27 slide 4


Second InputEvent.BUTTON3_MASK should be InputEvent. BUTTON1_MASK

Original

      if ( (modifiers & InputEvent.BUTTON3_MASK) !=0 )
         System.out.println( "Button 3 clicked" );
      else if ((modifiers & InputEvent.BUTTON2_MASK) !=0 )
         System.out.println( "Button 2 clicked" );
      else if ((modifiers & InputEvent.BUTTON3_MASK) !=0 )
         System.out.println( "Button 1 clicked" );

Corrected Version

      if ( (modifiers & InputEvent.BUTTON3_MASK) !=0 )
         System.out.println( "Button 3 clicked" );
      else if ((modifiers & InputEvent.BUTTON2_MASK) !=0 )
         System.out.println( "Button 2 clicked" );
      else if ((modifiers & InputEvent.BUTTON1_MASK) !=0 )
         System.out.println( "Button 1 clicked" );

Doc 37, Errata Slide # 11

Doc 29 slide 10


Corrected a typo.

Original

A consumed event will not be set to any peer.

Corrected Version

A consumed event will not be sent to any peer.

Doc 37, Errata Slide # 12

Doc 30 slide 19

Contained an example using Java 1.0 event model. Updated the example to use Java 1.1 event model.

Original
class  CardLayoutExample  extends Frame  {
   CardLayout threeCards;
   Panel deck;
         
   public CardLayoutExample( int  widthInPixels, int heightInPixels )
      {
      setTitle( "CardLayoutExample Example" );
      setSize( widthInPixels, heightInPixels );
      setLayout( new BorderLayout() );
      
      threeCards = new CardLayout();
      deck = new Panel();
      deck.setLayout( threeCards );
      deck.add( "Ace", new Button( "Ace" ) );
      deck.add( "King", new Button( "King" ) );
      deck.add( "Queen", new Button( "Queen" ) );
      add( deck, BorderLayout.CENTER );
      add( new Button( "Next" ), BorderLayout.NORTH );
      show();
      }
      
   public boolean action( Event processNow, Object buttonPressed ) {
      if ( buttonPressed.equals( "Next" ) )
         threeCards.next( deck );
      else return super.action( processNow, buttonPressed );
      return true;
      }
      
   public  static  void  main( String  args[] ) {
      new  CardLayoutExample(200, 200);
      }
   }

Corrected Version
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class  CardLayoutExample  extends Frame  {
   CardLayout threeCards;
   Panel deck;
   
   public CardLayoutExample( int  widthInPixels, int heightInPixels ){
      setTitle( "CardLayoutExample Example" );
      setSize( widthInPixels, heightInPixels );
      setLayout( new BorderLayout() );
      
      threeCards = new CardLayout();
      deck = new Panel();
      deck.setLayout( threeCards );
      deck.add( "Ace", new Button( "Ace" ) );
      deck.add( "King", new Button( "King" ) );
      deck.add( "Queen", new Button( "Queen" ) );
      add( deck, BorderLayout.CENTER );
      
      Button next = new Button( "Next" );
      next.addActionListener( new NextListener() );
      
      add( next, BorderLayout.NORTH );
      show();
   }
      
   public  static  void  main( String  args[] ) {
      new  CardLayoutExample(200, 200);
   }
   
   class NextListener implements ActionListener {
      public void actionPerformed( ActionEvent buttonPressed ) {
         threeCards.next( deck );
      }
   }
}

Doc 37, Errata Slide # 13

Doc 31 slide 36


Delete second assignment of password.

Original

      password = new TextField( numberOfColumns );
      password.setEchoChar( '*' );
      password = new TextField( numberOfColumns );
Corrected Version

      password = new TextField( numberOfColumns );
      password.setEchoChar( '*' );

Copyright © 1998 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
All rights reserved.

visitors since 04-Jan-99