This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

java application using swing  RSS feed

 
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.
 
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
 
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!