JAVA   24
ICanCount
Guest on 9th February 2023 03:04:25 AM


  1. import objectdraw.*;
  2. import java.awt.*;
  3.  
  4.     // A program to count as high as you can click.
  5. public class ICanCount extends WindowController {
  6.  
  7.         // location where count should be displayed
  8.     private static final Location COUNT_POS = new Location( 100, 100);
  9.  
  10.     private int theCount = 1;   // how high we have counted
  11.     private Text countDisplay;  // current screen display of count
  12.  
  13.         // Create the Text to display the current count
  14.     public void begin() {
  15.         countDisplay = new Text( theCount, COUNT_POS, canvas );
  16.     }
  17.  
  18.         // Increase the count with each click
  19.     public void onMouseClick(Location point) {
  20.         theCount = theCount + 1;
  21.         countDisplay.setText( theCount );
  22.     }
  23. }

Raw Paste

Login or Register to edit or fork this paste. It's free.