【问题标题】:Java application double tap won't work when running it in Windows 8 tablet在 Windows 8 平板电脑上运行 Java 应用程序双击将不起作用
【发布时间】:2013-09-05 06:45:20
【问题描述】:

我创建了一个 Java 应用程序,它在 Windows7 操作系统的桌面上运行良好。 我尝试在 Windows 8 环境中运行该程序。我使用的设备是平板电脑。 Java 应用程序已安装并确实运行。但问题在于双击。该程序具有类似于双击和选择项目的功能。 但是在平板电脑中,您必须双击该平板电脑。但是双击该项目将无济于事。它只会在第一次单击时突出显示,但在双击它时,什么也没有。 Windows 8 平板电脑中关于这个的问题可能是什么。 这和 Windows 8 中的 java 有关系吗?

非常感谢任何想法。谢谢

[更新:] 事件代码:

    private void jListItemsMouseClicked(java.awt.event.MouseEvent evt) {                                           
        System.out.println("Product Clicked 1");
        if (evt.getClickCount() == 2) {

            m_ReturnProduct = (ItemsInfo) jListItems.getSelectedValue();
            if (m_ReturnProduct != null) {
                buttonTransition(m_ReturnProduct);
            }
        }
    }   

【问题讨论】:

  • 你在听什么活动?
  • 鼠标点击事件。那么,该事件在 Windows 8 平板电脑中不起作用?
  • 双击鼠标事件?似乎您很幸运它可以在 Windows 7 上运行。您在方法中使用 MouseEvent.getClickCount() 吗?如果您向我们展示一些侦听器的代码,也许会对我们有所帮助
  • 是的,它最初部署在 windows 7-desktop 中。但在 windows8 平板电脑上..什么都没有。我将更新我的帖子以包含我的事件代码
  • 我猜在 Windows 8 上,您在该方法中运行了 2 次,都是 clickcount = 1,这就是为什么没有执行任何操作。你能试试我是真的吗?如果是这样:我可能有解决方法

标签: java windows


【解决方案1】:

看来,Windows 8 平板电脑的 MultiClickInterval 较低。

您可以通过以下行获得该值: Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval")

我的解决方法是,您使用 Timer 和 TimerTask 编写自己的 MultiClickInterval:

您需要一个静态的Map<java.awt.Component, Integer> 来保存每个Component 的点击次数。

public static final Map<java.awt.Component, Integer> MULTI_CLICK_MAP = new HashMap<java.awt.Component, Integer>();

您还需要java.util.Timer

private Timer timer = new Timer();

在方法中,您增加了组件的计数器。当它为 2 时,您执行代码。 TimerTask 将在定义的时间后重置计数器。

您的方法将如下所示:

private void jListItemsMouseClicked(java.awt.event.MouseEvent evt) { 
    Component comp = evt.getComponent();

    //added the component to the map or increase the counter
    if(MULTI_CLICK_MAP.containsKey(comp)) {
        MULTI_CLICK_MAP.put(comp, 1);
    } else {
        int oldCounter = MULTI_CLICK_MAP.get(comp);

        MULTI_CLICK_MAP.put(comp, oldCounter + 1);
    }

    //check for double click
    if (MULTI_CLICK_MAP.get(comp) == 2) {
        MULTI_CLICK_MAP.remove(comp);

        //here is your logic
        m_ReturnProduct = (ItemsInfo) jListItems.getSelectedValue();
        if (m_ReturnProduct != null) {
            buttonTransition(m_ReturnProduct);
        }
    } 
    else {

        //start the TimerTask that resets the counter. this will reset after 1 second (1000 milliseconds)
        this.timer.schedule(new ClickReseter(comp), 1000);
    }

} 

ClickReset 是一个简单的 TimerTask,其中包含 Component

public class ClickReseter extends TimerTask {

    private Component component;

    public ClickReseter(Component component)
    {
        this.component = component;
    }

    @Override
    public void run()
    {
        MULTI_CLICK_MAP.remove(component);

    }

}

我希望这对你有用。它没有测试它!如果您有任何问题,请随时提问。

【讨论】:

  • 我对@9​​87654329@ 是什么感到困惑?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-21
  • 2012-11-30
  • 1970-01-01
  • 2014-09-18
相关资源
最近更新 更多