Hi,
I have a JFrame window which pops up a dialog box at the time of pressing a menu item. Now in dialog box i have a login button which performs some processing and then closes the dialog box. But before closing it must change the title of parent window. I searched & found following commands:
parentWind.invalidate();
parentWind.validate();
parentWind.repaint();
parentWind.pack();
parentWind.setVisible(true);
but they are not doing anything. I also found on this forum to use window listener:
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
parentWind.setTitle("Login = bob");
parentWind.invalidate();
parentWind.validate();
parentWind.repaint();
parentWind.pack();
parentWind.setVisible(true);
}
});
but addWindowListener(..) requires an object to invoke. I tried this & parentWind obj but it says cant find symbol constructor().
My dialog box code is given below:
class LoginDialog extends JDialog implements ActionListener{
JFrame parentWind;
JTextField userName = new JTextField();
JTextField password = new JTextField();
JLabel label = new JLabel("LOGIN");
//JLabel label1 = new JLabel("TraineeID");
JLabel label2 = new JLabel("Password");
JButton btn = new JButton("Login");
LoginDialog(JFrame parent,String title){
super(parent,title,false);
setLayout(new FlowLayout());
//setSize(300, 200);
//JOptionPane.showMessageDialog(null,"Inside LoginDialog");
setSize(800,700);
userName.setPreferredSize(new Dimension(130,30));
password.setPreferredSize(new Dimension(130,30));
label.setPreferredSize(new Dimension(30,30));
label2.setPreferredSize(new Dimension(70,80));
parentWind = parent;
add(userName);
add(label);
add(label2);
add(password);
add(btn);
//setVisible(true);
btn.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
parentWind.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
parentWind.setTitle("Login = bob");
parentWind.invalidate();
parentWind.validate();
parentWind.repaint();
parentWind.pack();
parentWind.setVisible(true);
}
});
}
}
.
Somebody please guide me.
Zulfi.