本文整理汇总了Java中java.awt.Desktop.open方法的典型用法代码示例。如果您正苦于以下问题:Java Desktop.open方法的具体用法?Java Desktop.open怎么用?Java Desktop.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Desktop
的用法示例。
在下文中一共展示了Desktop.open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openExplorer
import java.awt.Desktop; //导入方法依赖的package包/类
/**
* Open an Explorer with the given Path
*
* @param directoryPath - Path to open
* @return Open-Explorer ActionListener
*/
static ActionListener openExplorer(String directoryPath) {
return e -> {
Desktop desktop = Desktop.getDesktop();
try {
desktop.open(new java.io.File(File.ensureDSonEndOfPath(directoryPath)).getAbsoluteFile());
} catch(Exception ex) {
ex.printStackTrace();
ErrorWindow errorWindow = new ErrorWindow(
"Unable to open the File-Explorer with the Directory: " + directoryPath,
ErrorWindow.ERROR_LEVEL_ERROR,
false
);
errorWindow.show();
}
};
}
示例2: doShowFolderInDesktop
import java.awt.Desktop; //导入方法依赖的package包/类
public void doShowFolderInDesktop() {
if (!Desktop.isDesktopSupported()) {
log.warning("Sorry, desktop operations are not supported");
return;
}
try {
Desktop desktop = Desktop.getDesktop();
File f = new File(lastFileName);
if (f.exists()) {
desktop.open(f.getParentFile());
}
} catch (Exception e) {
log.warning(e.toString());
}
}
示例3: runJavac
import java.awt.Desktop; //导入方法依赖的package包/类
private void runJavac() throws IOException, InterruptedException {
//String batchFile = "C:\\Users\\inhoj\\Desktop\\eclipse\\workspace\\The Coder\\run.bat";
String batchFile = "C:\\The Coder\\run.bat";
/*String[] commands = {"cmd.exe", "/c", "C:\\Users\\inhoj\\Desktop\\eclipse\\workspace\\The Coder\\run.bat"};
Process proc = Runtime.getRuntime().exec(commands);*/
/*Display display = new Display();
Program.launch(batchFile);
display.dispose();*/
//File bfile = new File("C:\\Users\\inhoj\\Desktop\\eclipse\\workspace\\The Coder\\run.bat");
File bfile = new File("C:\\The Coder\\run.bat");
Desktop desk = Desktop.getDesktop();
long start = System.currentTimeMillis(); //시작시각
synchronized (desk) {
desk.open(bfile);
Thread.sleep(2000);
}
//Add kill CMD process code after 2s
Runtime rt = Runtime.getRuntime();
rt.exec("taskkill " +"/IM CMD.EXE");
/*
long end = System.currentTimeMillis(); //끝나는 시각
long gap = (int)((end-start)/1000);
System.out.println(gap+"초");
if(gap>3) System.exit(0);*/
//Desktop.getDesktop().open(bfile);
//Desktop.getDesktop().wait(2000);
/*Runtime rt = Runtime.getRuntime();
String batFile = "C:\\Users\\inhoj\\Desktop\\eclipse\\workspace\\The Coder\\run.bat";
Process proc;
try {
proc = rt.exec(batFile);
proc.waitFor();
} catch(Exception e) {
e.printStackTrace();
}*/
//Thread.sleep(1500);
}