/home/wpollock1/public_html/restricted/Java1/TxtCrypt.java
// Java applet to convert entered text into pig-latin.
// This program demonstrates complex GUI methods including
// Panels, Buttons, TextAreas, ..., and using GridBagLayout.
//
// The main task is performed by the "PigLatin.encrypt" method,
// which illustrates String use. (From an idea in "The Visual
// Basic 4 for Windows 95 Handbook" by Gary Cornell, (c)1996 by
// Osborne McGraw-Hill, pp. 316-319.)
//
// Pig Latin words are formed by shifting leading consonants of
// a word to the end, and adding "ay". If the word begins with
// a vowel, just add "way" (no shifting). So "Java" becomes
// "Avajay" while "out" becomes "outway". There are extra rules
// for dealing with "u" and "y". For simplicity this code treats
// hyphens and apostrophes as consonants, so words such as "I'll"
// and "Q-Tip" don't come out quite right.
// Written by Wayne Pollock, Tampa, FL USA, 1999
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class TxtCrypt extends Applet implements ActionListener
{
private TextArea in = new TextArea( 6, 50 );
private TextArea out = new TextArea( 6, 50 );
private Button doit = new Button( "Encrypt" );
private Button clear = new Button( "Clear" );
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
private void makeLabel ( String text, Font font )
{
Label label = new Label( text );
label.setForeground( Color.yellow );
label.setFont( font );
gridbag.setConstraints( label, c );
add( label );
}
public void init ()
{
setBackground( Color.GRAY );
c.gridx = 0;
c.gridwidth = 2;
Insets i = new Insets(0, 10, 0, 10);
c.insets = i;
setLayout( gridbag );
makeLabel( "Text Encryption Program", new Font("Serif", Font.BOLD, 18) );
makeLabel("\u00A9 1999 by Wayne Pollock", new Font("Serif", Font.BOLD, 16) );
c.anchor = GridBagConstraints.WEST;
makeLabel("Plaintext:", new Font("Serif", Font.BOLD, 14) );
c.anchor = GridBagConstraints.SOUTH;
i.bottom = 10;
gridbag.setConstraints( in, c );
in.setBackground ( Color.WHITE );
add(in);
doit.addActionListener( this );
clear.addActionListener( this );
Panel buttonPanel = new Panel();
buttonPanel.setLayout( new FlowLayout() );
buttonPanel.add( doit );
buttonPanel.add( new Label(" ") ); // Just a spacer.
buttonPanel.add( clear );
c.anchor = GridBagConstraints.CENTER;
i.bottom = 1;
gridbag.setConstraints( buttonPanel, c );
add( buttonPanel );
c.anchor = GridBagConstraints.WEST;
makeLabel("Ciphertext:", new Font("Serif", Font.BOLD, 14) );
out.setBackground ( Color.WHITE );
out.setEditable( false );
i.bottom = 15;
gridbag.setConstraints( out, c );
add( out );
i.bottom = 0;
c.gridwidth = 1;
c.gridheight = 2;
c.anchor = GridBagConstraints.NORTHEAST;
makeLabel("Notice:", new Font("Serif", Font.BOLD, 14) );
c.gridx = 1;
c.gridheight = 1;
c.anchor = GridBagConstraints.WEST;
makeLabel("U.S. Federal law may prohibit the use or",
new Font("Serif", Font.PLAIN, 14) );
i.bottom = 5;
c.gridheight = GridBagConstraints.REMAINDER;
c.weighty = 100; c.weightx = 100;
makeLabel("export of this encryption program.",
new Font("Serif", Font.PLAIN, 14) );
in.requestFocus();
}
public void actionPerformed( ActionEvent e )
{
if ( e.getActionCommand().equals( "Encrypt" ) )
{ out.setText( PigLatin.encrypt( in.getText() ) );
} else
{ in.setText( null );
out.setText( null );
}
in.requestFocus();
}
} // End of class TxtCrypt