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

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // Oscilator.java        v 1.00 b3
  5. // Written by:           I. van Rienen / E-mail ivr@bart.nl
  6. // URL:                  http://www/bart.nl/~ivr
  7. // Initial release:           v 1.00b1 01-03-1996
  8. //                            v 1.00b3 01-03-1996 Short circuit init bug fixed
  9. // Released in public domain: v 1.00b1 01-03-1996
  10. //
  11. // ---- Description ----
  12. // Java class containing methods for creating and simulating a Oscilator
  13. //
  14. // This program and the Java source is in the public domain.
  15. // Permission to use, copy, modify, and distribute this software
  16. // and its documentation for NON-COMMERCIAL purposes and
  17. // without fee is hereby granted.
  18. //
  19. //    Copyright 1996
  20. //
  21. //    Iwan van Rienen
  22. //    Joan Maetsuyckerstr. 145
  23. //    2593 ZG  The Hague
  24. //    The Netherlands
  25. //
  26. // I am not responsible for any bugs in this program and
  27. // possible damage to hard- or software when using this program.
  28. //****************************************************************************
  29. import java.applet.Applet;
  30. import java.awt.*;
  31. import java.util.Vector;
  32.  
  33. class Oscilator extends ElectronicComponent {
  34.  
  35. //----------------------------------------------------------------------------
  36. // The constructor of a the oscilator
  37. //----------------------------------------------------------------------------
  38.     public Oscilator (Pin PinGrid[][], int x, int y) {
  39.         super (x, y, 8, 6, 1, 1, 4, 4, 0, 1);  // x,y,w,h HitBox x,y,w,h,I,O
  40.         ComponentName = "Oscilator";
  41.         ClassName = "Oscilator";
  42.         OPin[0] = new OutputPin("Q", 7, 3, -2, 0, 0, 0, ComponentPin.PIN_TEXT_INVISIBLE); // name, x, y, w, h, flags
  43.         RegisterPins (PinGrid, x, y);
  44.     }
  45.  
  46. //----------------------------------------------------------------------------
  47. // The constructor of a new Oscilator, which is a copy of CompToCopy
  48. //----------------------------------------------------------------------------
  49.     public Oscilator (ElectronicComponent CompToCopy, int xo, int yo) {
  50.         super (CompToCopy, xo, yo);
  51.     }
  52.  
  53. //----------------------------------------------------------------------------
  54. // Method for copying this component.
  55. //----------------------------------------------------------------------------
  56.     public ElectronicComponent Copy(int xo, int yo) {
  57.         Oscilator NewComponent = new Oscilator(this, xo, yo);
  58.         return NewComponent;
  59.     }
  60.  
  61. //----------------------------------------------------------------------------
  62. // Method for drawing this oscilator
  63. //----------------------------------------------------------------------------
  64.     public void draw(Graphics g, int xp, int yp, int gs) {
  65.         super.draw (g, xp, yp, gs);
  66.         int x = Pos.x - xp;
  67.         int y = Pos.y - yp;
  68.  
  69.         // Draw HitBox and Dimension
  70.         // DrawHitBox(g, x, y, gs);
  71.  
  72.         // Draw O Pins
  73.         DrawOutputPins(g, x, y, gs);
  74.  
  75.         // Draw body
  76.         g.setColor (Color.gray);
  77.         g.drawLine ((x + 2) * gs, (y + 2) * gs, (x + 2) * gs, (y + 4) * gs);
  78.         g.drawLine ((x + 3) * gs, (y + 2) * gs, (x + 3) * gs, (y + 4) * gs);
  79.         g.drawLine ((x + 4) * gs, (y + 2) * gs, (x + 4) * gs, (y + 4) * gs);
  80.         g.setColor (Color.red);
  81.         g.drawLine ((x + 2) * gs, (y + 2) * gs, (x + 3) * gs, (y + 2) * gs);
  82.         g.setColor (Color.green);
  83.         g.drawLine ((x + 3) * gs, (y + 4) * gs, (x + 4) * gs, (y + 4) * gs);
  84.         g.setColor (ComponentColor);
  85.         g.drawRect ((x + 1) * gs, (y + 1) * gs, gs * 4, gs * 4);
  86.     }
  87.  
  88. //----------------------------------------------------------------------------
  89. // This method is simulating the component
  90. //----------------------------------------------------------------------------
  91.     public void SimulateLogic() {
  92.     }
  93.  
  94. //----------------------------------------------------------------------------
  95. // Inform all connected components to this oscilator
  96. //----------------------------------------------------------------------------
  97.     public void Simulate(int id) {
  98. //       System.out.println ("Oscilator simulate()");
  99. //       System.out.println ("Oscilator Simulate() ID= " + id);
  100.         InformConnectedComponents(id);
  101.     }
  102.  
  103. //----------------------------------------------------------------------------
  104. // Init the oscilator before a simulation cycle, toggle the output.
  105. //----------------------------------------------------------------------------
  106.     public void InitBeforeSimulate() {
  107.         OPin[0].InitBeforeSimulate();
  108.         if (OPin[0].getLevel() == 0) {
  109.             OPin[0].Level = 5;
  110.          } else {
  111.             OPin[0].Level = 0;
  112.         }
  113.     }
  114. }