Hello,
I am learning Java, using Netbeans GUI builder. How do I add the "throws FileNotFoundException" to the event/action; the GUI-generated code for the event is protected from changes ("guarded blocks")? Is there some other way I can/should do this?
Thanks.
8 Replies - 298 Views - Last Post: 30 April 2012 - 02:39 PM
#1
Learning Java with Netbeans, need to provide FileNotFoundException
Posted 30 April 2012 - 11:50 AM
Replies To: Learning Java with Netbeans, need to provide FileNotFoundException
#2
Re: Learning Java with Netbeans, need to provide FileNotFoundException
Posted 30 April 2012 - 11:52 AM
http://wiki.netbeans...ngGuardedBlocks
P.S - Also do yourself a favour and don't use the Netbeans GUI builder. It produces horrible unmaintainable code and is often the source of horror here when people post masses of generated code from it.
Learn how to produce Java GUI's by hand. They are not hard and you will gain a lot more experience and knowledge in the process.
P.S - Also do yourself a favour and don't use the Netbeans GUI builder. It produces horrible unmaintainable code and is often the source of horror here when people post masses of generated code from it.
Learn how to produce Java GUI's by hand. They are not hard and you will gain a lot more experience and knowledge in the process.
This post has been edited by Ryano121: 30 April 2012 - 11:55 AM
#3
Re: Learning Java with Netbeans, need to provide FileNotFoundException
Posted 30 April 2012 - 12:04 PM
Thanks, I've actually seen that, but ...
"write your code out of the guarded block, typically into the constructor after the initComponents() method call"
I'm not exactly sure what I'm supposed to put in into the constructor to make this happen - or even where I should put it.
"write your code out of the guarded block, typically into the constructor after the initComponents() method call"
I'm not exactly sure what I'm supposed to put in into the constructor to make this happen - or even where I should put it.
#4
Re: Learning Java with Netbeans, need to provide FileNotFoundException
Posted 30 April 2012 - 01:47 PM
I have the opposite experience with netbeans for GUI. I found it saves a lot of time when I am in a rush. I can generate a code and clean it up myself later on. but I would recommend at least understanding how it it works and not just let it do your work without understanding it.
#5
Re: Learning Java with Netbeans, need to provide FileNotFoundException
Posted 30 April 2012 - 01:54 PM
But the key point is that you have to clean it up.
Ok builders may be good for a rushed project but all in all you are losing time.
Why not do it properly the first time?
Plus once you get some experience and know your may around swing, you could probably code a solution faster than you could drag 'n' drop one. You finish faster, you don't have to go back later and clean the rubbish and you might learn something in the process. Win, win, win.
Ok builders may be good for a rushed project but all in all you are losing time.
Why not do it properly the first time?
Plus once you get some experience and know your may around swing, you could probably code a solution faster than you could drag 'n' drop one. You finish faster, you don't have to go back later and clean the rubbish and you might learn something in the process. Win, win, win.
#6
Re: Learning Java with Netbeans, need to provide FileNotFoundException
Posted 30 April 2012 - 01:58 PM
Quote
How do I add the "throws FileNotFoundException" to the event/action
You can't, but shouldn't need to. Why do you think you do?
#7
Re: Learning Java with Netbeans, need to provide FileNotFoundException
Posted 30 April 2012 - 02:07 PM
I was trying to read a file into an array; I have learned that the method needs to say throws FileNotFoundException, which worked fine on the console, but when I tried to move it to the GUI, I couldn't edit the method. I realize I don't fully understand exceptions yet, but how "should" this be done?
#8
Re: Learning Java with Netbeans, need to provide FileNotFoundException
Posted 30 April 2012 - 02:35 PM
You need to catch the exception, not throw it. That should be done (by the sounds) in your event handler
#9
Re: Learning Java with Netbeans, need to provide FileNotFoundException
Posted 30 April 2012 - 02:39 PM
Thank you goose.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|