Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I am starting my own applet and have lots of questions

 
Bobby Dillan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not exactly sure what you mean by question 1.

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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic