Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

I am starting my own applet and have lots of questions

 
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?
 
Ranch Hand
Posts: 2410
  • 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)
 
Did you just should on me? You should read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic