Newsgroup: it.comp.java
Titolo: cambiare wallpaper in java

vorrei fare un programma in java o in grado di caricare un immagine a
caso da una cartella e impostarlo come sfondo del desktop so ke bisogna
usare le api di win .
qualcuno puo dirmi come si fa?
e come faccio a caricare un immagine a caso?
ho trovato questo codice in c ke cambia lo sfondo del desktop:
#define STRICT
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
typedef enum
{
    WALLPAPER_CENTERED = 0,
    WALLPAPER_TILED,
    WALLPAPER_STRETCHED,
    WALLPAPER_POSITIONED
} WALLPAPER_MODE;
/*
 * SetDesktopWallpaper function
 *
 *   lpszFilename
 *     Filename to use as wallpaper
 *
 *   wpmode
 *     WALLPAPER_CENTERED ....... Centered on the screen
 *     WALLPAPER_TILED .......... Tiled to cover entire screen
 *     WALLPAPER_STRETCHED ...... Stretched to cover entire screen
 *     WALLPAPER_POSITIONED ..... Positioned (use sOffsetX/sOffsetY
arguments)
 *
 *   sOffsetX
 *     Horizontal offset
 *
 *   sOffsetY
 *     Vertical offset
 *
 *
 * Notes for registry values:
 *   Center ---> WallpaperStyle = "0" / TileWallpaper = "0"
 *   Tile -----> WallpaperStyle = "0" / TileWallpaper = "1"
 *   Stretch --> WallpaperStyle = "2" / TileWallpaper = "0"
 */
BOOL SetDesktopWallpaper (LPTSTR lpszFilename, WALLPAPER_MODE wpmode,
SHORT sOffsetX, SHORT sOffsetY)
{
    BOOL    bRet = FALSE;
    LONG    lRet;
    HKEY    hKey;
    DWORD   dwSize;
    LPTSTR  lpszTile, lpszStyle;
    TCHAR   szBuf[16];
    lRet = RegOpenKeyEx (HKEY_CURRENT_USER, _T("Control
Panel\\Desktop"),
                         0, KEY_WRITE, &hKey);
    if (lRet == ERROR_SUCCESS)
    {
        if (wpmode == WALLPAPER_STRETCHED)
            lpszStyle = _T("2");
        else
            lpszStyle = _T("0");
        if (wpmode == WALLPAPER_TILED)
            lpszTile = _T("1");
        else
            lpszTile = _T("0");
        dwSize = (lstrlen (lpszStyle) + 1) * sizeof (TCHAR);
        lRet = RegSetValueEx (hKey, _T("WallpaperStyle"), 0, REG_SZ,
(const BYTE*) lpszStyle, dwSize);
        if (lRet == ERROR_SUCCESS)
        {
            dwSize = (lstrlen (lpszTile) + 1) * sizeof (TCHAR);
            lRet = RegSetValueEx (hKey, _T("TileWallpaper"), 0, REG_SZ,
(const BYTE*) lpszTile, dwSize);
        }
        if (lRet == ERROR_SUCCESS)
        {
            if (wpmode == WALLPAPER_POSITIONED)
            {
                wsprintf (szBuf, _T("%d"), sOffsetX);
                dwSize = (lstrlen (szBuf) + 1) * sizeof (TCHAR);
                lRet = RegSetValueEx (hKey, _T("WallpaperOriginX"), 0,
REG_SZ, (const BYTE*) szBuf, dwSize);
                if (lRet == ERROR_SUCCESS)
                {
                    wsprintf (szBuf, _T("%d"), sOffsetY);
                    dwSize = (lstrlen (szBuf) + 1) * sizeof (TCHAR);
                    lRet = RegSetValueEx (hKey, _T("WallpaperOriginY"),
0, REG_SZ, (const BYTE*) szBuf, dwSize);
                }
            }
            else
            {
                RegDeleteValue (hKey, _T("WallpaperOriginX"));
                RegDeleteValue (hKey, _T("WallpaperOriginY"));
            }
        }
        RegCloseKey (hKey);
        if (lRet == ERROR_SUCCESS)
            bRet = SystemParametersInfo (SPI_SETDESKWALLPAPER, 0,
lpszFilename, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
    }
    return bRet;
}
/*
 * Main function
 *
 * Command line arguments:
 *   <filename> <mode> [<x-offset>] [<y-offset>]
 *
 * Arguments:
 *   <filename> .... filename to use as wallpaper
 *   <mode> ........ "c" for centered
 *                   "t" for tiled
 *                   "s" for stretched
 *                   "p" for positioned
 *   <x-offset> .... Horizontal offset
 *   <y-offset> .... Vertical offset
 *
 * With no arguments, removes the desktop wallpaper
 */
int _tmain (int argc, TCHAR *argv[])
{
    LPTSTR          lpszFilename = _T("");
    WALLPAPER_MODE  wpmode = WALLPAPER_CENTERED;
    SHORT           sOffsetX = 0, sOffsetY = 0;
    if (argc >= 3)
    {
        lpszFilename = argv[1];
        if (_tcscmp (argv[2], _T("c")) == 0)
            wpmode = WALLPAPER_CENTERED;
        else if (_tcscmp (argv[2], _T("t")) == 0)
            wpmode = WALLPAPER_TILED;
        else if (_tcscmp (argv[2], _T("s")) == 0)
            wpmode = WALLPAPER_STRETCHED;
        else if (_tcscmp (argv[2], _T("p")) == 0)
        {
            wpmode = WALLPAPER_POSITIONED;
            if (argc == 5)
            {
                sOffsetX = (SHORT) _ttoi (argv[3]);
                sOffsetY = (SHORT) _ttoi (argv[4]);
            }
        }
    }
    if (SetDesktopWallpaper (lpszFilename, wpmode, sOffsetX, sOffsetY))
        _tprintf (_T("Set desktop wallpaper ok\n"));
    else
        _tprintf (_T("Set desktop wallpaper failed\n"));
    return 0;
}
 puo essere utile?

  puo essere utile?
Oddio... O_o ... a me no!  :-P
CIAO!

 vuoi caricarla...
nn caricarla mi sono espresso male vogli ke il programmino scelga un
immagine a caso da alcune immagini contenutein una cartella
P.S.
il prog dovrebbe rimanere aperto e funzionare in background
sai come si fa?

 sai come si fa?
https://jdic.dev.java.net/#demos
  ... dai un'occhiata a TrayIcon