Is it possible to change the desktop background with Java for different operating systems?

前端 未结 1 637
暗喜
暗喜 2020-12-17 07:17

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

Can I change my Windows desktop

相关标签:
1条回答
  • 2020-12-17 07:42

    You can just use:

    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
    }
    

    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).

    0 讨论(0)
提交回复
热议问题