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

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // BiColorLED.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 Bi color LED
  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 BiColorLED extends ElectronicComponent {
  33.     final static Color LEDColorOff = Color.gray;
  34.  
  35. //----------------------------------------------------------------------------
  36. // The constructor of a new bi-color LED
  37. //----------------------------------------------------------------------------
  38.     public BiColorLED (Pin PinGrid[][], int x, int y) {
  39.         super (x, y, 9, 4, 4, 1, 2, 2, 2, 0);  // x,y,w,h HitBox x,y,w,h,I,O
  40.         ComponentName = "Bi-color LED (Light Emitting Diode)";
  41.         ClassName = "Bi-Color LED";
  42.         IPin[0] = new InputPin("A", 1, 2, 3, 0, 0, 0, ComponentPin.PIN_TEXT_INVISIBLE); // name, x, y, w, h, flags
  43.         IPin[1] = new InputPin("B", 8, 2, -2, 0, 0, 0, ComponentPin.PIN_TEXT_INVISIBLE); // name, x, y, w, h, flags
  44.         RegisterPins (PinGrid, x, y);
  45.     }
  46.  
  47. //----------------------------------------------------------------------------
  48. // The constructor of a bi-color LED, which is a copy of CompToCopy
  49. //----------------------------------------------------------------------------
  50.     public BiColorLED (ElectronicComponent CompToCopy, int xo, int yo) {
  51.         super (CompToCopy, xo, yo);
  52.     }
  53.  
  54. //----------------------------------------------------------------------------
  55. // Method for copying this component.
  56. //----------------------------------------------------------------------------
  57.     public ElectronicComponent Copy(int xo, int yo) {
  58.         BiColorLED NewComponent = new BiColorLED(this, xo, yo);
  59.         return NewComponent;
  60.     }
  61.  
  62. //----------------------------------------------------------------------------
  63. // Method for drawing this bi-color LED
  64. //----------------------------------------------------------------------------
  65.     public void draw(Graphics g, int xp, int yp, int gs) {
  66.         super.draw (g, xp, yp, gs);
  67.         int x = Pos.x - xp;
  68.         int y = Pos.y - yp;
  69.  
  70.         // Draw HitBox and Dimension
  71.         // DrawHitBox(g, x, y, gs);
  72.  
  73.         // Draw all I Pins
  74.         DrawInputPins(g, x, y, gs);
  75.  
  76.         // Draw body
  77.         if (IPin[0].getLevel() == 5 && IPin[1].getLevel() == 0) {
  78.             g.setColor (Color.red);
  79.         } else if (IPin[0].getLevel() == 0 && IPin[1].getLevel() == 5) {
  80.             g.setColor (Color.green);
  81.         } else {
  82.             g.setColor (LEDColorOff);
  83.         }
  84.         g.fillOval ((x + 4) * gs, (y + 1) * gs, 2 * gs + 1, 2 * gs + 1);
  85.         g.setColor (Color.white);
  86.         g.drawOval ((x + 4) * gs, (y + 1) * gs, 2 * gs, 2 * gs);
  87.     }
  88.  
  89. //----------------------------------------------------------------------------
  90. // Initialize all inputs before simulating with level -1.
  91. // This prevent the LED is lightning when there's no potential to the pins.
  92. //----------------------------------------------------------------------------
  93.     public void InitBeforeSimulate() {
  94.         IPin[0].InitBeforeSimulate();
  95.         IPin[1].InitBeforeSimulate();
  96.         IPin[0].setLevel (-1);
  97.         IPin[1].setLevel (-1);
  98.     }
  99.  
  100. }