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編碼的情況?
你能描述一下是個問題「的actionPerformed」一些AWT方法被調用?另外,[MCVE](http://stackoverflow.com/help/mcve)肯定會增加獲得幫助的可能性。 –