O O!!!! *Raises hand* A ui for models?
// tha save button
new GreenfootButton("Save","save.png")
{
public void onClick() {
StorageHandler sh = Greenfoot.getStorageHandler();
// we have a local storage?
if(sh != null){
// the background image
GreenfootImage image = getBackground();
// save the background image
sh.setItem("myImage", image.toString());
// display dialog
GreenfootDlg.showInfoMessage("Save image", "The image has been saved.");
} else {
// no local storage
GreenfootDlg.showWarningMessage("Info", "Storage not supported!");
// we can disable this button
setEnabled(false);
}
}
};
// the load button
new GreenfootButton("Load","load.png")
{
public void onClick() {
StorageHandler sh = Greenfoot.getStorageHandler();
// we have a local storage?
if(sh != null){
// get storage object
String data = sh.getItem("myImage");
// check if storage isn't empty
if(data != null) {
GreenfootImage image = new GreenfootImage(data);
setBackground(image);
} else {
// storage was empty
GreenfootDlg.showWarningMessage("No Storage", "Unable to load storage!\nStorage is empty or invalid!");
}
} else {
GreenfootDlg.showWarningMessage("Info", "Storage not supported!");
setEnabled(false);
}
}
};