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

Contents of Doc 27, JFC Errata


References:


Graphic Java, Mastering the JFC Vol. 1: The AWT, Greay, 1999, pp. 263-265

JDK 1.2 On-line API


Listen Here!S-nov23 1min, Q-nov24 1min Doc 27, JFC Errata Slide # 2

JFC Errata

resize() & setSize()

In Doc 24 the method resize( int width, int height ) was used to set the size of the window. This method is deprecated. The method setSize( int width, int height ) instead. Doc 24 has been modified. All occurrences of resize() have been replaced with setSize().

BorderLayout Constants


The BorderLayout does support constants. The example on Doc 24, slide 23 incorrectly used strings, which was how it was done in JDK 1.0. The corrected example is shown below. It has been corrected in Doc 24.

class  BorderLayoutExample  extends Frame  {
   
   public BorderLayoutExample( int  widthInPixels, 
                           int heightInPixels ) {
      setTitle( "BorderLayout Example" );
      setSize( widthInPixels, heightInPixels );
      setLayout( new BorderLayout() );
      
      add(  new Button( "North" ), BorderLayout.NORTH );
      add(  new Button( "Center" ), BorderLayout.CENTER );
      add(  new Button( "East" ), BorderLayout.EAST );
      add(  new Button( "West" ), BorderLayout.WEST );
      add(  new Button( "South" ), BorderLayout.SOUTH );
      show();
   }
   
   public  static  void  main( String  args[] ) {
      new  BorderLayoutExample( 175, 100 );
   }
}

Listen Here!S-nov23 2mins, Q-nov24 2mins Doc 27, JFC Errata Slide # 3

One, Two and Three Button Mice

Java 1.1 supports mice with different number of buttons. It does this by combining a mouse click with modifier keys.

Button pressed
Java reports
Button 1
Mouse clicked
Button 2
Mouse clicked + ALT key pressed
Button 3
Mouse clicked + META key pressed

A user on a platform that does not support a three-button mouse can simulate a three-button mouse by pressing the proper key while clicking the mouse. There is no way to tell if the user pressed button 3 or pressed button 1 with the META key pressed. The example on the next slide illustrates how to check for which button of the mouse was pressed.


Listen Here!S-nov23 1min, Q-nov24 2mins Doc 27, JFC Errata Slide # 4
Mouse Button Example
import java.awt.event.*;
import java.awt.Frame;
class MouseClickExample extends  Frame {
   public MouseClickExample( int left, int top, int width, int height){
      super( "Mouse Click" );
      setSize( width, height );
      setLocation( left, top);
      addMouseListener( new MouseClick(  ) );
      show();
   }
   
   public  static  void  main( String  args[] )   {
       new  MouseClickExample(20, 20, 200, 50);
   }
}
class MouseClick implements MouseListener {
   public void mouseClicked(MouseEvent e)  {
      System.out.println( "Number of clicks " + e.getClickCount());
      System.out.println("Mouse at x: " + e.getX() + " y: "+ e.getY() );
      int modifiers = e.getModifiers();
      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" );
   }
      
   public void mousePressed(MouseEvent e) {};
   public void mouseReleased(MouseEvent e) {};
   public void mouseEntered(MouseEvent e) {};
   public void mouseExited(MouseEvent e) {};
}

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

visitors since 21-Nov-98