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

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // TFlipFlop.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 Toggle flip flop
  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 TFlipFlop extends IntegratedCircuit {
  33.  
  34. //----------------------------------------------------------------------------
  35. // The constructor of a new Toggle flip flop
  36. //----------------------------------------------------------------------------
  37.     public TFlipFlop(Pin PinGrid[][], int x, int y) {
  38.         super (x, y, 10, 6, 3, 1, 4, 4, 1, 2);      // x,y,w,h HitBox x,y,w,h,I,O
  39.         IPin[0] = new InputPin("T", 1, 3, 2, 0, 0, 0, ComponentPin.PIN_EDGETRIGGERED); // name, x, y, w, h, flags
  40.         OPin[0] = new OutputPin("Q", 9, 2, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, flags
  41.         OPin[1] = new OutputPin("Q", 9, 4, -2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, flags
  42.         ComponentName = "T-flipflop";
  43.         ClassName = "TFlipFlop";
  44.         RegisterPins (PinGrid, x, y);
  45.     }
  46.  
  47. //----------------------------------------------------------------------------
  48. // The constructor of a new T- flip flop, which is a copy of CompToCopy
  49. //----------------------------------------------------------------------------
  50.     public TFlipFlop (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.         TFlipFlop NewComponent = new TFlipFlop(this, xo, yo);
  59.         return NewComponent;
  60.     }
  61.  
  62. //----------------------------------------------------------------------------
  63. // Here is the code that's simulating the component
  64. //----------------------------------------------------------------------------
  65.     public void SimulateLogic() {
  66.         if (IPin[0].OldLevel == 0 && IPin[0].getLevel() == 5) {
  67. //          System.out.println ("**** Edge triggered");
  68.             // Toggle output
  69.             if (OPin[0].getLevel() == 0) {
  70.                 OPin[0].setLevel (5);
  71.                 OPin[1].setLevel (5);
  72.             } else {
  73.                 OPin[0].setLevel (0);
  74.                 OPin[1].setLevel (0);
  75.             }
  76.         }
  77.         IPin[0].OldLevel = IPin[0].getLevel();
  78.     }
  79.  
  80. //----------------------------------------------------------------------------
  81. // Inform all components connected to the outputs with the OLD level,
  82. // because this is an edge-triggered component
  83. //----------------------------------------------------------------------------
  84.     public void Simulate(int id) {
  85.         InformConnectedComponentsOldLevel(id);
  86.     }
  87.  
  88. }