hoxisoft(hoxisoft) :可以先不看我的源代码三,帮帮忙。

解决方案 »

  1.   

    因为你的代码的缘故,改了之后的效果你看看,如果得到你的效果就再改改,应该不难,如下是俺修改过的代码:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.image.*;class myIcon implements Icon//实现图标
    {
            //大框图
            private double scale;
            private int startX=3;
            private int startY=3;
            private double width;
            private double height;
            //网络故障二层
            private double nWidth;
            private double nHeight;
            private int nStartx;
            private int nStarty;
            //电力故障三层
            private double eWidth;
            private double eHeight;
            private int eStartx;
            private int eStarty;
            //顶层
            //硬件故障一列
            private double hWidth;
            private double hHeight;
            private int hStartx;
            private int hStarty;
            //软件故障二列
            private double sWidth;
            private double sHeight;
            private int sStartx;
            private int sStarty;
            //更新故障二列
            private double uWidth;
            private double uHeight;
            private int uStartx;
            private int uStarty;        //和个模块的颜色
            private Color  OK_COLOR=Color.green;
            private Color  NULL_COLOR=Color.lightGray;
            private Color  eColor= Color.black;
            private Color  nColor=Color.red;
            private Color  hColor=Color.orange;
            private Color  sColor=Color.white;
            private Color  uColor=Color.pink;        myIcon(double a)
            {
                    //大框图
                    scale=a;
                    width=100.0/scale;
                    height=200.0/scale;
                    //网络故障二层
                    nWidth=width;
                    nHeight=height/3;
                    nStartx=startX;
                    nStarty=startY+(int)nHeight;
                    //电力故障三层
                    eWidth=width;
                    eHeight=height-height*2/3+2;
                    eStartx=startX;
                    eStarty=nStarty+(int)nHeight;
                    //顶层//硬件故障一列
                    hWidth=width/3;
                    hHeight=nHeight;
                    hStartx=startX;
                    hStarty=startY;
                    //软件故障二列
                    sWidth=width/3;
                    sHeight=nHeight;
                    sStartx=hStartx+(int)hWidth;
                    sStarty=startY;
                    //更新故障二列
                    uWidth=width-hWidth-sWidth+2;
                    uHeight=nHeight;
                    uStartx=sStartx+(int)hWidth;
                    uStarty=startY;
            }
            public int getIconWidth(){return (int)width+3;}
            public int getIconHeight(){return (int)height+3;}
            public void paintIcon(Component c,Graphics g,int x,int y)
            {
                    g.drawRect(startX,startY,(int)width,(int)height);                g.setColor(nColor);
                    g.fillRect(nStartx,nStarty,(int)nWidth,(int)nHeight);                g.setColor(eColor);
                    g.fillRect(eStartx,eStarty,(int)eWidth,(int)eHeight);                g.setColor(hColor);
                    g.fillRect(hStartx,hStarty,(int)hWidth,(int)hHeight);                g.setColor(sColor);
                    g.fillRect(sStartx,sStarty,(int)sWidth,(int)sHeight);                g.setColor(uColor);
                    g.fillRect(uStartx,uStarty,(int)uWidth,(int)uHeight);                g.draw3DRect(startX-1,startY-1,(int)width+1,(int)height+1,true);
                    g.draw3DRect(startX-2,startY-2,(int)width+2,(int)height+2,true);
                    g.draw3DRect(startX-3,startY-3,(int)width+3,(int)height+3,true);
            }
    }
    class myPanel extends JPanel
    {
            private Graphics g;
            private ImageIcon icon;
            private Toolkit tool=Toolkit.getDefaultToolkit();
            private myIcon myicon=new myIcon(2.0);        private Point first,last;
            int i=0;
            private int width,height;        JLabel mmm//小的
                   ,lll;//大的
            myPanel(JPanel jp)
            {
                    setLayout(null);
                    icon=new ImageIcon("d.jpg");
                    mmm=new JLabel(myicon);
                    lll=new JLabel(icon);
                    lll.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
                    mmm.setBounds(0,0,myicon.getIconWidth(),myicon.getIconHeight());
                    jp.add(mmm);
                    add(lll);
                    width=icon.getIconWidth();
                    height=icon.getIconHeight();
                    setSize(width,height);
                    mmm.addMouseListener(new MouseAdapter()
                    {
                            public void mousePressed(MouseEvent e)
                            {
                                    first=e.getPoint();
                                    System.out.println("first="+first);
                            }
                            public void mouseReleased(MouseEvent e)
                            {
                            }                }
                    );                //实现小图标的拖动
                    mmm.addMouseMotionListener(new MouseMotionAdapter()
                    {
                            public void mouseDragged(MouseEvent e)
                            {
                                    JLabel ppp=(JLabel)e.getSource();
                                    last=e.getPoint();
                                    System.out.println("last="+last);
                                    ppp.setLocation(ppp.getLocation().x+last.x-first.x,ppp.getLocation().y+last.y-first.y);
                            }
                    }
                    );        }
            public int getWidth(){return width;}
            public int getHeight(){return height;}
    }
    class myView extends JViewport implements AdjustmentListener
    {
            //实现滚屏
            public void adjustmentValueChanged(AdjustmentEvent e)
            {
              if(((JScrollBar)e.getSource()).getName().equals("a"))
                setViewPosition(new Point(getViewPosition().x,e.getValue()));
              else if(((JScrollBar)e.getSource()).getName().equals("b"))
                setViewPosition(new Point(e.getValue(),getViewPosition().y));
              ((JPanel)super.getParent()).repaint();
            }
    }
    public class applet8 extends JFrame
    {
            public applet8()
            {
            addWindowListener(new WindowAdapter()
            {
                    public void windowClosing(WindowEvent e){System.exit(0);}
            }
            );
            }
            public static void main(String args[]) {
                    Toolkit tool=Toolkit.getDefaultToolkit();
                    Dimension screen=tool.getScreenSize();
                    applet8 myform=new applet8();
                    myPanel my=new myPanel((JPanel)myform.getContentPane());
                    myView view=new myView();
                    view.setView(my);
                    JScrollBar ver=new JScrollBar();
                    JScrollBar hor=new JScrollBar();
                    hor.setOrientation(JScrollBar.HORIZONTAL);
                    ver.addAdjustmentListener(view);
                    hor.addAdjustmentListener(view);
                    ver.setName("a");
                    hor.setName("b");
                    myform.setSize(800,600);
                    myform.setLocation(myform.getToolkit().getScreenSize().width/2-myform.getWidth()/2,myform.getToolkit().getScreenSize().height/2-myform.getHeight()/2);
                    myform.getContentPane().add(view,"Center");
                    myform.getContentPane().add(ver,"East");
                    myform.getContentPane().add(hor,"South");
                    myform.show();
            }
    }
      

  2.   

    beyond_xiruo(希偌) 大哥,我还在试,好象还是有点问题。明天晚上我会结分。再次感谢