8 Replies - 566 Views - Last Post: 30 April 2012 - 02:39 PM Rate Topic: -----

#1 theflash21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-April 12

Learning Java with Netbeans, need to provide FileNotFoundException

Posted 30 April 2012 - 11:50 AM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: Learning Java with Netbeans, need to provide FileNotFoundException

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • Posts: 3,002
  • Joined: 30-January 11

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.

This post has been edited by Ryano121: 30 April 2012 - 11:55 AM

Was This Post Helpful? 0
  • +
  • -

#3 theflash21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-April 12

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.
Was This Post Helpful? 0
  • +
  • -

#4 collegekid901  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 41
  • Joined: 09-March 12

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.
Was This Post Helpful? 0
  • +
  • -

#5 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • Posts: 3,002
  • Joined: 30-January 11

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.
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2689
  • View blog
  • Posts: 11,351
  • Joined: 20-September 08

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?
Was This Post Helpful? 0
  • +
  • -

#7 theflash21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-April 12

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?
Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2689
  • View blog
  • Posts: 11,351
  • Joined: 20-September 08

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
Was This Post Helpful? 1
  • +
  • -

#9 theflash21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-April 12

Re: Learning Java with Netbeans, need to provide FileNotFoundException

Posted 30 April 2012 - 02:39 PM

Thank you goose.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1