就是说,我有一个按钮,在点击这个按钮之前鼠标动作不想监听,在点击按钮之后,才监听鼠标,怎么实现啊

解决方案 »

  1.   

    <input type="button" onclick="script();">
      

  2.   

    加标识,点击之前监听方法直接return。
    点击之后,再让他运行监听方法内的实质内容
      

  3.   

    Swing  就是说没点按钮之前不进行操作,点了之后才开始监听鼠标
      

  4.   

    你说的是java应用程序开发吧!是javase方向,我给你一个实例吧!
      

  5.   


    嗯 好的 十分感谢  我才学java 还不清楚方向,怎么收你发的实例呢
      

  6.   

    public class Example4 extends JFrame implements ActionListener {
    /**
     * @param args
     */
    JTextArea text;
    JButton button;
    JButton button2;
    JButton button3;
    RandomAccessFile inout = null;
    Example4() {
    super("顺序的循环输出");
    Container con = this.getContentPane();
    text = new JTextArea(20, 30);
    text.setBackground(Color.cyan);
    button = new JButton("排序后的数组显示在文本框中");
    button2 = new JButton("清空数据");
    button3 = new JButton("退出");
    button.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
    con.setLayout(new BorderLayout());
    con.setSize(100, 200);
    JScrollPane jsp = new JScrollPane(text);
    con.add(jsp, BorderLayout.NORTH);
    JPanel p=new JPanel();
    p.add(button);
    p.add(button2);
    p.add(button3);
    con.add(p,BorderLayout.SOUTH);
    this.setVisible(true);
    this.pack();
    } public static void main(String[] args) {
    Example4 example = new Example4(); }
    public void actionPerformed(ActionEvent arg0) {
    if (arg0.getSource() == button) {
    long data[] = new long[] { 151, 20, 187, 102, 30, 100, -54, 58, 780 };
    try {
    inout = new RandomAccessFile("test.txt", "rw");
    for (int i = 0; i < data.length; i++) {
    inout.writeLong(data[i]);
    System.out.println("整数文件写入成功!");
    }
    text.setText(null);
    for (int j = data.length - 1; j >= 0; j--) {
    inout.seek(j*8);
    text.append(String.valueOf(inout.readLong()) + " ");


    } } catch (FileNotFoundException e1) {
    System.out.println("文件没有发现异常" + e1);
    } catch (IOException e2) {
    System.out.println("文件读写错误!" + e2);
    } }
    if (arg0.getSource() == button2) {
    text.setText(null);
    }
    if(arg0.getSource()==button3){
    try {
    inout.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    button.removeActionListener(this);
    System.exit(1);
    }
    }
      

  7.   

    不太明白搂主的意思,你是说在点击按钮后开始监听鼠标的动作吗?如果是WEB页面的话,可以写成<input id="b01" type="button" value="Click Me"  onclick="document.body.onmouseover = function() {document.write('MOUSE MOVE!!!!!!!!!!')}">,如果不是WEB页面的话,可以用addEventListener来添加
      

  8.   

            要用这几个函数实现:
           public void mouseExited(MouseEvent en){}
    public void mouseEntered(MouseEvent en){}
    public void mouseReleased(MouseEvent en){}
    public void mousePressed(MouseEvent en){}
    public void mouseClicked(MouseEvent en)
    获得en.getButton()的值,在相应的事件里写入相应的代码,具体的可以参考JDK API。
      

  9.   

    其实你可以做点小操作就行了。比如说,一开始就在监听类中的执行方法里写个if(false值)当然这个值是个静态的引用,里面放你要执行的代码。点击按钮的时候把这个引用改为true。可能行,这只是个临时想法,仅供参考
      

  10.   

    如果是Swing的话,给这个按钮添加一个MouseListener,传入一个MouseAdapter,再实现MouseAdapter里的public void mouseReleased(MouseEvent en){}就行了,关键代码如下: button.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseReleased(MouseEvent e) {
    if (e.isPopupTrigger()) {
    popMenu.show(e.getComponent(), e.getX(),e.getY());
    }
    }
    });