This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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
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
Joined: Feb 06, 2003
Cool. Yes, I should design class with static methods. Singleton is NOT the way to go. Eugene, Thank you for the code. John Chien