I cant not get the input from my JPasswordField. I'm getting it because it will be shown in a JOptionPane as an output(just for practice purposes).
Eclipse does not give me any errors but the program does not work correctly
Okay so here's the flow of the program. if the JPasswordField is equal to "admin". Then a dialog box will appear and will display my password (which is "admin"). That's it.
I already converted my JPasswordField into string. But still. there's no string to be displayed. There's no error to be displayed in Eclipse also.
Codes:
public class GUI2 extends JFrame {
private JButton shut;
private JPasswordField field;
public GUI2(){
super("Display The Password");
setLayout(new FlowLayout());
field = new JPasswordField(10);
add(field);
display = new JButton("Display");
add(display);
thehandler handler = new thehandler();
display.addActionListener(handler);
}
class thehandler implements ActionListener{
String password = new String(field.getPassword());
public void actionPerformed(ActionEvent event){
if (password.equals("admin")){
JOptionPane.showMessageDialog(null, password);
}
}
}
}