开发者

How to change method signature in Netbeans Form Editor?

开发者 https://www.devze.com 2022-12-27 14:15 出处:网络
I create GUI in Netbeans Form Editor and want to change an auto-generated signature of one method, namely to add throws to it. How to do it?

I create GUI in Netbeans Form Editor and want to change an auto-generated signature of one method, namely to add throws to it. How to do it?

For instance, I have

private void btOpenFileActionPerformed(java.awt.event.ActionEvent evt) {}

And 开发者_如何学运维want to make it

private void btOpenFileActionPerformed(java.awt.event.ActionEvent evt) throws AssertionError{}

As the method signature is auto-generated, I cannot change it manually.


You cannot change the signature of the action-performed event method in any way other than changing the name.

What are your intentions for the exception once it gets thrown from your event method? The exception is going to be passed up to the auto-generated action listener, and that action listener cannot pass it along because that would be a violation of the ActionListener#actionPerformed contract.

If you want to throw an exception from your event method, you have two options. The first is to have the auto-generated event method call the exception-throwing event method. The second is to manually create an ActionListener and attach that to the component rather than relying on the automatic generation. In either case, you will need to handle the exception: a checked exception cannot be passed back from the ActionListener.

0

精彩评论

暂无评论...
验证码 换一张
取 消