JAVA 11
Clickcount.java Guest on 26th September 2020 07:11:26 PM
  1. /*
  2.        Import all matching classes: the standard Applet and Abstract Window
  3.        Toolkit classes.
  4. */
  5.  
  6. import java.applet.*;
  7. import java.awt.*;
  8.  
  9. /*
  10.       Declare class "clickcount" as a subclass of class "Applet"
  11. */
  12. public class clickcount extends Applet
  13. { /* start class clickcount */
  14.   int count ;
  15.   TextField f;
  16.  
  17.       /*
  18.             This code builds the display of the applet (Figure  37.3)
  19.             It redefines "init"
  20.       */
  21.   public void init ()
  22.   { /* start init */
  23.     count = 0;
  24.        /*
  25.              Create an instance of "Button" and add it to the applet's
  26.              window.
  27.        */
  28.     add(new Button ("Click Here") );
  29.     f = new TextField ("   The button has not been clicked at all.");
  30.     f.setEditable(false);
  31.     add(f);  /* Associate f with the applet window. */
  32.   } /* stop init  */
  33.  
  34.       /*
  35.             This code redefines "action."  It determines the action performed
  36.             when the user clicks on the button.
  37.       */
  38.   public boolean action (Event e, Object arg)
  39.   { /* start action  */
  40.      if ( ( (Button) e.target).getLabel() == "Click Here")
  41.      {/* start if  */
  42.         count += 1;
  43.         f.setText ("     The button has been clicked " + count + " times.");
  44.      }/* stop if  */
  45.      return true;
  46.   } /* stop action  */
  47.  
  48. }/* stop class clickcount */

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

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