⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jycshow.java

📁 一个图形旋转的好例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* JycShow.java
 * writen by eleMent
 * http://member.netease.com/~element
 * kware@sina.com
 * 1998.02.13 JiYuChun at Jinan
 */

import java.awt.*;
import java.applet.*;
import java.net.*;

public class JycShow extends Applet implements Runnable {
  Image img0,img1,img2,img3,img4;
  Image offImage;
  Graphics offGraphics = null;
  int width,height,margin=10;
  MediaTracker tracker;
  Thread engine = null;
  String adInfo;
  final static Color bgColor=new Color(90,222,255);
  boolean loaded = false;
  static int cnt=0;

  public void init() {
    img0 = getImage(getCodeBase(),"element.gif");
    img1 = getImage(getCodeBase(),"jyc.gif");
    img2 = getImage(getCodeBase(),"msvcmm.gif");
    img3 = getImage(getCodeBase(),"cad3ds.gif");
    try {
      URL url = new URL("http://bannerexchange.icq.com/cgi-bin/counter.pl5?uin=7183269");
      img4 = getImage(url);
    } catch (Exception e) {
      img4 = getImage(getCodeBase(),"j_scale.gif");
    }

    adInfo = getParameter("adInfo");
    if (adInfo==null) adInfo = "http://member.netease.com/~element";

    tracker=new MediaTracker(this);
    tracker.addImage(img0,0);
    tracker.addImage(img1,1);
    tracker.addImage(img2,1);
    tracker.addImage(img3,1);
    tracker.addImage(img4,2);

    setBackground(bgColor);
  }

  public void start() {
    if (engine==null) {
      engine = new Thread(this);
      engine.start();
    }
  }

  public void stop() {
    engine = null;
  }

  public void getResource() {
    try {
      tracker.waitForAll();
      loaded = true;
    } catch(InterruptedException e) {
      loaded = false;
    }
  }

  public void getZoom() {
    int w1,h1,w2,h2;
    w1 = img1.getWidth(this);
    h1 = img1.getHeight(this);
    w2 = img2.getWidth(this);
    h2 = img2.getHeight(this);
    width = Math.max(w1, w2);
    height = Math.max(h1, h2);
    width += 2*margin;
    offImage = createImage(width, height);
    //if (offImage!=null) 
    offGraphics = offImage.getGraphics();
  }

  public void delay(int d) {
    try { engine.sleep(d); }
    catch(InterruptedException e) { }
  }

  public void refresh(int dt) {
    Graphics grp = getGraphics();
    if (grp!=null) {
      grp.drawImage(offImage, 0, 0, this);
      delay(dt);
    }
  }

  public void run() {
    if (!loaded) {
      getResource();
      if (!loaded) return;
    }
    if (offGraphics==null) {
      getZoom();
      if (offGraphics==null) return;
    }
    showStatus(adInfo);

    int sw=8;
    while (engine!=null &&
           Thread.currentThread()==engine &&
           engine.isAlive()) {
      switch(sw) {
        case 0: jShow10(); jShow1();  jShow8(1); jShow4(4); break;
        case 1: jShow12(); jShow4(1); jShow9(2); jShow4(2); break;
        case 2: jShow10(); jShow5(1); jShow6();  jShow4(3); break;
        case 3: jShow0(1); jShow7();  jShow2();  jShow9(5); break;
        case 4: jShow10(); jShow4(6); jShow4(5); jShow5(2); break;
        case 5: jShow0(2); jShow3();  jShow9(15);jShow4(7); break;
        case 6: jShow10(); jShow8(2); jShow5(3); jShow4(8); break;
        case 7: jShow0(3); jShow11(1); jShow4(9); jShow11(6); break;
        case 8: jCounter(); break;
      }
      sw = (int)(Math.random()*9);
    }
  }

  private void jShow0(int mode) { // Two direct stretch
    for (int x=0; x<=width/2; x+=2) {
      offGraphics.setClip(0, 0, width, height);
      offGraphics.clearRect(0, 0, width, height);
      switch (mode) {
        case 1:
          offGraphics.setClip(0, 0, width/2, height);
          offGraphics.drawImage(img0, width/2-x, 17, this);
          offGraphics.setClip(width/2, 0, width/2, height);
          offGraphics.drawImage(img0, x-width/2, 17, this);
          break;
        case 2:
          offGraphics.setClip(0, 0, x, height);
          offGraphics.drawImage(img0, x-width/2, 17, this);
          offGraphics.setClip(width-x, 0, x, height);
          offGraphics.drawImage(img0, width/2-x, 17, this);
          break;
        case 3:
          offGraphics.setClip(0, 0, width, x*height/width);
          offGraphics.drawImage(img0, 0, 17+x*height/width-height/2, this);
          offGraphics.setClip(0, height-x*height/width, width, x*height/width);
          offGraphics.drawImage(img0, 0, 17+height/2-x*height/width, this);
          break;
      }
      refresh(10);
    }
    delay(1000);
  }

  private void jShow1() { // Continuous 3 images slide move
    for (int sw=0; sw<3; sw++) {
      for (int x=margin; x<=width-margin; x+=2) {
        offGraphics.setClip(0, 0, width, height);
        offGraphics.clearRect(0,0,width,height);
        offGraphics.drawImage(sw==0?img3:sw==1?img1:img2,x+(width-2*margin), 0, this);
        offGraphics.drawImage(sw==0?img1:sw==1?img2:img3, x, 0, this);
        offGraphics.drawImage(sw==0?img2:sw==1?img3:img1,x-(width-2*margin), 0, this);
        offGraphics.drawImage(sw==0?img3:sw==1?img1:img2,x-2*(width-2*margin), 0, this);
        refresh(10);
      }
    }
    delay(1000);
  }

  private void jShow2() { // Pingpong move
    int x=margin,y=0,dx=5,dy=5,i;
    offGraphics.setClip(0, 0, width, height);
    offGraphics.clearRect(0,0,width,height);
    for (i=0; i<500; i++) {
      offGraphics.setClip(x,y,5,5);
      offGraphics.drawImage(img1,margin,0,this);
      refresh(10);
      x+=dx; y+=dy;
      if (x<margin || x>=width-margin) { dx=-dx; x+=dx; }
      if (y<0 || y>=height) { dy=-dy; x+=dy; }
    }
  }

  private void jShow3() { // Ruber horiz scale
    for (int sw=0; sw<3; sw++) {
      for (int x=0; x<=width-2*margin; x+=2) {
        offGraphics.setClip(0, 0, width, height);
        offGraphics.clearRect(0,0,width,height);
        offGraphics.drawImage(sw==0?img1:sw==1?img2:img3,width/2-x/2,0,x,height,this);
        refresh(10);
      }
      delay(1000);
    }
  }

  private void jShow4(int mode) { // Two direct bar slide move
    for (int sw=0; sw<3; sw++) {
      for (int x=0; x<=width; x+=2) {
        Polygon pg;
        offGraphics.setClip(0, 0, width, height);
        offGraphics.clearRect(0,0,width,height);
        offGraphics.setColor(Color.white);
        offGraphics.drawImage(sw==0?img1:sw==1?img2:img3,margin,0,this);
        switch (mode) {
        case 1:
          pg = new Polygon();
          pg.addPoint(x*(width+height)/width-height, 0);
          pg.addPoint(width, 0);
          pg.addPoint(width, width+height-x*(width+height)/width);
          offGraphics.fillPolygon(pg);
          break;
        case 2:
          pg = new Polygon();
          pg.addPoint(x*(width+height)/width-height, height);
          pg.addPoint(width, height);
          pg.addPoint(width, -width+x*(width+height)/width);
          offGraphics.fillPolygon(pg);
          break;
        case 3:
          pg = new Polygon();
          pg.addPoint(x-width/2, height/2);
          pg.addPoint(width/2, height/2-width+x);
          pg.addPoint(width*3/2-x, height/2);
          pg.addPoint(width/2, height/2+width-x);
          offGraphics.fillPolygon(pg);
          break;
        case 4:
          pg = new Polygon();
          pg.addPoint(0,0);
          pg.addPoint(width/2, x*height/width/2);
          pg.addPoint(width, 0);
          pg.addPoint(width-x/2, height/2);
          pg.addPoint(width, height);
          pg.addPoint(width/2, height-x*height/width/2);
          pg.addPoint(0, height);
          pg.addPoint(x/2, height/2);
          offGraphics.fillPolygon(pg);
          break;
        case 5:
          for (int y=0; y<=height-5; y+=10) {
            offGraphics.fillRect(x,y,width-x,5);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -