mport greenfoot.*;
/**
* a world to demonstrate Ceasar Ciphering
*/
public class CipherWorld extends World
{
private Textbox textboxA, textboxB; // the text boxes
private int codeKey; // the cipher key
/** prepares world */
public CipherWorld()
{
super(380, 500, 1);
addObject(textboxA = new Textbox(), getWidth()/2, 40);
addObject(textboxB = new Textbox(), getWidth()/2, 80);
}
/** processes keyboard input and maintains string values of textboxes */
public void act()
{
String key = Greenfoot.getKey();
if (key != null)
{
if ("space".equals(key)) key = " ";
if ("backspace".equals(key) && textboxA.getText().length() > 0)
{
String text = textboxA.getText();
text = text.substring(0, text.length()-1);
textboxA.setText(text);
}
if ("escape".equals(key)) textboxA.setText("");
if ("up".equals(key)) codeKey = (codeKey+1)%26;
if ("down".equals(key)) codeKey = (codeKey+25)%26;
if (key.length() == 1) textboxA.setText(textboxA.getText()+key);
