import java.awt.event.ActionListener; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * EncryptDecryptFrame.java * * Created on Dec 19, 2011, 9:00:48 AM */ /** * * @author Chris */ public class EncryptDecryptFrame extends javax.swing.JFrame implements ActionListener { EncryptionLogic el = new EncryptionLogic(); /** Creates new form EncryptDecryptFrame */ public EncryptDecryptFrame() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { titleLBL = new javax.swing.JLabel(); mainTP = new javax.swing.JTabbedPane(); encrypt = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); enCipherTextTA = new javax.swing.JTextArea(); enPlainTextLBL = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); enPlainTextTA = new javax.swing.JTextArea(); enCipherTextLBL = new javax.swing.JLabel(); encryptBUT = new javax.swing.JButton(); offsetTF = new javax.swing.JTextField(); enSaveBUT = new javax.swing.JButton(); clearBUT = new javax.swing.JButton(); statusTF = new javax.swing.JTextField(); decryptPAN = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(null); titleLBL.setFont(new java.awt.Font("Calibri", 1, 36)); // NOI18N titleLBL.setText("String Encrypter Decrypter"); getContentPane().add(titleLBL); titleLBL.setBounds(240, 20, 420, 50); encrypt.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N encrypt.setLayout(null); enCipherTextTA.setColumns(20); enCipherTextTA.setEditable(false); enCipherTextTA.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N enCipherTextTA.setRows(5); jScrollPane1.setViewportView(enCipherTextTA); encrypt.add(jScrollPane1); jScrollPane1.setBounds(30, 220, 650, 150); enPlainTextLBL.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N enPlainTextLBL.setText("Plain Text"); encrypt.add(enPlainTextLBL); enPlainTextLBL.setBounds(320, 20, 60, 20); enPlainTextTA.setColumns(20); enPlainTextTA.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N enPlainTextTA.setRows(5); jScrollPane2.setViewportView(enPlainTextTA); encrypt.add(jScrollPane2); jScrollPane2.setBounds(30, 40, 650, 150); enCipherTextLBL.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N enCipherTextLBL.setText("Cipher Text"); encrypt.add(enCipherTextLBL); enCipherTextLBL.setBounds(320, 200, 80, 20); encryptBUT.setBackground(new java.awt.Color(255, 204, 0)); encryptBUT.setFont(new java.awt.Font("Calibri", 1, 24)); // NOI18N encryptBUT.setText("Encrypt ->"); encryptBUT.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); encryptBUT.addActionListener(this); encrypt.add(encryptBUT); encryptBUT.setBounds(60, 390, 130, 40); offsetTF.setFont(new java.awt.Font("Calibri", 1, 24)); // NOI18N offsetTF.setText("1"); encrypt.add(offsetTF); offsetTF.setBounds(220, 400, 70, 30); enSaveBUT.setBackground(new java.awt.Color(255, 51, 0)); enSaveBUT.setFont(new java.awt.Font("Calibri", 1, 24)); // NOI18N enSaveBUT.setText("Save CIpher Text"); enSaveBUT.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); enSaveBUT.addActionListener(this); encrypt.add(enSaveBUT); enSaveBUT.setBounds(470, 390, 200, 40); clearBUT.setBackground(new java.awt.Color(255, 204, 0)); clearBUT.setFont(new java.awt.Font("Calibri", 1, 24)); // NOI18N clearBUT.setText("Clear"); clearBUT.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); clearBUT.addActionListener(this); encrypt.add(clearBUT); clearBUT.setBounds(340, 390, 100, 40); statusTF.setFont(new java.awt.Font("Calibri", 1, 24)); // NOI18N encrypt.add(statusTF); statusTF.setBounds(90, 440, 470, 30); mainTP.addTab("Encrypt", encrypt); decryptPAN.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N decryptPAN.setVerifyInputWhenFocusTarget(false); decryptPAN.setLayout(null); mainTP.addTab("Decrypt", decryptPAN); getContentPane().add(mainTP); mainTP.setBounds(110, 60, 720, 500); pack(); } // Code for dispatching events from components to event handlers. public void actionPerformed(java.awt.event.ActionEvent evt) { if (evt.getSource() == encryptBUT) { EncryptDecryptFrame.this.encryptBUTActionPerformed(evt); } else if (evt.getSource() == clearBUT) { EncryptDecryptFrame.this.clearBUTActionPerformed(evt); } else if (evt.getSource() == enSaveBUT) { EncryptDecryptFrame.this.enSaveBUTActionPerformed(evt); } }// //GEN-END:initComponents private void encryptBUTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_encryptBUTActionPerformed String s = enPlainTextTA.getText(); String off = offsetTF.getText(); int offset = Integer.parseInt(off); //Call the offset encrypter String result = el.encryptASCIIOffset(s, offset); enCipherTextTA.setText(result); }//GEN-LAST:event_encryptBUTActionPerformed private void clearBUTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearBUTActionPerformed enPlainTextTA.setText(""); enCipherTextTA.setText(""); }//GEN-LAST:event_clearBUTActionPerformed private void enSaveBUTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enSaveBUTActionPerformed String ct = enCipherTextTA.getText(); el.writeFile("Example.txt", ct); statusTF.setText("Example1.txt is saved!"); }//GEN-LAST:event_enSaveBUTActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new EncryptDecryptFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton clearBUT; private javax.swing.JPanel decryptPAN; private javax.swing.JLabel enCipherTextLBL; private javax.swing.JTextArea enCipherTextTA; private javax.swing.JLabel enPlainTextLBL; private javax.swing.JTextArea enPlainTextTA; private javax.swing.JButton enSaveBUT; private javax.swing.JPanel encrypt; private javax.swing.JButton encryptBUT; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTabbedPane mainTP; private javax.swing.JTextField offsetTF; private javax.swing.JTextField statusTF; private javax.swing.JLabel titleLBL; // End of variables declaration//GEN-END:variables }