0

Python から Java に切り替えていますが、プロジェクトで少し問題が発生しています。私が教えているいくつかの暗号のために、Swing で GUI を書いています。私のプロジェクトには、cryptolib と cryptogui という 2 つのパッケージがあります。Cryptolib にはすべての異なる暗号がクラスとして含まれており、cryptogui は私の GUI です。

私のすべての暗号は、私が定義した Cipher クラスのサブクラスです。現在、次のクラスの使用に問題があります。

package cryptolib;
public class SubstitutionCipher extends Cipher{
... implementation here ...
}

私の GUI クラスでは、匿名クラスを使用して置換暗号に切り替えるメニュー項目を定義しています。

package cryptogui;
import cryptolib.*;
public class CryptoSwing extends JFrame {
    private Cipher cipher;
    public CryptoSwing() {
        JMenuItem mntmSubstitution = new JMenuItem("Substitution");
        mntmSubstitution.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                cipher = SubstitutionCipher(txtSubKeyword.getText());
             }
        });
 }

私が直面している問題は、「private Cipher cipher;」の間です。動作しますが、ActionListener の SubstitutionCipher コードでエラーが発生します

The method SubstitutionCipher(String) is undefined for the type new ActionListener(){}

Swing からインポートしたクラス (java.awt.CardLayout など) は完全に機能します。おそらく私が見逃した基本的なものであることはわかっていますが、検索しても問題が見つからないようです。

4

1 に答える 1

1
cipher = SubstitutionCipher(txtSubKeyword.getText());

おそらくあるはずです

cipher = new SubstitutionCipher(txtSubKeyword.getText());

newキーワードに注意してください。

于 2012-07-25T17:06:09.647 に答える