How to add exception to actionPerformed?

I have code that looks like this, with the main panel using an action listener in a different class in the same file:

publicclass MyPanel

{

public MyPanel()

{

//Panel code

button.addActionListener(new MyButton());

}

}

privateclass MyButtonimplements ActionListener

{

publicvoid actionPerformed(ActionEvent e)

//I want to throw a FileNotFoundException here, but when

//I compile it, I get:

//actionPerformed in Panel.java cannot implement actionPerformed in

//java.awt.event.ActionListener; overridden method does not throw FileNotFoundException

{

Scanner scan =new Scanner(new File("Items.txt"));

}

}

Any help would be appreciated. Thanks

[1521 byte] By [tschnella] at [2007-11-26 18:49:01]
# 1
Handle the exception inside the actionPerformed() method using try-catch.Read this as well (8.4.4, especially the end part) http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#78323 #
duckbilla at 2007-7-9 6:23:02 > top of Java-index,Desktop,Core GUI APIs...
# 2

I know how to catch an exception once it is thrown, I am having trouble declaring the method will throw an exception. When I put

public void actionPerformed(ActionEvent e) throws Exception

and try to compile, it gives me a compiler error (the one in my first post.) I have tried declaring the exception in all other actionPerformed methods in my file, but have had no luck as they will all have a compiler error. I have no clue what to do to fix it.

tschnella at 2007-7-9 6:23:02 > top of Java-index,Desktop,Core GUI APIs...
# 3
You can't declare it to throw an exception. See the link above.#
duckbilla at 2007-7-9 6:23:02 > top of Java-index,Desktop,Core GUI APIs...
# 4
So how would I use a scanner object in an ActionListener? I am using it to load a file, which i must read from. I'm assuming since java has file choosers, you can also throw excpetions for them.
tschnella at 2007-7-9 6:23:02 > top of Java-index,Desktop,Core GUI APIs...
# 5
Never mind I just figured out I can catch an exception without declaring to throw it. Thanks for the help and the link.
tschnella at 2007-7-9 6:23:02 > top of Java-index,Desktop,Core GUI APIs...