I'm building a large Java application that uses multiple pop-up windows. Some of these windows must be able to be displayed at the same time (for instance, separate pop-ups for Google Earth and a webcam feed), but some of them can only be displayed one at a time (for instance, error messages). The first kind of pop-ups, the webcam kind, are working fine. But the error message pop-ups act like the webcam type of pop-ups (that is, they create new .class files and there can be multiple error pop-ups). How do I fix this? Should I create a new error class?
Also, in one of the webcam-type pop-ups, I have JTextFields which read a username and password. This log-in popup works fine, but if I use it once, close it, and use it again, doing a getText() on the JTextFields returns an empty string. I think this problem might be related to the one above, but I am not sure.
passwordAction.addActionListener(new ActionListener() {
JFrame pwPop=new JFrame("Log in");
JTextField unameField;
JTextField pwField;
public void actionPerformed(ActionEvent arg0) {
pwPop.setBounds(250,200,300,150);
JPanel pwPopPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,10,10));
pwPop.add(pwPopPanel);
unameField=new JTextField();
pwField=new JTextField();
JButton logInButton=new JButton("Log in");
JButton cancelButton=new JButton("Cancel");
JLabel logInText=new JLabel("Username:");
JLabel passwordText=new JLabel("Password:");
JPanel buttonPanel=new JPanel(new FlowLayout(FlowLayout.CENTER,5,0));
pwPopPanel.add(logInText);
pwPopPanel.add(unameField);
pwPopPanel.add(passwordText);
pwPopPanel.add(pwField);
buttonPanel.add(logInButton);
buttonPanel.add(cancelButton);
pwPopPanel.add(buttonPanel);
logInButton.addActionListener(new ActionListener() {
JFrame logErrorFrame;
public void actionPerformed(ActionEvent arg0) {
if (doLogIn(unameField.getText(), pwField.getText(), "")) {
unameField.setText(null);
pwField.setText(null);
pwPop.setVisible(false);
}
}
});
pwPop.setVisible(true);
}
});