0

So I have a program that launches an input dialog when I click a button. What I need help on is that once I gather the information from the input dialog and they are gone, I press the Enter key and the input dialogs re-appear. Why?

Also, How can I have it so that if the input dialog is left empty, it comes out as an error and then repeats until it is not empty?


public static String fn;
public static String sn;

public void actionPerformed (ActionEvent e){
    fn = JOptionPane.showInputDialog("What is your first name?");
    sn = JOptionPane.showInputDialog("What is your second name");

    //JOptionPane.showMessageDialog(null, "Welcome " + fn + " " + sn + ".", "", JOptionPane.INFORMATION_MESSAGE);
    text.setText("Welcome " + fn + " " + sn + ".");
    b.setVisible(false);
    text.setVisible(true);
    text.setBounds(140,0,220,20);
    text.setHorizontalAlignment(JLabel.CENTER);
    text.setEditable(false);
    text.setBackground(Color.YELLOW);
    writeToFile();
}

public BingoHelper(){
    super("BINGO");
    add(text);
    text.setVisible(false);
    add(b);
    this.add(pnlButton);
    pnlButton.setBackground(Color.BLUE);
    //pnlButton.add(b);+
    b.setVisible(true);
    b.setBounds(145,145,145,20);
    //b.setPreferredSize(new Dimension(150,40));
    b.addActionListener(this);
    b.setBackground(Color.GREEN);
    rootPane.setDefaultButton(b);
}
4

1 に答える 1