Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ActionListener in a static context?

807607Dec 8 2006 — edited Dec 8 2006
I'm struggling with my first applet. I'm trying to make a group of buttons using a method named CreateAndShowGUI (guess what it does.)

If I make CreateAndShowGUI static, I get this error:
wishlist.java:103: non-static variable this cannot be referenced from a static context
                                actionButton[looper].addActionListener(this);
                                                                       ^
If I make CreateAndShowGUI nonstatic, I get this error:
wishlist.java:258: non-static method createAndShowGUI(int,int,boolean) cannot be referenced from a static context
                createAndShowGUI(wishCount, wishDisplay, (viewer.equals("Platonix                        ")));
                ^
Line 258, the "static context", is part of main(), which has to be static or God kills a kitten. So I suppose CreateAndShowGUI also has to be static, meaning I need to know how to set an ActionListener on a JButton in a static context where I'm not allowed to use the this keyword.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 5 2007
Added on Dec 8 2006
3 comments
178 views