2015-05-23 119 views
0
public static void main(String [] args) throws Exception {  
     setUp(); 

     prepareGUI(); 

     Label con=new Label("Entered Context :",Label.RIGHT); 
     Label encode=new Label("Encoded text :",Label.RIGHT); 
     Label decode=new Label("Decoded text :",Label.LEFT); 
     Label head=new Label("Test"); 

     final TextField userText=new TextField(20); 
     final TextField tencode=new TextField(20); 
     final TextField tdecode=new TextField(25); 

     byte [] encryptionBytes = null; 

     Font headFont=new Font("Dialog",Font.PLAIN,20); 
     Font labelFont= new Font("SansSerif",Font.PLAIN,15); 
     head.setFont(headFont); 
     con.setFont(labelFont); encode.setFont(labelFont); decode.setFont(labelFont); 

     Button encoding=new Button("Encoding"); 
     Button decoding=new Button("Decoding"); 

     input=userText.getText(); 

     encryptionBytes = encrypt(input); 
     BASE64Encoder encoder = new BASE64Encoder(); 
     BASE64Decoder decoder = new BASE64Decoder(); 
     final String encodeString = encoder.encode(encryptionBytes); 
     final String decodeString = decrypt(decoder.decodeBuffer(encodeString)); 

     encoding.addActionListener(new ActionListener() { 
      @Override 
      public void actionPerformed(ActionEvent e) { 
       tencode.setText(encodeString); 
      } 
     }); 

     decoding.addActionListener(new ActionListener() { 
      @Override 
      public void actionPerformed(ActionEvent e) { 
       tdecode.setText(decodeString); 
      } 
     }); 

     headerPanel.add(head); 
     controlPanel.add(con); 
     controlPanel.add(userText); 
     controlPanel.add(encoding); 
     encodePanel.add(encode); 
     encodePanel.add(tencode); 
     encodePanel.add(decoding); 
     decodePanel.add(decode); 
     decodePanel.add(tdecode); 
     frame.setVisible(true); 
    } 


    private static byte [] encrypt(String input) throws InvalidKeyException, BadPaddingException, 
    IllegalBlockSizeException { 
     cipher.init(Cipher.ENCRYPT_MODE, key); 
     byte [] inputBytes = input.getBytes(); 
     return cipher.doFinal(inputBytes); 
    } 


    private static String decrypt(byte [] encryptionBytes) throws InvalidKeyException, BadPaddingException, 
      IllegalBlockSizeException { 
     cipher.init(Cipher.DECRYPT_MODE, key); 
     byte [] recoveredBytes = cipher.doFinal(encryptionBytes); 
     String recovered = new String(recoveredBytes); 
     return recovered; 
    } 

} 

这是未完成的来源。 它开始编码没有输入值。 我希望在填写上下文的文本字段后开始加密和解密。 我该如何解决这个问题?我怎样才能解决这个有关awt编码的情况?

+1

你能描述一下是个问题“的actionPerformed”一些AWT方法被调用?另外,[MCVE](http://stackoverflow.com/help/mcve)肯定会增加获得帮助的可能性。 –

回答

0

编码和解码应该像,而不是主要方法

相关问题