home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 22 / AMUG_22-1.ISO / Files / Internet / Java / spinalink-3.sit / spindem3 / SpinDemo2.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-22  |  5.6 KB  |  229 lines  |  [Clss/CWIE]

  1. import java.awt.Canvas;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  5. import java.awt.Event;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.Polygon;
  9. import java.awt.image.ImageObserver;
  10.  
  11. class SpinDemo2 extends Canvas {
  12.    SpinDemo1 dad;
  13.    private int valofspin;
  14.    private int incincrease;
  15.    private int maxvalue;
  16.    private int minvalue;
  17.    private boolean cycle;
  18.    String label;
  19.    private boolean looplink;
  20.    private boolean nnmj;
  21.    private boolean mouse_is_down;
  22.    private boolean top_pressed;
  23.    private boolean bot_pressed;
  24.    private Image ghy;
  25.    private Dimension ghjb;
  26.    private Graphics ghyb;
  27.  
  28.    public SpinDemo2(SpinDemo1 owner, int MV, boolean fff) {
  29.       this.looplink = fff;
  30.       this.dad = owner;
  31.       this.top_pressed = false;
  32.       this.nnmj = true;
  33.       this.bot_pressed = false;
  34.       this.valofspin = 1;
  35.       this.incincrease = 1;
  36.       this.maxvalue = MV;
  37.       this.minvalue = 1;
  38.       int widthofbut = 60;
  39.       int heightofbut = 50;
  40.       ((Component)this).resize(widthofbut, heightofbut);
  41.    }
  42.  
  43.    public void paint(Graphics g) {
  44.       if (this.cycle) {
  45.          this.cycle = false;
  46.       } else {
  47.          this.cycle = true;
  48.       }
  49.  
  50.       g.setColor(Color.lightGray);
  51.       g.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  52.       g.setColor(Color.lightGray);
  53.       if (this.dad.bn != null) {
  54.          g.drawImage(this.dad.bn, 0, 0, this);
  55.       }
  56.  
  57.       g.draw3DRect(0, 0, ((Component)this).size().width - 1, ((Component)this).size().height - 1, true);
  58.       g.setColor(Color.black);
  59.       g.drawRect(4, 4, ((Component)this).size().width - 11, ((Component)this).size().height - 10);
  60.       g.drawLine(5, ((Component)this).size().height / 2 - 1, ((Component)this).size().width - 8, ((Component)this).size().height / 2 - 1);
  61.       if (this.nnmj) {
  62.          this.paintUp(g);
  63.          this.ArrowsUp(g);
  64.       } else {
  65.          this.bhytx(g);
  66.       }
  67.  
  68.    }
  69.  
  70.    public void bhytx(Graphics g) {
  71.       this.paintUp(g);
  72.       Dimension d = ((Component)this).size();
  73.       int h = d.height;
  74.       int w = d.width;
  75.       g.setColor(Color.lightGray);
  76.       if (this.top_pressed) {
  77.          g.fillRect(5, 5, ((Component)this).size().width - 12, ((Component)this).size().height / 2 - 6);
  78.          g.setColor(Color.gray);
  79.          g.drawLine(5, 5, ((Component)this).size().width - 7, 5);
  80.          g.drawLine(5, 5, 5, ((Component)this).size().height / 2 - 1);
  81.          if (this.cycle) {
  82.             g.setColor(Color.red);
  83.          } else {
  84.             g.setColor(Color.green);
  85.          }
  86.  
  87.          Polygon nick = new Polygon();
  88.          nick.addPoint(w / 2 - 2 + 1, h / 2 - h / 3 + 1);
  89.          nick.addPoint(w / 2 - w / 4 - 2 + 1, h / 2 - h / 6 + 1);
  90.          nick.addPoint(w / 2 + w / 4 - 2 + 1, h / 2 - h / 6 + 1);
  91.          g.fillPolygon(nick);
  92.          g.drawLine(w / 2 - w / 4 - 2 + 1, h / 2 - h / 6 + 1 + 1, w / 2 + w / 4 - 3 + 1, h / 2 - h / 6 + 1 + 1);
  93.          g.drawLine(w / 2 - w / 4 - 2 + 1, h / 2 - h / 6 + 3 + 1, w / 2 + w / 4 - 3 + 1, h / 2 - h / 6 + 3 + 1);
  94.          g.setColor(Color.red);
  95.          Polygon olis = new Polygon();
  96.          olis.addPoint(w / 2 - 2, h / 2 + h / 3 - 2);
  97.          olis.addPoint(w / 2 - w / 4 - 2 + 1, h / 2 + h / 6 - 1);
  98.          olis.addPoint(w / 2 + w / 4 - 2 - 1, h / 2 + h / 6 - 1);
  99.          g.fillPolygon(olis);
  100.          g.drawLine(w / 2 - w / 4 - 2, h / 2 + h / 6 - 1 - 2, w / 2 + w / 4 - 3, h / 2 + h / 6 - 1 - 2);
  101.          g.drawLine(w / 2 - w / 4 - 2, h / 2 + h / 6 - 1 - 4, w / 2 + w / 4 - 3, h / 2 + h / 6 - 1 - 4);
  102.          if (this.cycle) {
  103.             this.valofspin += this.incincrease;
  104.             if (this.looplink) {
  105.                if (this.valofspin > this.maxvalue) {
  106.                   this.valofspin = 1;
  107.                }
  108.             } else if (this.valofspin > this.maxvalue) {
  109.                this.valofspin = this.maxvalue;
  110.             }
  111.  
  112.             this.dad.testButtonbuttonClicked(this.valofspin);
  113.             this.label = "upper" + this.valofspin;
  114.          }
  115.       } else if (this.bot_pressed) {
  116.          g.fillRect(5, ((Component)this).size().height / 2, ((Component)this).size().width - 12, ((Component)this).size().height / 2 - 6);
  117.          g.setColor(Color.gray);
  118.          g.drawLine(5, ((Component)this).size().height / 2, ((Component)this).size().width - 7, ((Component)this).size().height / 2);
  119.          g.drawLine(5, ((Component)this).size().height / 2, 5, ((Component)this).size().height / 2 + ((Component)this).size().height / 2 - 6);
  120.          if (this.cycle) {
  121.             g.setColor(Color.red);
  122.          } else {
  123.             g.setColor(Color.green);
  124.          }
  125.  
  126.          Polygon oli = new Polygon();
  127.          oli.addPoint(w / 2 - 2 + 1, h / 2 + h / 3 - 2 + 1);
  128.          oli.addPoint(w / 2 - w / 4 - 2 + 1 + 1, h / 2 + h / 6 - 1 + 1);
  129.          oli.addPoint(w / 2 + w / 4 - 2 - 1 + 1, h / 2 + h / 6 - 1 + 1);
  130.          g.drawLine(w / 2 - w / 4 - 2 + 1, h / 2 + h / 6 - 1 - 2 + 1, w / 2 + w / 4 - 3 + 1, h / 2 + h / 6 - 1 - 2 + 1);
  131.          g.drawLine(w / 2 - w / 4 - 2 + 1, h / 2 + h / 6 - 1 - 4 + 1, w / 2 + w / 4 - 3 + 1, h / 2 + h / 6 - 1 - 4 + 1);
  132.          g.fillPolygon(oli);
  133.          g.setColor(Color.red);
  134.          Polygon nicks = new Polygon();
  135.          nicks.addPoint(w / 2 - 2, h / 2 - h / 3);
  136.          nicks.addPoint(w / 2 - w / 4 - 2, h / 2 - h / 6);
  137.          nicks.addPoint(w / 2 + w / 4 - 2, h / 2 - h / 6);
  138.          g.fillPolygon(nicks);
  139.          g.drawLine(w / 2 - w / 4 - 2, h / 2 - h / 6 + 1, w / 2 + w / 4 - 3, h / 2 - h / 6 + 1);
  140.          g.drawLine(w / 2 - w / 4 - 2, h / 2 - h / 6 + 3, w / 2 + w / 4 - 3, h / 2 - h / 6 + 3);
  141.          if (this.cycle) {
  142.             this.valofspin -= this.incincrease;
  143.             if (this.looplink) {
  144.                if (this.valofspin < this.minvalue) {
  145.                   this.valofspin = this.maxvalue;
  146.                }
  147.             } else if (this.valofspin < this.minvalue) {
  148.                this.valofspin = this.minvalue;
  149.             }
  150.  
  151.             this.label = "upper" + this.valofspin;
  152.             this.dad.testButtonbuttonClicked(this.valofspin);
  153.          }
  154.       }
  155.  
  156.       g.setColor(Color.black);
  157.    }
  158.  
  159.    public boolean mouseUp(Event evt, int x, int y) {
  160.       this.nnmj = true;
  161.       this.label = "niether" + this.valofspin;
  162.       this.mouse_is_down = false;
  163.       ((Component)this).repaint();
  164.       this.top_pressed = false;
  165.       this.bot_pressed = false;
  166.       return true;
  167.    }
  168.  
  169.    public final synchronized void update(Graphics g) {
  170.       Dimension d = ((Component)this).size();
  171.       if (this.ghy == null || d.width != this.ghjb.width || d.height != this.ghjb.height) {
  172.          this.ghy = ((Component)this).createImage(d.width, d.height);
  173.          this.ghjb = d;
  174.          this.ghyb = this.ghy.getGraphics();
  175.       }
  176.  
  177.       this.paint(this.ghyb);
  178.       g.drawImage(this.ghy, 0, 0, (ImageObserver)null);
  179.    }
  180.  
  181.    public void paintUp(Graphics g) {
  182.       g.setColor(Color.lightGray);
  183.       g.fill3DRect(5, 5, ((Component)this).size().width - 12, ((Component)this).size().height / 2 - 6, true);
  184.       g.fill3DRect(5, ((Component)this).size().height / 2, ((Component)this).size().width - 12, ((Component)this).size().height / 2 - 6, true);
  185.    }
  186.  
  187.    public void ArrowsUp(Graphics g) {
  188.       Dimension d = ((Component)this).size();
  189.       int h = d.height;
  190.       int w = d.width;
  191.       if (this.cycle) {
  192.          g.setColor(Color.red);
  193.       } else {
  194.          g.setColor(new Color(225, 0, 0));
  195.       }
  196.  
  197.       Polygon nick = new Polygon();
  198.       nick.addPoint(w / 2 - 2, h / 2 - h / 3);
  199.       nick.addPoint(w / 2 - w / 4 - 2, h / 2 - h / 6);
  200.       nick.addPoint(w / 2 + w / 4 - 2, h / 2 - h / 6);
  201.       g.fillPolygon(nick);
  202.       g.drawLine(w / 2 - w / 4 - 2, h / 2 - h / 6 + 1, w / 2 + w / 4 - 3, h / 2 - h / 6 + 1);
  203.       g.drawLine(w / 2 - w / 4 - 2, h / 2 - h / 6 + 3, w / 2 + w / 4 - 3, h / 2 - h / 6 + 3);
  204.       Polygon oli = new Polygon();
  205.       oli.addPoint(w / 2 - 2, h / 2 + h / 3 - 2);
  206.       oli.addPoint(w / 2 - w / 4 - 2 + 1, h / 2 + h / 6 - 1);
  207.       oli.addPoint(w / 2 + w / 4 - 2 - 1, h / 2 + h / 6 - 1);
  208.       g.fillPolygon(oli);
  209.       g.drawLine(w / 2 - w / 4 - 2, h / 2 + h / 6 - 1 - 2, w / 2 + w / 4 - 3, h / 2 + h / 6 - 1 - 2);
  210.       g.drawLine(w / 2 - w / 4 - 2, h / 2 + h / 6 - 1 - 4, w / 2 + w / 4 - 3, h / 2 + h / 6 - 1 - 4);
  211.    }
  212.  
  213.    public boolean mouseDown(Event evt, int x, int y) {
  214.       this.nnmj = false;
  215.       this.mouse_is_down = true;
  216.       ((Component)this).repaint();
  217.       Dimension d = ((Component)this).size();
  218.       if (y <= d.height / 2) {
  219.          this.label = "upper";
  220.          this.top_pressed = true;
  221.       } else {
  222.          this.label = "lower";
  223.          this.bot_pressed = true;
  224.       }
  225.  
  226.       return true;
  227.    }
  228. }
  229.