import java.awt.*; import java.awt.event.*; import java.applet.*; //import com.sun.java.swing.*; //import com.sun.java.swing.UIManager; public class crypto extends Applet{// implements ActionListener{ boolean isStandalone = false; String initialS; BorderLayout borderLayout1 = new BorderLayout(); TextArea textArea1 = new TextArea(4,60); Panel panel1 = new Panel(); TextArea textArea2 = new TextArea(4,60); GridLayout gridLayout1 = new GridLayout(3,26); Label[] letterLabels; Label[] freqLabels; TextField[] nextField; public String convertedString(String in){ //perform all substitutions // uses char by char rebuilding // of string, used to use String.replace method String s = in.toUpperCase(); StringBuffer out=new StringBuffer(""); String n; char nextChar,thisChar; int i,index; for (i=0;i'Z') out.append(thisChar); else { index=thisChar-'A'; n=nextField[index].getText().trim().toLowerCase(); if (n.length()>0){ nextChar=n.charAt(0); out.append(nextChar);} else out.append(thisChar);}} return out.toString();} //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public crypto() { } //Initialize the applet public void init() { try { initialS = this.getParameter("initialstring", "lyl fqg tred nten ntrdr'w oq xeur nqoyxtn? eaa ntr tqbzrf"+ "saefrdw beur lqco cynt ntr btybzro sgbzw."); } catch (Exception e) { e.printStackTrace(); } try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } //static { // try { // //UIManager.setLookAndFeel(new com.sun.java.swing.plaf.metal.MetalLookAndFeel()); // //UIManager.setLookAndFeel(new com.sun.java.swing.plaf.motif.MotifLookAndFeel()); // UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel()); // } // catch (Exception e) {} //} //Component initialization private void jbInit() throws Exception { textArea1.setText(initialS); panel1.setLayout(gridLayout1); textArea2.setText(""); textArea2.setEditable(false); // gridLayout1.setRows(3); // gridLayout1.setColumns(26); this.setLayout(borderLayout1); // this.setSize(700,300); int i; letterLabels=new Label[26]; for (i=0;i<26;i++){ letterLabels[i]=new Label(""+((char)((int)'A'+i))); panel1.add(letterLabels[i]);} freqLabels=new Label[26]; for (i=0;i<26;i++){ freqLabels[i]=new Label(""); panel1.add(freqLabels[i]);} nextField=new TextField[26]; for (i=0;i<26;i++){ nextField[i]=new TextField("",1); panel1.add(nextField[i]); // nextField[i].addActionListener(this); } // this.add(textArea1, BorderLayout.NORTH); // this.add(panel1, BorderLayout.CENTER); // this.add(textArea2, BorderLayout.SOUTH); this.add("North",textArea1); this.add("Center",panel1); this.add("South",textArea2); } // public void actionPerformed(ActionEvent e){ public boolean action(Event e,Object o){ boolean b= super.action(e,o); // if (e.getId()==Event.ACTION_EVENT) textArea2.setText(convertedString(textArea1.getText())); return b;}; //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { String pinfo[][] = { {"initialstring", "String", ""}, }; return pinfo; } //Main method /* public static void main(String[] args) { crypto applet = new crypto(); applet.isStandalone = true; Frame frame = new Frame(); frame.setTitle("Applet Frame"); frame.add(applet, BorderLayout.CENTER); applet.init(); applet.start(); // frame.setSize(700,300); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible(true); } */ }