为什么JOptionPane无法在我的应用程序中停止执行流程?
问题描述:
String nmEmp = fName.getText();
if(nmEmp.trim().isEmpty() || nmEmp.trim().equals("")){
JOptionPane.showMessageDialog(null, "Empty Name", "Name Confirmation", JOptionPane.YES_OPTION);
}
为什么JOptionPane无法在我的应用程序中停止执行流程?并且java继续运行以执行JOptionPane下面的代码,如果JOptionPane执行时处于真实状态。这是什么原因呢?请帮帮忙,谢谢为什么JOptionPane无法在我的应用程序中停止执行流程?
答
从Java文档的JOptionPane:https://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html
直接使用:
要创建并直接使用的JOptionPane,标准模式是 大致如下:
JOptionPane pane = new JOptionPane(arguments); pane.set.Xxxx(...); // Configure JDialog dialog = pane.createDialog(parentComponent, title); dialog.show(); Object selectedValue = pane.getValue(); if(selectedValue == null) return CLOSED_OPTION; //If there is not an array of option buttons: if(options == null) { if(selectedValue instanceof Integer) return ((Integer)selectedValue).intValue(); return CLOSED_OPTION; } //If there is an array of option buttons: for(int counter = 0, maxCounter = options.length; counter < maxCounter; counter++) { if(options[counter].equals(selectedValue)) return counter; } return CLOSED_OPTION;
你认为'String.isEmpty ()'和'String.equals(“”)'? –
对话框是否显示? – bradimus
是的,对话框可以显示,但仍然执行JOptionPane下面的代码。 – javFor