File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Error Display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Error Display" Watch "Error Display" New topic
Author

Error Display

John Chien
Ranch Hand

Joined: Feb 06, 2003
Posts: 105
Hi,
For the GUI design, I found that it is necessary to show some error messages to the user. This may happen in different components of the GUI. I do not want to implement them in each class. What I am thinking is to design a class called MessageDisplay to display the messages.
I am thinking in designing this class to be a Singleton. Is it a correct approach ?
Thanks,
John Chien


SCJP, SCJD, SCWCD, SCBCD<br />IBM Certified Specialist (158)<br />Oracle9i PL/SQL Developer Certified Associate
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello.
Why not a class with a static method that shows the error message?
Miguel
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Yes this is an approach that is good to use, as it handles all Exceptions that the client needs to display. Now as a Singleton and in a seperate class I am not positive if that is good or bad.
Actually I just added two lines to my main class. in the public static void main() method.

This code was in the catch of the main try statements. So I make sure that all the exceptions that can occur in the client, that the client must show, gets thrown all the way up to display this message.
So I didn't need to create a different class at all.
But like in everything, you get to choose your approach.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

Why not a class with a static method that shows the error message?

That's what I did, too:

Eugene.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

That's cool Eugene, in that case I would suggest a class like yours. In mine I only had the error messages, so having one catch was fine in my code, but if I was to make it show more types of messages then refactoring like yours would be better.
Mark
John Chien
Ranch Hand

Joined: Feb 06, 2003
Posts: 105
Cool.
Yes, I should design class with static methods.
Singleton is NOT the way to go.
Eugene, Thank you for the code.
John Chien
 
Don't get me started about those stupid light bulbs.
 
subject: Error Display