Lecture 12

home Contents Index Prev Next

Managing Event, Pop-up, check box, label and Handling Event


model-view observer <- interface requires update method

Observer <- abstract class



Example

class Observer Int extends Observable {

        int value;

            .

            .

            .

        setValue( );

        getValue( );

        i.setValue(i.getValue( ) + 1);// corresponding to C code i=i+1;

}



Managing Event



Events are apart AWT



        mouse down

        mouse up

        mouse rotation

        keyboard action



Example

public Boolean mouseDown(Event e, int x, int y){

	anchor = new Point(x, y);

	return true;

}

	Point anchor;



Example

public Boolean mouseUp(Event e, int x, int y){

       Point rmove = new Point(x - anchor.x, anchor.y - y);



       String objectString = objectMoveChoice.getSelectedItem( );



       if(objectString.equals("Camera")){

           Repaint( );

           return true;

       }

       if(objectString.equals("Camera")){

           Camera c = (Camera)Camera;

           c.auto_Pan = ap_cb.getState( );

           C.change_config( rmove );

           compute_ranges( );

           Repaint( );

           return true;

       }



Pop-Up Option

Example

public class SimpleDraw extends Applet{

       Choice objectMoveChoice;

}

public void add_move_choice_menu( ){

       objectMoveChoice = new choice( );

       objectMoveChoice.addItem("Object Properties");

       add(objectMoveChoice);

}



Example(submethod)

public void create_gui( ){

        setBackground(color.white);

        add_check_boxes( );

        add_label_scrollbars( );

        add_move_comemenu( );



Adding Check Box

Example

        checkbox ap_cb = new checkbox("auto_Pan", null, true);

        //if ap_cb getState( )



        checkbox checkboxes[ ]{ ap_cb, … ,};

        //store into array



public void add_checkBoxes( ){;//add check box

        for(int i=0; i<checkboxes.length; i++){

                add(checkBoxes[i]);

        }



Adding Label

Example

public void add_labels_add_scrollbars( ){

        add(new Label("Rho"));

        rho_l = new Label("45");

        rho_scrollbars = new ScrollBar(ScrollBar.VERTICAL, 

        		set.length.VERTICAL(VX));

        add(rho_l);

        add(rho_scrollbars);

}



Handling Event

Example

public Boolean handling_ScrollBar(Event 'e'){

        double f= f_scrollbars.getValue( )/100;



        f_l.setText(String ValueOf(f));

        c.F = f;

        return true;

}



Example

public Boolean handling Event(Event 'e'){

        if (e.target instanceOfScrollBar){

                return_handel_ScrollBar(e);

        }

        return Super.handelEvent(e);

}








Homework

use code that you wrote last time to add check box to select prof's face,

to add pop up menu to select background some colors, to add scroll bar to 

translate prof's move with your motion.







home Contents Index Prev Next




UBLOGO Last Update: 11/28/96
Copyright © 1996 - Douglas Lyon
Lyon@cse.bridgeport.edu