I’m designing the frontend so the user can modify a current password. When the user presses the JButton, it displays a password field where they enter their password, which triggers another password field to appear where they re-enter their password. After both passwords are entered, the inherited method changePassword() changes the static method from the superclass.
<code>JPasswordField pWordBox1 = new JPasswordField();
JPasswordField pWordBox2 = new JPasswordField();
JLabel msg1 = new JLabel();
JLabel msg2 = new JLabel();
JLabel confirm = new JLabel("Password successfully saved");
JLabel inError = new JLabel();
pWordBox1.setBounds(1200, 580, 200, 20);
msg1.setBounds(1200, 550, 200, 20);
window.add(msg1);
inError.setBounds(1200, 720, 200, 20);
window.add(inError);
msg2.setBounds(1200, 620, 200, 20);
window.add(inError);
pWordBox2.setBounds(1200, 640, 200, 20);
confirm.setBounds(1200, 680, 200, 20);
JButton modPassword = new JButton("Change Admin Password");
modPassword.setBounds(1200, 500, 200, 30);
window.add(modPassword);
modPassword.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
msg1.setText("Please enter new password");
window.add(pWordBox1);
window.revalidate();
window.repaint();
pWordBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent d) {
try
{
int val1 = Integer.parseInt(new String(pWordBox1.getPassword()));
window.add(pWordBox2);
msg2.setText("Please Re-Enter Password");
pWordBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent n) {
int val2 = Integer.parseInt(new String(pWordBox2.getPassword()));
if(val1 == val2)
{
changePassword(val1);
confirm.setText("Password successfully saved");
}
}
});
} catch(Exception e) {
inError.setText("Not a valid password. Try again!");
}
window.revalidate();
window.repaint();
}
});
}
});
</code>
<code>JPasswordField pWordBox1 = new JPasswordField();
JPasswordField pWordBox2 = new JPasswordField();
JLabel msg1 = new JLabel();
JLabel msg2 = new JLabel();
JLabel confirm = new JLabel("Password successfully saved");
JLabel inError = new JLabel();
pWordBox1.setBounds(1200, 580, 200, 20);
msg1.setBounds(1200, 550, 200, 20);
window.add(msg1);
inError.setBounds(1200, 720, 200, 20);
window.add(inError);
msg2.setBounds(1200, 620, 200, 20);
window.add(inError);
pWordBox2.setBounds(1200, 640, 200, 20);
confirm.setBounds(1200, 680, 200, 20);
JButton modPassword = new JButton("Change Admin Password");
modPassword.setBounds(1200, 500, 200, 30);
window.add(modPassword);
modPassword.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
msg1.setText("Please enter new password");
window.add(pWordBox1);
window.revalidate();
window.repaint();
pWordBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent d) {
try
{
int val1 = Integer.parseInt(new String(pWordBox1.getPassword()));
window.add(pWordBox2);
msg2.setText("Please Re-Enter Password");
pWordBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent n) {
int val2 = Integer.parseInt(new String(pWordBox2.getPassword()));
if(val1 == val2)
{
changePassword(val1);
confirm.setText("Password successfully saved");
}
}
});
} catch(Exception e) {
inError.setText("Not a valid password. Try again!");
}
window.revalidate();
window.repaint();
}
});
}
});
</code>
JPasswordField pWordBox1 = new JPasswordField();
JPasswordField pWordBox2 = new JPasswordField();
JLabel msg1 = new JLabel();
JLabel msg2 = new JLabel();
JLabel confirm = new JLabel("Password successfully saved");
JLabel inError = new JLabel();
pWordBox1.setBounds(1200, 580, 200, 20);
msg1.setBounds(1200, 550, 200, 20);
window.add(msg1);
inError.setBounds(1200, 720, 200, 20);
window.add(inError);
msg2.setBounds(1200, 620, 200, 20);
window.add(inError);
pWordBox2.setBounds(1200, 640, 200, 20);
confirm.setBounds(1200, 680, 200, 20);
JButton modPassword = new JButton("Change Admin Password");
modPassword.setBounds(1200, 500, 200, 30);
window.add(modPassword);
modPassword.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
msg1.setText("Please enter new password");
window.add(pWordBox1);
window.revalidate();
window.repaint();
pWordBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent d) {
try
{
int val1 = Integer.parseInt(new String(pWordBox1.getPassword()));
window.add(pWordBox2);
msg2.setText("Please Re-Enter Password");
pWordBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent n) {
int val2 = Integer.parseInt(new String(pWordBox2.getPassword()));
if(val1 == val2)
{
changePassword(val1);
confirm.setText("Password successfully saved");
}
}
});
} catch(Exception e) {
inError.setText("Not a valid password. Try again!");
}
window.revalidate();
window.repaint();
}
});
}
});
Every time I press the JButton, the screen turns white, and the JButton is the only thing to return. Neither my superclass or my subclass uses null layouts, but I did use setBounds on both. Are the layouts or the nested addActionListeners the issue? What can I do to remedy this?