如何等待鼠标点击 [英] How to wait for a mouse click

查看:138
本文介绍了如何等待鼠标点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class GameFrameClass extends javax.swing.JFrame  {

    public void MyFunc()
    {
        UserButton.setText(Str);
        UserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UserButtonActionPerformed(evt);
            }
        });
        getContentPane().add(UserButton);
    }

    private void UserButtonActionPerformed(java.awt.event.ActionEvent evt) {

        //print some stuff after mouse click
    }
}

在其他类中,我定义了此函数

In someother class i define this function

void functionAdd()
{
    GameFrameClass gfc = new GameFrameClass()
    gfc.MyFunc()
    System.out.println("PRINT THIS AFTER MOUSE CLICK")  
}

如果有人可以看一下码。我要等待鼠标单击。有没有一种方法可以在单击鼠标后打印System.out.println(在鼠标单击后打印此行)行。现在,这种情况立即发生,我无法等待鼠标单击。有办法吗?除了在UserButtonActionPerformed()函数中执行此操作外。请让我知道。

If someone can look into this code. I want to wait on the mouse click . Is there a way i can print the line System.out.println("PRINT THIS AFTER MOUSE CLICK") after the mouse is being clicked . For now this happens immediately and i am not able to wait for the mouse click . Is there a way of doing it ? Apart from doing it inside the function UserButtonActionPerformed() . Please let me know .

推荐答案

您始终可以通过在同一类中定义UserButtonActionPerformed来等待它。如果是这种情况,那么您就不会遇到遇到的问题

You can always wait in UserButtonActionPerformed by defining it in the same class. If that is the case then you should not have the problem you are facing

这篇关于如何等待鼠标点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆