Previous Slide


Remembering the "State"

Next Slide

AN ALTERNATE APPROACH IS TO USE AN ADDITIONAL VARIABLE TO REMEMBER THE Y COORDINATE OF THE PREVIOUS MOUSE POSITION:


int lastY;

public void mouseMove(int x,int y)  {
    if (y > 65 && lastY <= 65) {
        pen.drawImage(webImage);
        pen.invertRect(0,65,220,65);
    } 
    if (y <= 65 && lastY > 65) {
        pen.drawImage(webImage);
        pen.invertRect(0,0,220,65);
     }
     lastY = y;
}
  • IN JAVA A PAIR OF AMPERSANDS IS USED TO SAY "AND".



The Web:
Technologies and
Techniques


Links to other course pages:


Williams College
Department of Computer Science
This page is part of a section of lecture slides related to " Conditional Instructions in Java " within the topic "Conditionas and Choices in Java". Other slides within this section and other sections of slides for the topic "Conditionas and Choices in Java" can be accessed using the links below.
  • Conditional Instructions in Java
  • A Responsive Image Map
  • Conditional Execution
  • THE "if" STATEMENT
  • Simplifying the Geometry
  • A Simple Conditional Statement
  • Relational Operators
  • MORE COMPLEX CONDITIONS
  • Accounting for the "State"
  • Fixing the "State"
  • Remembering the "State"
  • Conditionals as Choices
  • The "else" Clause
  • Java "Choice" Components
  • "Choice" Components
  • Credits
  • Determining a Choice's Setting
  • Handling "Choice" Events
  • A Bit More History
  • Name that "State"
  • Remembering the Coordinates
  • Updating the Coordinate Variables
  • Resetting the Sliders