是否可以使用Java为不同的操作系统更改桌面背景? [英] Is it possible to change the desktop background with Java for different operating systems?

查看:75
本文介绍了是否可以使用Java为不同的操作系统更改桌面背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个班级项目的想法,该项目涉及在不同时间更改桌面背景图像.我看到了以下问题:

I have an idea for a class project which involves changing the desktop background image at different times. I saw these questions:

可以更改Windows桌面墙纸吗Java/Groovy中以编程方式进行编程?

以编程方式定期更改桌面墙纸

使用Java本机更改MAC系统的桌面背景访问

所以我知道它可以在特定的操作系统上完成.是否可以在不编写单独程序的情况下针对不同的操作系统进行设置?

So I know it can be done on a specific operating system. Is it possible to set it for different operating systems without writing separate programs?

推荐答案

您可以使用:

String os = System.getProperty("os.name");

确定应用程序在哪个操作系统上运行,并从那里决定要做什么.像这样:

to determine what OS the app is running on, and decide what to do from there. Like so:

if (os.startsWith("Windows")) {
    // includes all Windows versions
} else if (os.startsWith("Mac")) {
    // includes all Mac OS versions
} else {
    // all others
}

我建议查找所有不同的值 os.name 可能必须能够处理尽可能多的值.您可能想对这些值使用枚举,而不是像我一样检查 startsWith .此处是您可能需要的值列表考虑(尽管不是很新).

I suggest looking up all of the different values os.name can have to be able to handle as many as possible. You might want to use enums for these values instead of checking startsWith like I did. Here is a list of values you might want to consider (although not very up to date).

这篇关于是否可以使用Java为不同的操作系统更改桌面背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆