
Java Art Chapter 0.5. Automatic Wallpapering

From the website:

  Killer Game Programming in Java
  http://fivedots.coe.psu.ac.th/~ad/jg

  Dr. Andrew Davison
  Dept. of Computer Engineering
  Prince of Songkla University
  Hat yai, Songkhla 90112, Thailand
  E-mail: ad@fivedots.coe.psu.ac.th


If you use this code, please mention my name, and include a link
to the website.

Thanks,
  Andrew

============================

When the machine is switched on, the ChangWall.bat batch file starts the 
GoogleWallpaper Java application. The batch file is scheduled on my Windows 
machine by using a freeware crontab utility called Z-Cron (http://www.z-cron.com/).

GoogleWallpaper reads in a text file of words, from words.txt.
It randomly selects one of the words, and queries Googles image search  
using its AJAX Search API to obtain URLs of images that match the word. The data
is returned in JSON format, which is examined.

Another Web access downloads one of the images, scaling and cropping it to match the 
computers screen dimensions. 

Updating the desktop image is the last step, and the only one requiring OS-specific 
functionality. On Windows, this involves changing its registry in three places, 
and requesting a desktop refresh. I use JNA (Java Native Access) to link Java and the OS.



This directory contains:

  * GoogleWallpaper.java
	- does the image search, download, and desktop update

  * WebUtils.java
	- useful support methods 
 
  * words.txt
        - a list of words used for searching Google Images

  * json.jar
       - this is a JAR version of the org.json library
       - from http://www.json.org/java/



There are 2 batch files:

  * compile.bat

  * ChangeWall.bat           // calls GoogleWallPaper

  - both batch files assume that json.jar, jna.jar, and platform.jar 
    are in the local directory

  - ChangeWall.bat assumes words.txt is in the local directory


----------------------------
JNA Installation
https://jna.dev.java.net/

Download jna.jar and platform.jar

----------------------------
json.jar Installation
http://www.json.org/java/

Download the zipped file containing all the source code 
  http://www.json.org/java/json.zip

Unzip, compile, and create a JAR called json.jar:

 - unzip in local directory, creating org\ folder
 - cd org\json
 - javac *.java
 - cd ..\..			// back to local directory
 - jar cvf json.jar org		// creates json.jar

 - you can delete the zip file and the org\ folder
 
----------------------------
Compilation and Execution:

  > compile *.java

  > ChangeWall.bat


----------------------------
Wallpapering Problems

Please read the last section of the report for tips on getting Desktop
wallpapering to work on Windows XP and Windows 7.

---------
Last updated: 27th May 2010
