以前我用html写的,加载图片。现在我已经用java 画出设备的外观了,而且效果还可以,但是我不知道怎么捕捉鼠标的消息,同时提供不同的tooltip。[email protected]

解决方案 »

  1.   

    //源代码
    import java.applet.Applet;
    import java.awt.Image;
    import java.awt.Graphics;
    import java.awt.Rectangle;
    import java.awt.MediaTracker;
    import java.awt.event.*;
    import java.util.StringTokenizer;
    import java.util.Vector;
    import java.util.Hashtable;
    import java.net.URL;
    import java.awt.image.ImageProducer;
    import java.awt.image.ImageFilter;
    import java.awt.image.CropImageFilter;
    import java.awt.image.FilteredImageSource;
    import java.net.MalformedURLException;
    import java.awt.*;
    public class Mb extends Applet
        implements MouseListener, MouseMotionListener, Runnable {
        
      //********************************* Dim     ***********************************  
      //********************************* Prepare ***********************************
      
      Color ColorDarker(Color c) {
       return c.darker();
      }
      
      Color ColorBrighter(Color c) {
       return c.brighter();
      }
      
      void DrawLed(Graphics g, int x, int y, boolean On) {
    //Led

    int diam = 12;

       Color LedColor;
    Color BgColor = new Color(36, 46, 103);

    if (On) {
    LedColor = Color.green;
    } else {
    LedColor = new Color(198, 195, 198);
    }

    //Draw the Led beveled-outline portion.

    g.setColor(ColorDarker(BgColor));
       g.drawArc(x, y, diam, diam, 45, 180);
       g.setColor(ColorBrighter(BgColor));
    g.drawArc(x, y, diam, diam, 255, 180);

    //Draw the Led fill portion.

    g.setColor(LedColor);
    g.fillOval(x+1, y+1, diam-2, diam-2);

    //Draw the Led reflection and shadow arcs.
    //This first reflection arc lies close to the upper-left edge.

    g.setColor(ColorBrighter(LedColor));
    g.drawArc(x + (diam / 10),
    y + (diam / 10),
    (4 * diam) / 5,
    (4 * diam) / 5,
    80,
    110);

    //These two, smaller arcs are closer to the center of the bulb,
    //but are offset towards the light-source.

    g.setColor(Color.white);
    g.drawArc(x + (diam / 4) + 1,
    y + (diam / 4) + 1,
    (diam) / 4,
    (diam) /4,
    80,
    110);
    g.drawArc(x + (diam / 4) + 2,
    y + (diam / 4) + 2,
    (diam) / 5,
    (diam) / 5,
    80,
    100);

    //This final, shadow arc lies close to the lower-left edge.

    g.setColor(ColorDarker(LedColor));
    g.drawArc(x + (diam / 10),
    y + (diam / 10),
    (3 * diam) / 5,
    (3 * diam) / 5,
    260,
    110);

      }  void DrawTP(Graphics g, int x, int y, boolean On) {
       //Draw TP OnLine and OffLine

    int width = 22;
    int height = 29;

       int b = 6;//bound Space
       int R = 3*(width-2*b)/8+1;
       int r = R/3;
      
       Color RjColor;
       Color BgColor;
      
    if (On) {
    RjColor = new Color(30, 160, 208);
        BgColor = new Color(165, 250, 201);
    } else {
    RjColor = Color.gray;
    BgColor = ColorBrighter(Color.gray);
    }
      
       //Draw outter background
      
       g.setColor(Color.white);
       g.fillRect(x, y, width, height);
       g.setColor(Color.black);
       g.drawRect(x+2, y+2, width-4, height-4);
       g.drawRect(x+3, y+3, width-6, height-6);
       g.setColor(BgColor);
       g.fillRect(x+4, y+4, width-8, height-8);
         
       //Dill inner-RJ45 port
      
       g.setColor(RjColor);
       g.fillRect(x+b, y+b, width-2*b-R/2, height-2*b);
       g.setColor(Color.black);
       g.drawRect(x+b, y+b, width-2*b-R/2, height-2*b);
       g.setColor(RjColor);
       g.fillArc(x+width-b-2*R, y+b+r+1, 2*R, 2*R, 300, 120);
       g.setColor(Color.black);
       g.drawArc(x+width-b-2*R, y+b+r+1, 2*R, 2*R, 300, 120);  }
      
      void DrawFxPort(Graphics g, int x, int y, int diam, Color c) {
       //Draw FxPort OnLine and OffLine
      
       //Draw Outer-bound
      
       g.setColor(Color.black);
       g.drawOval(x, y, diam, diam);
       g.setColor(c);
       g.fillOval(x+1, y+1, diam-2, diam-2);
      }
      
      void DrawFX(Graphics g, int x, int y, boolean On) {
    //Draw FX OnLine and OffLine int width = 22;
    int height = 57;   int b = 6;//bound Space
       int R = (width)/4;
      
       Color RjColor;
       Color BgColor;
      
    if (On) {
    RjColor = new Color(30, 160, 208);
        BgColor = new Color(165, 250, 201);
    } else {
    RjColor = Color.gray;
    BgColor = ColorBrighter(Color.gray);
    }

    //Draw outter background

    g.setColor(Color.white);
    g.fillRect(x, y, width, height);
    g.setColor(Color.black);
    g.drawRect(x+1, y+1, width-2, height-2);
    g.setColor(BgColor);
    g.fillRect(x+2, y+2, width-4, height-4);
      
       //Draw inner FX port
      
       DrawFxPort(g, x+width/2-R, y+2*b, 2*R, RjColor);
       DrawFxPort(g, x+width/2-R, y+height-2*b-2*R, 2*R, RjColor);
      
      }  
      void DrawCcMb(Graphics g, int x, int y, int index, int style, boolean On) {
       //Draw Mb OnLine and OffLine by Style
      
       int width = 47;
       int height = 235;
      
       int b = height/36;
         
       Color MbColor = new Color(36, 46, 103);
      
       g.setColor(Color.white);
       g.drawLine(x, y, x, y+height);//left
       g.drawLine(x, y, x+width, y);//top
      
       g.setColor(ColorDarker(Color.white));
       g.drawLine(x+width, y, x+width, y+height);//right
       g.drawLine(x, y+height, x+width, y+height);//bottom
      
       //Fill BackGrand
      
       g.setColor(MbColor);
       g.fillRect(x+3, y+3, width-5, height-5);
      
       //Draw Caption
       
       g.setColor(Color.white);
       g.drawString(""+index, x+(width-6)/2, y+5*b);
      
    if (On) {
       //Draw TP, FX, Led
      
        DrawTP(g, x+(47-21)/2, y+7*b, false);//22,29
        DrawTP(g, x+(47-21)/2, y+7*b+29+b, true);//22,29
        DrawLed(g, x+4, y+7*b+29+2*b+29+2*b, false);//12
        DrawLed(g, x+4+12+2, y+7*b+29+2*b+29+2*b, false);
    DrawLed(g, x+4+12+2+12+2, y+7*b+29+2*b+29+2*b, true);
    DrawLed(g, x+4, y+7*b+29+2*b+29+2*b+12+2, false);
    DrawLed(g, x+4+12+2, y+7*b+29+2*b+29+2*b+12+2, false);
    DrawLed(g, x+4+12+2+12+2, y+7*b+29+2*b+29+2*b+12+2, false);
    DrawFX(g, x+(47-21)/2, y+7*b+29+2*b+29+2*b+12+2+12+2*b, true);//22,57
    }

      }  
          
      //********************************* Exec    ***********************************//  public void init() {
    // DrawLed(this.getGraphics(), 1, 1, 10, Color.green);
    //  }  public void paint(Graphics g) {
      
       setBackground(Color.gray);
      
       DrawCcMb(this.getGraphics(), 10, 10, 10, 1, true);
       
      }  public void run() {
      
      }
      
      public void mouseDragged(MouseEvent e) {  }
      
      public void mouseMoved(MouseEvent e) {  }
      
      public void mouseClicked(MouseEvent e) {
      
      }
      
      public void mousePressed(MouseEvent e) {
      
      }
     
      public void mouseReleased(MouseEvent e) {
      }
      
      public void mouseEntered(MouseEvent e) {
      }
      
      public void mouseExited(MouseEvent e) {
      }
      
    }
    //html 文档<HTML>
    <HEAD>
    </HEAD>
    <BODY BGCOLOR="000000">
    <CENTER>
    <APPLET
    code = "Mb.class"
    width = "500"
    height = "300"
    >
    alt="你的浏览器不支持java,请安装java插件!"
    </APPLET>
    </CENTER>
    </BODY>
    </HTML>
      

  2.   

    也可以看这里;http://expert.csdn.net/Expert/topic/2630/2630416.xml?temp=9.048098E-02