编写一个程序,其中包括一个按钮。当鼠标移到按钮上时,隐藏按钮;当鼠标离开按钮时,显示按钮。

解决方案 »

  1.   

    如果要设置为隐藏我就不知道了,设置为可不可用使用setEnable(boolean)
      

  2.   

    在鼠标按下事件( mouseDown)中 用 button.setVisible(false);
    在鼠标弹起(mouseUp)中用button.setVisible(true);
      

  3.   

    给按钮加个Listener不就行了马
      

  4.   

    +班不爽中,正在做applet,现成的代码改改,帮你实现下,测试通过,代码如下:
    btnFirst_pre.addMouseListener(new MouseAdapter() {
    public void mouseEntered(MouseEvent e) {
    btnFirst_pre.setVisible(false);
    }
    public void mouseExited(MouseEvent e) {
    btnFirst_pre.setVisible(true);
    }
    });鼠标监听就是实现这几个方法:
        /**
         * Invoked when the mouse has been clicked on a component.
         */
        public void mouseClicked(MouseEvent e) {}    /**
         * Invoked when a mouse button has been pressed on a component.
         */
        public void mousePressed(MouseEvent e) {}    /**
         * Invoked when a mouse button has been released on a component.
         */
        public void mouseReleased(MouseEvent e) {}    /**
         * Invoked when the mouse enters a component.
         */
        public void mouseEntered(MouseEvent e) {}    /**
         * Invoked when the mouse exits a component.
         */
        public void mouseExited(MouseEvent e) {}
    想学还是自己看看代码,小问题也贴出来不利于学习