BFOIT

Introduction
to Programming

Java

Input Events
mouseclick and keypressed


Introduction




Mouse and Key Events


    class DrawLines extends TurtleGraphicsWindow    
    {

        public void keypressed(int keyNum)
        {
            switch ( keyNum )
            {
                case TGKeyHandler.DOWN:
                    pendown();
                    break;
                case TGKeyHandler.UP:
                    penup();
                    break;
                case '0':
                    setpencolor( Turtle.BLACK );
                    break;
                case '1':
                    setpencolor( Turtle.BLUE );
                    break;
                case '2':
                    setpencolor( Turtle.GREEN );
                    break;
                case '4':
                    setpencolor( Turtle.RED );
                    break;
            }

        } // end keypressed()

        public void mouseclick()
        {
            setxy( mousex(), mousey() );
    
        } // end mouseclick()
    
        public static void main(String[] args)
        {
            DrawLines me = new DrawLines();
        }

    } // end class DrawLines
    
Example 22.1


Summary


Back to Table of Contents
Back to previous Lesson ( Control Flow )
On to next Lesson ( )