• Post Reply Bookmark Topic Watch Topic
  • New Topic

java application using swing

 
mike smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, I've been learning Java for a few months after studing c++ for about 2 years. Below is a program I am working on. I know it is kinda long and really messy. I'm having some problems with certain things, such as were I should put certain code, and what the standard style is. The code gets a compile error at the throws IOexception. Any help I appreciated.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error you are getting comes from the ActionPerformed (ActioneEvent e) throws IOException correct?
If so, actionPerformed comes from the ActionListener interface, and needs to have a specific signature:
public void actionPerformed (ActionEvent e) {
without any throws or extra modifiers. This is part of the contract for using the interface. If some part of your actionPerformed method throws an exception it should be caught in the actionPerformed method itself. (place the code in a try { } catch (IOException e) { } block).
I would think, but am not sure it is required, that any exceptions in the main method should likewise be caught and dealt with (such as by calling an exitProgram method or something) to allow your program to exit gracefully from errors.
Steve
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Their is no use throwing any exception from the main method as their is nobody to catch it. remove the IOException from the main method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!