Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 程序打开所有应用程序_Java_User Interface_Desktop Application_Executable - Fatal编程技术网

Java 程序打开所有应用程序

Java 程序打开所有应用程序,java,user-interface,desktop-application,executable,Java,User Interface,Desktop Application,Executable,在我的程序中,我存储了所有桌面图标位置的ArrayList。我的问题是,当我点击一个图标时,我的电脑试图同时打开所有最后的程序、文件夹和文件,而我真的只想打开点击的任何东西。我怎样才能打开这个,而不让其他程序启动 public void executeUserProgram(Point cursorPosition) { for (int i = 0; i < icons_.getIcon().size(); i++) { if (icons_.getIco

在我的程序中,我存储了所有桌面图标位置的
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();
            }
        }
    }
}
public void executeUserProgram(点光标位置)
{
对于(int i=0;i
找到图标后,您的
for
循环仍将继续。在
if
try
中添加
return
break
语句

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