【问题标题】:Program opens all applications程序打开所有应用程序
【发布时间】:2013-04-13 13:05:47
【问题描述】:

在我的程序中,我存储了一个ArrayList 我的所有桌面图标位置。我的问题是,当我单击一个图标时,我的计算机会尝试同时打开所有最后一个程序、文件夹和文件,而我真的只想打开单击的任何内容。我怎样才能让这个打开这个没有启动所有其他程序的错误?

public void executeUserProgram(Point cursorPosition)
{
    for (int i = 0; i < icons_.getIcon().size(); i++)
    {
        if (icons_.getIconDimension().get(i).contains(cursorPosition)) 
        {
            try 
            {
                Desktop.getDesktop().open(
                        new File(icons_.getFilePath().get(i)));
            } 
            catch (IOException e) 
            {
                e.printStackTrace();
            }
        }
    }
}

【问题讨论】:

    标签: java user-interface desktop-application executable


    【解决方案1】:

    您的for 循环在找到图标后仍会继续。在iftry 中添加returnbreak 语句。

    try{
        Desktop.getDesktop().open(new File(icons_.getFilePath().get(i)));
        break;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 2023-01-28
      相关资源
      最近更新 更多