// Chloe Chao // LexFilters.java // October 20, 1997 import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; import java.io.*; public class LexFilters extends Applet { // Globals and constants private Choice choice; private TextArea textArea; private Button button; private Font font; private FontMetrics fontmetrics; private static final int UPPERCASE = 0; private static final int LOWERCASE = 1; private static final int NOISE = 2; private static final int BLUR = 3; private static final int ENHANCE = 4; public void init() { // Take care of the font info font = new Font("Helvetica", Font.PLAIN, 12); fontmetrics = Toolkit.getDefaultToolkit().getFontMetrics( font ); int gx, gy, cols, rows; gx = 540; gy = 382; cols = (int)((float)(gx-16)/fontmetrics.charWidth('A')) - 1; // subtract 16 for scrollbar rows = (int)((float)gy / fontmetrics.getHeight()) - 3; System.out.println("rows = " + rows + " cols = " + cols ); Panel p = new Panel(); p.setLayout(new GridLayout(0,2)); // Add the choice menu. makeChoice(); p.add("West", choice); // Add the apply button. makeButton(); p.add("East", button); validate(); // Use BorderLayout. BorderLayout b = new BorderLayout(); setLayout(b); // Add the textArea. makeTextArea(rows, cols); add( "North", textArea ); add( "South", p ); validate(); }// end init() public void paint( Graphics g ) { paintComponents(g); }// end paint() public boolean handleEvent(Event e) { if (e.target == button) { String toBeChanged = textArea.getText(); textArea.setText(change(toBeChanged, choice.getSelectedIndex() )); repaint(); return true; } else return false; } // Add according to 'chloe chao'. // if c then add h // if h then add l or a // and so on. private String addNoise( String input ) { StringBuffer output = new StringBuffer( input ); for( int i=0; i 0 ) output.insert( ++i, 'l' ); else output.insert( ++i, 'a' ); break; case 'l': case 'a': output.insert( ++i, 'o' ); break; case 'o': output.insert( ++i, 'e' ); break; default: break; }// switch } return output.toString(); } private String addBlur( String input ) { StringBuffer output = new StringBuffer( input ); for( int i=0; i