Guest
Public paste!

Murrdawg

By: a guest | Mar 21st, 2010 | Syntax: None | Size: 4.66 KB | Hits: 77 | Expires: Never
Copy text to clipboard
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. import javax.swing.*;
  5.  
  6. public class ShiftedCipher extends JFrame implements ActionListener{
  7.     static JTextField encryptcode;
  8.     static JTextField decryptcode;
  9.     JTextArea encryptArea;
  10.     JScrollPane sp_encryptArea;
  11.     JTextArea decryptArea;
  12.     JScrollPane sp_decryptArea;
  13.     JLabel encryptLabel;
  14.     JLabel encryptedLabel;
  15.     JLabel decryptLabel;
  16.     JLabel decryptedLabel;
  17.     static JComboBox select;
  18.     JButton submitButton;
  19.     JTextField key;
  20.     JLabel keyLabel;
  21.     String selected="";
  22.  
  23.     public ShiftedCipher() {
  24.         ShiftedCipherLayout customLayout = new ShiftedCipherLayout();
  25.  
  26.         getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
  27.         getContentPane().setLayout(customLayout);
  28.  
  29.         encryptcode = new JTextField("");
  30.         getContentPane().add(encryptcode);
  31.  
  32.         decryptcode = new JTextField("");
  33.         getContentPane().add(decryptcode);
  34.        
  35.         encryptArea = new JTextArea("Encrypted code will appear here.");
  36.         sp_encryptArea = new JScrollPane(encryptArea);
  37.         getContentPane().add(sp_encryptArea);
  38.        
  39.         decryptArea = new JTextArea("Decrypted code will appear here.");
  40.         sp_decryptArea = new JScrollPane(decryptArea);
  41.         getContentPane().add(sp_decryptArea);
  42.        
  43.        
  44.         encryptLabel = new JLabel("Text to be encrypted:");
  45.         getContentPane().add(encryptLabel);
  46.  
  47.         encryptedLabel = new JLabel("Encrypted Text:");
  48.         getContentPane().add(encryptedLabel);
  49.  
  50.         decryptLabel = new JLabel("Text to be decrypted:");
  51.         getContentPane().add(decryptLabel);
  52.  
  53.         decryptedLabel = new JLabel("Decrypted Text:");
  54.         getContentPane().add(decryptedLabel);
  55.  
  56.         select = new JComboBox();
  57.         select.addActionListener(this);
  58.         submitButton.addActionListener(evt);
  59.         select.addItem("Select");
  60.         select.addItem("Encrypt");
  61.         select.addItem("Decrypt");
  62.         encryptArea.setEditable(false);
  63.         decryptArea.setEditable(false);
  64.         getContentPane().add(select);
  65.  
  66.         submitButton = new JButton("Encode/Decode");
  67.         getContentPane().add(submitButton);
  68.        
  69.  
  70.         key = new JTextField("");
  71.         getContentPane().add(key);
  72.  
  73.         keyLabel = new JLabel("Key:");
  74.         getContentPane().add(keyLabel);
  75.  
  76.         setSize(getPreferredSize());
  77.  
  78.         addWindowListener(new WindowAdapter() {
  79.             public void windowClosing(WindowEvent e) {
  80.                 System.exit(0);
  81.             }
  82.         });
  83.     }
  84.  
  85.         @Override
  86.         public void actionPerformed(ActionEvent event1) {
  87.                
  88.                 selected=(String)select.getSelectedItem();
  89.                 if (selected.equals("Encrypt")){
  90.                         decryptcode.setEditable(false);
  91.                         encryptcode.setEditable(true);
  92.                 }
  93.                 else if (selected.equals("Decrypt")){
  94.                         encryptcode.setEditable(false);
  95.                         decryptcode.setEditable(true);
  96.                 }
  97.                 else if (selected.equals("Select")){
  98.                         encryptcode.setEditable(false);
  99.                         decryptcode.setEditable(false);
  100.                 }
  101.         }
  102.        
  103.  
  104. }
  105.  
  106. class ShiftedCipherLayout implements LayoutManager {
  107.  
  108.     public ShiftedCipherLayout() {
  109.     }
  110.  
  111.     public void addLayoutComponent(String name, Component comp) {
  112.     }
  113.  
  114.     public void removeLayoutComponent(Component comp) {
  115.     }
  116.  
  117.     public Dimension preferredLayoutSize(Container parent) {
  118.         Dimension dim = new Dimension(0, 0);
  119.  
  120.         Insets insets = parent.getInsets();
  121.         dim.width = 1213 + insets.left + insets.right;
  122.         dim.height = 691 + insets.top + insets.bottom;
  123.  
  124.         return dim;
  125.     }
  126.  
  127.     public Dimension minimumLayoutSize(Container parent) {
  128.         Dimension dim = new Dimension(0, 0);
  129.         return dim;
  130.     }
  131.  
  132.     public void layoutContainer(Container parent) {
  133.         Insets insets = parent.getInsets();
  134.  
  135.         Component c;
  136.         c = parent.getComponent(0);
  137.         if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+56,472,40);}
  138.         c = parent.getComponent(1);
  139.         if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+296,472,40);}
  140.         c = parent.getComponent(2);
  141.         if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+112,472,136);}
  142.         c = parent.getComponent(3);
  143.         if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+352,472,120);}
  144.         c = parent.getComponent(4);
  145.         if (c.isVisible()) {c.setBounds(insets.left+48,insets.top+56,208,40);}
  146.         c = parent.getComponent(5);
  147.         if (c.isVisible()) {c.setBounds(insets.left+48,insets.top+112,208,40);}
  148.         c = parent.getComponent(6);
  149.         if (c.isVisible()) {c.setBounds(insets.left+56,insets.top+296,200,32);}
  150.         c = parent.getComponent(7);
  151.         if (c.isVisible()) {c.setBounds(insets.left+56,insets.top+360,200,24);}
  152.         c = parent.getComponent(8);
  153.         if (c.isVisible()) {c.setBounds(insets.left+776,insets.top+56,160,32);}
  154.         c = parent.getComponent(9);
  155.         if (c.isVisible()) {c.setBounds(insets.left+776,insets.top+112,160,24);}
  156.         c = parent.getComponent(10);
  157.         if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+488,72,24);}
  158.         c = parent.getComponent(11);
  159.         if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+488,72,24);}
  160.     }
  161. }