home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / ed8n1t2i / pushbutton.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  4.0 KB  |  99 lines

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // PushButton.java       v 1.00 b1
  5. // Written by:           I. van Rienen / E-mail ivr@bart.nl
  6. // URL:                  http://www/bart.nl/~ivr
  7. // Initial release:
  8. // Released in public domain:
  9. //
  10. // ---- Description ----
  11. // Java class containing methods for a Push button
  12. //
  13. // This program and the Java source is in the public domain.
  14. // Permission to use, copy, modify, and distribute this software
  15. // and its documentation for NON-COMMERCIAL purposes and
  16. // without fee is hereby granted.
  17. //
  18. //    Copyright 1996
  19. //
  20. //    Iwan van Rienen
  21. //    Joan Maetsuyckerstr. 145
  22. //    2593 ZG  The Hague
  23. //    The Netherlands
  24. //
  25. // I am not responsible for any bugs in this program and
  26. // possible damage to hard- or software when using this program.
  27. //****************************************************************************
  28. import java.applet.Applet;
  29. import java.awt.*;
  30. import java.util.Vector;
  31.  
  32. class PushButton extends Switch {
  33.  
  34. //----------------------------------------------------------------------------
  35. // The constructor of a push button
  36. //----------------------------------------------------------------------------
  37.     public PushButton (Pin PinGrid[][], int x, int y) {
  38.         super(PinGrid, x, y);
  39.         ComponentName = "push button";
  40.         ClassName = "PushButton";
  41.         HitBox.y--;
  42.         HitBoxSize.height++;
  43.     }
  44.  
  45. //----------------------------------------------------------------------------
  46. // The constructor of a new push button, which is a copy of CompToCopy
  47. //----------------------------------------------------------------------------
  48.     public PushButton (ElectronicComponent CompToCopy, int xo, int yo) {
  49.         super (CompToCopy, xo, yo);
  50.     }
  51.  
  52. //----------------------------------------------------------------------------
  53. // Method for copying this component.
  54. //----------------------------------------------------------------------------
  55.     public ElectronicComponent Copy(int xo, int yo) {
  56.         PushButton NewComponent = new PushButton(this, xo, yo);
  57.         return NewComponent;
  58.     }
  59.  
  60. //----------------------------------------------------------------------------
  61. // The user clicked on the button.
  62. //----------------------------------------------------------------------------
  63.     public boolean SimMouseDown() {
  64.         SwitchClosed = true;
  65.         return true;
  66.     }
  67.  
  68. //----------------------------------------------------------------------------
  69. // The user release the mouse button
  70. //----------------------------------------------------------------------------
  71.     public boolean SimMouseUp() {
  72.         SwitchClosed = false;
  73.         return true;
  74.     }
  75.  
  76. //----------------------------------------------------------------------------
  77. // Draw this push button
  78. //----------------------------------------------------------------------------
  79.     public void draw(Graphics g, int xp, int yp, int gs) {
  80.         super.draw (g, xp, yp, gs);
  81.         int x = Pos.x - xp;
  82.         int y = Pos.y - yp;
  83.         int Yadd = 0;
  84.         // Draw component
  85.         g.setColor (ComponentColor);
  86.         if (SwitchClosed) {
  87.             g.drawLine ((x + 5) * gs, (y) * gs, (x + 5) * gs, (int)((y + 3.5 ) * gs));
  88.             g.drawLine ((x + 6) * gs, (y) * gs, (x + 6) * gs, (int)((y + 3.25) * gs));
  89.             Yadd = 1;
  90.         } else {
  91.             g.drawLine ((x + 5) * gs, (y) * gs, (x + 5) * gs, (int)((y + 2.25) * gs));
  92.             g.drawLine ((x + 6) * gs, (y) * gs, (x + 6) * gs, (int)((y + 2.5) * gs));
  93.         }
  94.         g.drawLine ((int)((x + 4.5) * gs), (y) * gs, (int)((x + 6.5) * gs), (y ) * gs);
  95.         g.drawLine ((int)((x + 4.5) * gs), (int)((y + 1.5 + Yadd) * gs), (int)((x + 6.5) * gs), (int)((y + 1.5 + Yadd) * gs));
  96.         g.drawLine ((int)((x + 4.5) * gs), (int)((y + 1.5 + Yadd) * gs), (int)((x + 5.5) * gs), (int)((y + .5 + Yadd) * gs));
  97.         g.drawLine ((int)((x + 6.5) * gs), (int)((y + 1.5 + Yadd) * gs), (int)((x + 5.5) * gs), (int)((y + .5 + Yadd) * gs));
  98.     }
  99. }