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

📄 surface.java

📁 风机在线监测系统,采用sqlserver数据库,有问题联系我
💻 JAVA
字号:
package java2d;import java.awt.*;import java.awt.image.BufferedImage;import java.net.URL;import java.net.URLClassLoader;import javax.swing.JPanel;/** * Surface is the base class for the 2d rendering demos.  Demos must * implement the render() method. Subclasses for Surface are * AnimatingSurface, ControlsSurface and AnimatingControlsSurface. */public abstract class Surface extends JPanel {    public String perfStr; // PerformanceMonitor    public String perfStrMa;    public String perfStrMi;    public BufferedImage bimg;    public String name;    public AnimatingSurface animating;    protected long sleepAmount = 500;    protected float max, realdata;    private Toolkit toolkit;    private boolean perfMonitor, outputPerf;    protected Image Digits[];    public Surface() {        setDoubleBuffered(this instanceof AnimatingSurface);        toolkit = getToolkit();        /*  name = this.getClass().getName();          // name = name.substring(name.indexOf(".", 7)+1);             name=name.substring(7,name.length());         */        try {            if (System.getProperty("java2demo.perf") != null) {                perfMonitor = outputPerf = true;            }        } catch (Exception ex) {}        if (this instanceof AnimatingSurface) {            animating = (AnimatingSurface)this;        }        Digits = new Image[12];        for (int i = 0; i < 10; i++) {            Digits[i] = loadImage("java2d/digits/" + i + ".gif");        }        Digits[10] = loadImage("java2d/digits/dot_p.gif");        Digits[11] = loadImage("java2d/digits/dot_a.gif");    }    public void setMonitor(boolean pm) {        perfMonitor = pm;    }    public void setSleepAmount(long amount) {        sleepAmount = amount;    }    public long getSleepAmount() {        return sleepAmount;    }    public Image loadImage(String img) {        URLClassLoader urlLoader = (URLClassLoader)this.getClass().                                   getClassLoader();        URL fileLoc = urlLoader.findResource(img);        Image image = this.getToolkit().createImage(fileLoc);        MediaTracker mt = new MediaTracker(this);        mt.addImage(image, 0);        try {            mt.waitForAll();        } catch (Exception e) {            e.printStackTrace();        }        return image;    }    //parse the data of temperature    public int[] parseF(float data) {        int[] c = new int[4];        String D = "" + data;        int index = D.indexOf('.');        if (index == 1) {            c[0] = 0;            c[1] = Integer.parseInt(D.substring(0, index));            c[2] = Integer.parseInt(D.substring(index + 1, index + 2));            c[3] = Integer.parseInt(D.substring(index + 2, index + 3));        } else if (index == 2) {            c[0] = Integer.parseInt(D.substring(0, 1));            c[1] = Integer.parseInt(D.substring(1, index));            c[2] = Integer.parseInt(D.substring(index + 1, index + 2));            c[3] = Integer.parseInt(D.substring(index + 2, index + 3));        }        return c;    }    public void drawDigit(Graphics2D g2, int digit, int x, int y) {        g2.drawImage(Digits[digit], x, y, 35, 40, this);    }    public void drawDigit(Graphics2D g2, int digit, int x, int y, int w, int h) {        g2.drawImage(Digits[digit], x, y, w, h, this);    }    // ...demos that extend Surface must implement this routine...    public abstract void render(int w, int h, Graphics2D g2);    public void paint(Graphics g) {        Dimension d = getSize();        if (bimg == null) {            bimg = (BufferedImage) createImage(d.width, d.height);        }        Graphics2D g2 = bimg.createGraphics();        render(d.width, d.height, g2);        g2.dispose();        if (bimg != null) {            g.drawImage(bimg, 0, 0, null);            toolkit.sync();        }        if (perfMonitor) {            LogPerformance();        }    }    private void LogPerformance() {        /* if ((frame % REPORTFRAMES) == 0) {             long end = System.currentTimeMillis();             long rel = (end - start);             long tot = (end - orig);             if (frame == 0) {                 perfStr = name + " " + rel+" ms";                 if (animating == null || animating.thread == null) {                     frame = -1;                 }             } else {                 String s1 = Float.toString((REPORTFRAMES/(rel/1000.0f)));         s1 = (s1.length() < 4) ? s1.substring(0,s1.length()) : s1.substring(0,4);         */        max = (realdata > max) ? realdata : max;        perfStr = name + ":" + realdata;        perfStrMa = name + ".Max:" + max;        /*  }          if (outputPerf) {              System.out.println(perfStr);          }          start = end;                 }                 ++frame;         */    }}

⌨️ 快捷键说明

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