私は JApplet を初めて使用します。メソッド actionPerformed 内の内部クラスから JPasswordField オブジェクトにアクセスする方法がわかりません。JFrame BioReader に PasswordField を追加したいのですが、truePassword と JPasswordField の入力を比較したいのですが、エラーが発生します。 「パスワードは変数に解決できません」として。
import javax.swing.JFrame;
import javax.swing.JPasswordField;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class BioReader extends JFrame{
public BioReader(){
super("BioTech Inc.");
setLayout(new FlowLayout());
JPasswordField Password = new JPasswordField(10);
add(Password);
BioReader.theHandler eventHandler = new BioReader.theHandler();
Password.addActionListener(eventHandler);
}
private class theHandler implements ActionListener {
public void actionPerformed(ActionEvent event){
if(event.getSource()==Password) //error
String.format("You typed: %s",event.getActionCommand());
}//actionPerformed ended
}//class theHandler ended
}//class BioReader ended