FileDocCategorySizeDatePackage
Rot13.javaAPI DocExample1987Mon Mar 24 02:04:32 GMT 1997None

Rot13

public class Rot13 extends Frame

Fields Summary
TextArea
ta
Component
rotate
Component
done
Constructors Summary
public Rot13()

        super ("Rot-13 Example");
        add ("North", new Label ("Enter Text to Rotate:"));
        ta = (TextArea)(add ("Center", new TextArea (5, 40)));
        Panel p = new Panel ();
        rotate = p.add (new Button ("Rotate Me"));
        done = p.add (new Button ("Done"));
        add ("South", p);
    
Methods Summary
public booleanaction(java.awt.Event e, java.lang.Object o)

        if (e.target == rotate) {
            ta.setText (rot13Text (ta.getText()));
            return true;
        } else if (e.target == done) {
            hide();
            dispose();
            System.exit (0);
        }
        return false;
    
public booleanhandleEvent(java.awt.Event e)

        if (e.id == Event.WINDOW_DESTROY) {
            hide();
            dispose();
            System.exit (0);
            return true;
        }
        return super.handleEvent (e);
    
public static voidmain(java.lang.String[] args)

        Rot13 rot = new Rot13();
        rot.pack();
        rot.show();
    
java.lang.Stringrot13Text(java.lang.String s)

        int len = s.length();
        StringBuffer returnString = new StringBuffer (len);
        char c;
        for (int i=0;i<len;i++) {
            c = s.charAt (i);
            if (((c >= 'A") && (c <= 'M")) ||
                ((c >= 'a") && (c <= 'm")))
                c += 13;
            else if (((c >= 'N") && (c <= 'Z")) ||
                ((c >= 'n") && (c <= 'z")))
                c -= 13;
            returnString.append (c);
        }
        return returnString.toString();