Share Pastebin
Guest
Public paste!

Murrdawg

By: a guest | Mar 22nd, 2010 | Syntax: Java | Size: 4.64 KB | Hits: 87 | 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{
  7.     static JTextField encryptcode;
  8.     static JTextField decryptcode;
  9.     static JTextArea encryptArea;
  10.     JScrollPane sp_encryptArea;
  11.     static JTextArea decryptArea;
  12.     JScrollPane sp_decryptArea;
  13.     JLabel encryptLabel;
  14.     JLabel encryptedLabel;
  15.     JLabel decryptLabel;
  16.     JLabel decryptedLabel;
  17.     static JComboBox select;
  18.     static JButton submitButton;
  19.     static JTextField key;
  20.     JLabel keyLabel;
  21.     static 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(new ActionListener() {
  58.                 public void actionPerformed(ActionEvent e){
  59.                         selected=(String)select.getSelectedItem();
  60.                         if (selected.equals("Encrypt")){
  61.                                 decryptcode.setEditable(false);
  62.                                 encryptcode.setEditable(true);
  63.                         }
  64.                         else if (selected.equals("Decrypt")){
  65.                                 encryptcode.setEditable(false);
  66.                                 decryptcode.setEditable(true);
  67.                         }
  68.                         else if (selected.equals("Select")){
  69.                                 encryptcode.setEditable(false);
  70.                                 decryptcode.setEditable(false);
  71.                         }
  72.                 }
  73.         });
  74.        
  75.         select.addItem("Select");
  76.         select.addItem("Encrypt");
  77.         select.addItem("Decrypt");
  78.         encryptArea.setEditable(false);
  79.         decryptArea.setEditable(false);
  80.         getContentPane().add(select);
  81.  
  82.         submitButton = new JButton("Encode/Decode");
  83.         getContentPane().add(submitButton);
  84.        
  85.  
  86.         key = new JTextField("0");
  87.         getContentPane().add(key);
  88.  
  89.         keyLabel = new JLabel("Key:");
  90.         getContentPane().add(keyLabel);
  91.  
  92.         setSize(getPreferredSize());
  93.  
  94.         addWindowListener(new WindowAdapter() {
  95.             public void windowClosing(WindowEvent e) {
  96.                 System.exit(0);
  97.             }
  98.         });
  99.     }
  100.  
  101. }
  102.  
  103. class ShiftedCipherLayout implements LayoutManager {
  104.  
  105.     public ShiftedCipherLayout() {
  106.     }
  107.  
  108.     public void addLayoutComponent(String name, Component comp) {
  109.     }
  110.  
  111.     public void removeLayoutComponent(Component comp) {
  112.     }
  113.  
  114.     public Dimension preferredLayoutSize(Container parent) {
  115.         Dimension dim = new Dimension(0, 0);
  116.  
  117.         Insets insets = parent.getInsets();
  118.         dim.width = 1213 + insets.left + insets.right;
  119.         dim.height = 691 + insets.top + insets.bottom;
  120.  
  121.         return dim;
  122.     }
  123.  
  124.     public Dimension minimumLayoutSize(Container parent) {
  125.         Dimension dim = new Dimension(0, 0);
  126.         return dim;
  127.     }
  128.  
  129.     public void layoutContainer(Container parent) {
  130.         Insets insets = parent.getInsets();
  131.  
  132.         Component c;
  133.         c = parent.getComponent(0);
  134.         if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+56,472,40);}
  135.         c = parent.getComponent(1);
  136.         if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+296,472,40);}
  137.         c = parent.getComponent(2);
  138.         if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+112,472,136);}
  139.         c = parent.getComponent(3);
  140.         if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+352,472,120);}
  141.         c = parent.getComponent(4);
  142.         if (c.isVisible()) {c.setBounds(insets.left+48,insets.top+56,208,40);}
  143.         c = parent.getComponent(5);
  144.         if (c.isVisible()) {c.setBounds(insets.left+48,insets.top+112,208,40);}
  145.         c = parent.getComponent(6);
  146.         if (c.isVisible()) {c.setBounds(insets.left+56,insets.top+296,200,32);}
  147.         c = parent.getComponent(7);
  148.         if (c.isVisible()) {c.setBounds(insets.left+56,insets.top+360,200,24);}
  149.         c = parent.getComponent(8);
  150.         if (c.isVisible()) {c.setBounds(insets.left+776,insets.top+56,160,32);}
  151.         c = parent.getComponent(9);
  152.         if (c.isVisible()) {c.setBounds(insets.left+776,insets.top+112,160,24);}
  153.         c = parent.getComponent(10);
  154.         if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+488,72,24);}
  155.         c = parent.getComponent(11);
  156.         if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+488,72,24);}
  157.     }
  158. }