This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Applets and the fly likes I am starting my own applet and have lots of questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "I am starting my own applet and have lots of questions" Watch "I am starting my own applet and have lots of questions" New topic
Author

I am starting my own applet and have lots of questions

Bobby Dillan
Greenhorn

Joined: Mar 20, 2013
Posts: 5
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

Joined: Feb 07, 2005
Posts: 2367
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I am starting my own applet and have lots of questions
 
Similar Threads
JMenu Construction problem
Adding JLabels to JPanel as user creates Shapes
Creating one class from another
JFrame and JMenu
JMenu problem