Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: Java  |  size: 8.13 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /*
  7.  * NewJApplet.java
  8.  *
  9.  * Created on May 2, 2012, 5:21:06 PM
  10.  */
  11. package shootthebox;
  12. import java.lang.Math;
  13. /**
  14.  *
  15.  * @author jo0q5t6
  16.  */
  17. public class NewJApplet extends javax.swing.JApplet {
  18. String text1;
  19. String text2;
  20. char[] shift = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',};
  21.  
  22.     /** Initializes the applet NewJApplet */
  23.     @Override
  24.     public void init() {
  25.         /* Set the Nimbus look and feel */
  26.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  27.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  28.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  29.          */
  30.         try {
  31.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  32.                 if ("Nimbus".equals(info.getName())) {
  33.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  34.                     break;
  35.                 }
  36.             }
  37.         } catch (ClassNotFoundException ex) {
  38.             java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  39.         } catch (InstantiationException ex) {
  40.             java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  41.         } catch (IllegalAccessException ex) {
  42.             java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  43.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  44.             java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  45.         }
  46.         //</editor-fold>
  47.  
  48.         /* Create and display the applet */
  49.         try {
  50.             java.awt.EventQueue.invokeAndWait(new Runnable() {
  51.  
  52.                 public void run() {
  53.                     initComponents();
  54.                 }
  55.             });
  56.         } catch (Exception ex) {
  57.             ex.printStackTrace();
  58.         }
  59.     }
  60.  
  61.     /** This method is called from within the init() method to
  62.      * initialize the form.
  63.      * WARNING: Do NOT modify this code. The content of this method is
  64.      * always regenerated by the Form Editor.
  65.      */
  66.     @SuppressWarnings("unchecked")
  67.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  68.     private void initComponents() {
  69.  
  70.         jButton1 = new javax.swing.JButton();
  71.         jButton2 = new javax.swing.JButton();
  72.         jScrollPane1 = new javax.swing.JScrollPane();
  73.         jTextArea1 = new javax.swing.JTextArea();
  74.         jScrollPane2 = new javax.swing.JScrollPane();
  75.         jTextArea2 = new javax.swing.JTextArea();
  76.  
  77.         jButton1.setText("Encrypt");
  78.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  79.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  80.                 jButton1ActionPerformed(evt);
  81.             }
  82.         });
  83.  
  84.         jButton2.setText("Decrypt");
  85.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  86.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  87.                 jButton2ActionPerformed(evt);
  88.             }
  89.         });
  90.  
  91.         jTextArea1.setColumns(20);
  92.         jTextArea1.setRows(5);
  93.         jScrollPane1.setViewportView(jTextArea1);
  94.  
  95.         jTextArea2.setColumns(20);
  96.         jTextArea2.setRows(5);
  97.         jScrollPane2.setViewportView(jTextArea2);
  98.  
  99.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  100.         getContentPane().setLayout(layout);
  101.         layout.setHorizontalGroup(
  102.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103.             .addGroup(layout.createSequentialGroup()
  104.                 .addGap(56, 56, 56)
  105.                 .addComponent(jButton1)
  106.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 125, Short.MAX_VALUE)
  107.                 .addComponent(jButton2)
  108.                 .addGap(79, 79, 79))
  109.             .addGroup(layout.createSequentialGroup()
  110.                 .addContainerGap()
  111.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  112.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
  113.                 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  114.                 .addGap(28, 28, 28))
  115.         );
  116.         layout.setVerticalGroup(
  117.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  118.             .addGroup(layout.createSequentialGroup()
  119.                 .addGap(45, 45, 45)
  120.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  121.                     .addComponent(jButton1)
  122.                     .addComponent(jButton2))
  123.                 .addGap(30, 30, 30)
  124.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  125.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  126.                     .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  127.                 .addContainerGap(106, Short.MAX_VALUE))
  128.         );
  129.     }// </editor-fold>
  130.  
  131. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  132. // TODO add your handling code here:
  133.     char decp[] = text1.toCharArray();
  134. for (int i = 0; i < decp.length; i++)
  135.     {
  136.        
  137.         for (int a = 0; a < shift.length; a++ )
  138.         {
  139.             if (decp[i] == ' ')
  140.             {
  141.                 break;
  142.             }
  143.             if (decp[i] == shift[a])        
  144.            
  145.             {
  146.                  System.out.print(decp[i]+ " ");  
  147.                 if (a - 10 < 0)
  148.                 {
  149.                 a = Math.abs(a-10+26);  
  150.                 decp[i] = shift[a];
  151.                 }
  152.                 else
  153.                 {
  154.                 decp[i] = shift[a - 10];
  155.                 }
  156.               System.out.print(decp[i]);
  157.               System.out.println();
  158.               break;
  159.              
  160.             }
  161.            
  162.         }
  163.        
  164.     }
  165.  
  166.  
  167.  
  168.  
  169.      
  170. text1 = String.valueOf(decp);
  171. jTextArea2.setText("");
  172. jTextArea1.setText(text1);
  173. }
  174.  
  175. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  176. text1 = jTextArea1.getText();
  177. //System.out.println(text1);
  178. char decp[] = text1.toCharArray();
  179. for (int i = 0; i < decp.length; i++)
  180.     {
  181.        
  182.         for (int a = 0; a < shift.length; a++ )
  183.         {
  184.             if (decp[i] == ' ')
  185.             {
  186.                 break;
  187.             }
  188.             if (decp[i] == shift[a])        
  189.            
  190.             {
  191.                  System.out.print(decp[i]+ " ");  
  192.                 if (a + 10 > 25)
  193.                 {
  194.                 a = Math.abs(a+10-26);  
  195.                 decp[i] = shift[a];
  196.                 }
  197.                 else
  198.                 {
  199.                 decp[i] = shift[a + 10];
  200.                 }
  201.               System.out.print(decp[i]);
  202.               System.out.println();
  203.               break;
  204.              
  205.             }
  206.            
  207.         }
  208.        
  209.     }
  210.  
  211.  
  212.  
  213.  
  214.      
  215. text2 = String.valueOf(decp);
  216. jTextArea1.setText("");
  217. jTextArea2.setText(text2);
  218.        
  219. }
  220.  
  221. public void runme(){
  222.    
  223.    
  224.    
  225. }
  226.     // Variables declaration - do not modify
  227.     private javax.swing.JButton jButton1;
  228.     private javax.swing.JButton jButton2;
  229.     private javax.swing.JScrollPane jScrollPane1;
  230.     private javax.swing.JScrollPane jScrollPane2;
  231.     private javax.swing.JTextArea jTextArea1;
  232.     private javax.swing.JTextArea jTextArea2;
  233.     // End of variables declaration
  234. }