To start with learning swing I want to make a program that draws shapes from a menubar.
This is my pseudo-real code.
My issue is that in the world of Java AWT, Swing and Applets there are so many various types of listeners out there that it is almost impossible
to find the right methodolgy of doing things simply.
I just have some questions for my program- I am not expecting you to trouble shoot it.
1. For every JMenu item interface can I have one method for it that includes all of the components and their action listeners?
2. Why can I not put the JMenu components outside of the init ()? I want them to be public but that is not possible.
3. How many action listener methods do I need? One for each interface- one total or one for each method?
4. If you can; can you link me to a similar program with seperate interfaces for each JMenu item?
You need to instantiate the JMenu objects inside init(), because that is the basic driver method of the applet. It is run one time on startup followed by start(). You use that function to set up your interface. You can declare the JMenu variables as instance variables in the applet, and instantiate them in the init() method.
You could use the same ActionListener for all menuitems. You would distinguish between them using either getSource() or getActionCommand() in actionPerformed(ActionEvent)
Did you just should on me? You should read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!