I am doing a Java project and in my gui I want to use Buttons. I want to put a class' internal parts code as a button action. Because the class Throws Exception when I copy the contents of the class under the button definition I encounter unreported exception error. Since I cannot edit the

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)

part I cannot make the button throw an exception so my question is whether I can modify this button definition which is automatically generated by NetBeans to include this "throws exception" statement. Any help will be much appreciated as I have to get over this to go on. Thanks in advance.

Two ways: throw or catch.
Catch this Exception :

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        try {
            myButton1ActionPerformed(evt);
        } catch (Exception ex) {
            //Logger.getLogger(NewJPanel.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();// or other message JOptionPane.showMessageDialog(...
        }       
    }

Tank you very much it worked!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.