Desktop Java 类的窗口位置和大小
以下代码使用操作系统设置的应用程序打开一个文本文件。
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] a) {
try {
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
desktop.open(new File("c:\\a.txt"));
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
从这里我可以知道打开的窗口的大小和位置?
感谢您的帮助。
问候。
The following code opens a text file with the application that the operating system has set.
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] a) {
try {
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
desktop.open(new File("c:\\a.txt"));
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
From here, I can know the size and position of the window that opens?
Thanks for the help.
Greetings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不相信有简单的方法。该方法不会返回任何内容,并且打开的窗口无论如何都将是一个完全独立的应用程序。
可能有一种特定于操作系统的方法来查看正在运行的进程并构建一些东西来收集这些信息,但这并不容易。
I do not believe there is a simple way. The method doesn't return anything and window that opens will be a completely separate application anyway.
There might be a way that would be OS specific to look at running processes and build something to collect this information but it would not be easy.
如果您想使用 Java Toolkit 类,那么以下 Java 代码演示了如何获取屏幕尺寸:
在以 Dimension 对象的形式获取屏幕尺寸后,
您可以按如下方式获取高度和宽度:
If you wnat to use the Java Toolkit class, so the following Java code demonstrates how to get the screen size:
After you get the screen size as a Dimension object,
you can get the height and width as follows: