File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMenuBar in an Applet : Good vs Bad Code Practice?

 
achana chan
Ranch Hand
Posts: 277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, after a day of experimenting, following code is the only way I can get a JMenuBar in an applet, which gets invoked by html. I can further refine it by putting the menu bar in a JTextArea in borderlayout north, but the question is whether there is a better way, and whether this code is the normal way to put a JMenuBar in an applet:
Is there a better way?
 
Jason Steele
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about:
import javax.swing.*;
import java.awt.*;
public class Applet extends JApplet {

/** Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void init() {
JFrame frame = new JFrame("TITLE");
JMenuBar jmb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem menuItem = new JMenuItem("MenuItem");
menu.add(menuItem);
jmb.add(menu);
Container c = frame.getContentPane();
c.add(jmb);
...add more content here...
frame.pack();
frame.show();

}

}

This would put the menu in a frame where it should be. Does this help?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic