Error messages with Java Swing

后端 未结 3 1378
南笙
南笙 2021-01-20 17:42

I have a query on handling error conditions with Java Swing.

I am using Netbeans to develop a simple Java Swing app. It is to load in a text file, then run calculati

3条回答
  •  心在旅途
    2021-01-20 18:15

    yeah the problem is with your IO reading concept the while loop is reading to the end of the file and so on.. to prevent that u can use a buffered reader and use this code

    String line = null
    while((line = reader.readLine())!= null) {
    // do stuf
    }
    

    if you are having this problem with processing the read line all you need is to create a exception class of your own by extending Exception class and throw that exception in your catch block after setting the message to your custom exception class you can set that message in to

     JOptionPane.showMessageDialog(null,"message here"); //showMessageDialog is a static method
    

    ok

提交回复
热议问题