Java 如何解决使用awt编码的这种情况?

Java 如何解决使用awt编码的这种情况?,java,encryption,awt,encode,Java,Encryption,Awt,Encode,这不是完整的源代码。 它开始编码时没有输入值。 我希望在填写上下文的文本字段后开始加密和解密。 如何解决这个问题?编码和解码应该由一些AWT方法调用,比如在main方法中调用“actionPerformed”您能描述一下什么是问题吗?而且,这肯定会增加获得帮助的可能性。 public static void main(String [] args) throws Exception { setUp(); prepareGUI();

这不是完整的源代码。 它开始编码时没有输入值。 我希望在填写上下文的文本字段后开始加密和解密。
如何解决这个问题?

编码和解码应该由一些AWT方法调用,比如在main方法中调用“actionPerformed”

您能描述一下什么是问题吗?而且,这肯定会增加获得帮助的可能性。
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;
    }

}