This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hey, recently I've been trying to create applications and thus, use public static void main... however, a lot of it is really bothering me. First of all, how can I use ActionListener and the likes with static void main. When I tried, it would say non-static variable this can not be referenced in a static context (button.addActionListener(this)); I looked at a friends code and it seemed he used both public static void main and public void init. I tried to do this myself but init never seems to be called. So my question is, when i use public static void main, how can I get out of being static everywhere?
Hi Matt With regards to your friends code, if he is developing an Application the init() methods would never be called. About Main and Static: The main method must be declared static as this means that it doesnt belong to the class and can therefore be invoked without the class being constructed first. To use listeners: Follow Michael's example above. And in the foo class implement ActionListener and the actionPerformed method as required.
Hope that helps / James
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com