home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Polygon;
- import java.awt.image.ImageObserver;
-
- class SpinDemo2 extends Canvas {
- SpinDemo1 dad;
- private int valofspin;
- private int incincrease;
- private int maxvalue;
- private int minvalue;
- private boolean cycle;
- String label;
- private boolean looplink;
- private boolean nnmj;
- private boolean mouse_is_down;
- private boolean top_pressed;
- private boolean bot_pressed;
- private Image ghy;
- private Dimension ghjb;
- private Graphics ghyb;
-
- public SpinDemo2(SpinDemo1 owner, int MV, boolean fff) {
- this.looplink = fff;
- this.dad = owner;
- this.top_pressed = false;
- this.nnmj = true;
- this.bot_pressed = false;
- this.valofspin = 1;
- this.incincrease = 1;
- this.maxvalue = MV;
- this.minvalue = 1;
- int widthofbut = 60;
- int heightofbut = 50;
- ((Component)this).resize(widthofbut, heightofbut);
- }
-
- public void paint(Graphics g) {
- if (this.cycle) {
- this.cycle = false;
- } else {
- this.cycle = true;
- }
-
- g.setColor(Color.lightGray);
- g.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- g.setColor(Color.lightGray);
- if (this.dad.bn != null) {
- g.drawImage(this.dad.bn, 0, 0, this);
- }
-
- g.draw3DRect(0, 0, ((Component)this).size().width - 1, ((Component)this).size().height - 1, true);
- g.setColor(Color.black);
- g.drawRect(4, 4, ((Component)this).size().width - 11, ((Component)this).size().height - 10);
- g.drawLine(5, ((Component)this).size().height / 2 - 1, ((Component)this).size().width - 8, ((Component)this).size().height / 2 - 1);
- if (this.nnmj) {
- this.paintUp(g);
- this.ArrowsUp(g);
- } else {
- this.bhytx(g);
- }
-
- }
-
- public void bhytx(Graphics g) {
- this.paintUp(g);
- Dimension d = ((Component)this).size();
- int h = d.height;
- int w = d.width;
- g.setColor(Color.lightGray);
- if (this.top_pressed) {
- g.fillRect(5, 5, ((Component)this).size().width - 12, ((Component)this).size().height / 2 - 6);
- g.setColor(Color.gray);
- g.drawLine(5, 5, ((Component)this).size().width - 7, 5);
- g.drawLine(5, 5, 5, ((Component)this).size().height / 2 - 1);
- if (this.cycle) {
- g.setColor(Color.red);
- } else {
- g.setColor(Color.green);
- }
-
- Polygon nick = new Polygon();
- nick.addPoint(w / 2 - 2 + 1, h / 2 - h / 3 + 1);
- nick.addPoint(w / 2 - w / 4 - 2 + 1, h / 2 - h / 6 + 1);
- nick.addPoint(w / 2 + w / 4 - 2 + 1, h / 2 - h / 6 + 1);
- g.fillPolygon(nick);
- 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);
- 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);
- g.setColor(Color.red);
- Polygon olis = new Polygon();
- olis.addPoint(w / 2 - 2, h / 2 + h / 3 - 2);
- olis.addPoint(w / 2 - w / 4 - 2 + 1, h / 2 + h / 6 - 1);
- olis.addPoint(w / 2 + w / 4 - 2 - 1, h / 2 + h / 6 - 1);
- g.fillPolygon(olis);
- g.drawLine(w / 2 - w / 4 - 2, h / 2 + h / 6 - 1 - 2, w / 2 + w / 4 - 3, h / 2 + h / 6 - 1 - 2);
- g.drawLine(w / 2 - w / 4 - 2, h / 2 + h / 6 - 1 - 4, w / 2 + w / 4 - 3, h / 2 + h / 6 - 1 - 4);
- if (this.cycle) {
- this.valofspin += this.incincrease;
- if (this.looplink) {
- if (this.valofspin > this.maxvalue) {
- this.valofspin = 1;
- }
- } else if (this.valofspin > this.maxvalue) {
- this.valofspin = this.maxvalue;
- }
-
- this.dad.testButtonbuttonClicked(this.valofspin);
- this.label = "upper" + this.valofspin;
- }
- } else if (this.bot_pressed) {
- g.fillRect(5, ((Component)this).size().height / 2, ((Component)this).size().width - 12, ((Component)this).size().height / 2 - 6);
- g.setColor(Color.gray);
- g.drawLine(5, ((Component)this).size().height / 2, ((Component)this).size().width - 7, ((Component)this).size().height / 2);
- g.drawLine(5, ((Component)this).size().height / 2, 5, ((Component)this).size().height / 2 + ((Component)this).size().height / 2 - 6);
- if (this.cycle) {
- g.setColor(Color.red);
- } else {
- g.setColor(Color.green);
- }
-
- Polygon oli = new Polygon();
- oli.addPoint(w / 2 - 2 + 1, h / 2 + h / 3 - 2 + 1);
- oli.addPoint(w / 2 - w / 4 - 2 + 1 + 1, h / 2 + h / 6 - 1 + 1);
- oli.addPoint(w / 2 + w / 4 - 2 - 1 + 1, h / 2 + h / 6 - 1 + 1);
- 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);
- 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);
- g.fillPolygon(oli);
- g.setColor(Color.red);
- Polygon nicks = new Polygon();
- nicks.addPoint(w / 2 - 2, h / 2 - h / 3);
- nicks.addPoint(w / 2 - w / 4 - 2, h / 2 - h / 6);
- nicks.addPoint(w / 2 + w / 4 - 2, h / 2 - h / 6);
- g.fillPolygon(nicks);
- g.drawLine(w / 2 - w / 4 - 2, h / 2 - h / 6 + 1, w / 2 + w / 4 - 3, h / 2 - h / 6 + 1);
- g.drawLine(w / 2 - w / 4 - 2, h / 2 - h / 6 + 3, w / 2 + w / 4 - 3, h / 2 - h / 6 + 3);
- if (this.cycle) {
- this.valofspin -= this.incincrease;
- if (this.looplink) {
- if (this.valofspin < this.minvalue) {
- this.valofspin = this.maxvalue;
- }
- } else if (this.valofspin < this.minvalue) {
- this.valofspin = this.minvalue;
- }
-
- this.label = "upper" + this.valofspin;
- this.dad.testButtonbuttonClicked(this.valofspin);
- }
- }
-
- g.setColor(Color.black);
- }
-
- public boolean mouseUp(Event evt, int x, int y) {
- this.nnmj = true;
- this.label = "niether" + this.valofspin;
- this.mouse_is_down = false;
- ((Component)this).repaint();
- this.top_pressed = false;
- this.bot_pressed = false;
- return true;
- }
-
- public final synchronized void update(Graphics g) {
- Dimension d = ((Component)this).size();
- if (this.ghy == null || d.width != this.ghjb.width || d.height != this.ghjb.height) {
- this.ghy = ((Component)this).createImage(d.width, d.height);
- this.ghjb = d;
- this.ghyb = this.ghy.getGraphics();
- }
-
- this.paint(this.ghyb);
- g.drawImage(this.ghy, 0, 0, (ImageObserver)null);
- }
-
- public void paintUp(Graphics g) {
- g.setColor(Color.lightGray);
- g.fill3DRect(5, 5, ((Component)this).size().width - 12, ((Component)this).size().height / 2 - 6, true);
- g.fill3DRect(5, ((Component)this).size().height / 2, ((Component)this).size().width - 12, ((Component)this).size().height / 2 - 6, true);
- }
-
- public void ArrowsUp(Graphics g) {
- Dimension d = ((Component)this).size();
- int h = d.height;
- int w = d.width;
- if (this.cycle) {
- g.setColor(Color.red);
- } else {
- g.setColor(new Color(225, 0, 0));
- }
-
- Polygon nick = new Polygon();
- nick.addPoint(w / 2 - 2, h / 2 - h / 3);
- nick.addPoint(w / 2 - w / 4 - 2, h / 2 - h / 6);
- nick.addPoint(w / 2 + w / 4 - 2, h / 2 - h / 6);
- g.fillPolygon(nick);
- g.drawLine(w / 2 - w / 4 - 2, h / 2 - h / 6 + 1, w / 2 + w / 4 - 3, h / 2 - h / 6 + 1);
- g.drawLine(w / 2 - w / 4 - 2, h / 2 - h / 6 + 3, w / 2 + w / 4 - 3, h / 2 - h / 6 + 3);
- Polygon oli = new Polygon();
- oli.addPoint(w / 2 - 2, h / 2 + h / 3 - 2);
- oli.addPoint(w / 2 - w / 4 - 2 + 1, h / 2 + h / 6 - 1);
- oli.addPoint(w / 2 + w / 4 - 2 - 1, h / 2 + h / 6 - 1);
- g.fillPolygon(oli);
- g.drawLine(w / 2 - w / 4 - 2, h / 2 + h / 6 - 1 - 2, w / 2 + w / 4 - 3, h / 2 + h / 6 - 1 - 2);
- g.drawLine(w / 2 - w / 4 - 2, h / 2 + h / 6 - 1 - 4, w / 2 + w / 4 - 3, h / 2 + h / 6 - 1 - 4);
- }
-
- public boolean mouseDown(Event evt, int x, int y) {
- this.nnmj = false;
- this.mouse_is_down = true;
- ((Component)this).repaint();
- Dimension d = ((Component)this).size();
- if (y <= d.height / 2) {
- this.label = "upper";
- this.top_pressed = true;
- } else {
- this.label = "lower";
- this.bot_pressed = true;
- }
-
- return true;
- }
- }
-