如何打印"错误"而JTextfield
为空
save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String sn =jX1.getText();
if (sn==null){
System.out.println("Error");
System.out.println("T");
}
由于
答案 0 :(得分:0)
尝试使用故障安全方法。同时扩展注释,您应该以更好的格式记录数据。 Java托管了大量不同的记录特定数据的方法。 look here
至于你的错误处理,try-catch-finally。这不是经过测试的代码。如果您遇到任何问题,请参阅try-catch和其他语句的文档here或here
public static void main(String[] args) {
while (String sn == null)
try {
String sn = JX1.getText();
} catch (Exception ex) {
System.out.println("Exception thrown!");
} finally {
if (sn != null) {
System.out.println("Closing PrintWriter");
sn.close();
} else {
System.out.println("PrintWriter not open");
}
}