0
所以我有一个程序,当我点击一个按钮时启动一个输入对话框。我需要帮助的是,一旦我从输入对话框收集信息并且它们消失后,我按下Enter键并重新出现输入对话框。为什么?输入对话框[需要的信息]
另外,我怎样才能让它如此,如果输入对话框留空,它会出现一个错误,然后重复,直到它不是空的?
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);
}
无关:不做组件的任何手动尺寸/定位,永远 - 这就是布局管理的全部责任。 – kleopatra
当你收集输入,并且输入对话消失时,按钮获得焦点? – Cold