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.