0

I'm trying to make a Java applet with a menu (stretching across the screen with different mode options), and I want to make it have two different modes.

Is the best way to do this making two different applets that are run by a application, or should I use something different like a JFrame (I would rather use an Applet), or should I use a bunch of if statements in the paint method and such?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user2371168
  • 47
  • 1
  • 3
  • 1
    What do you mean by menu? Do you mean a menu bar? – MadProgrammer Jun 27 '13 at 00:28
  • 1
    1) Why code an applet? If it is due due to spec. by teacher, please refer them to [Why CS teachers should stop teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson Jun 27 '13 at 06:32

3 Answers3

1

You have a number of options.

Personally, I would start with a custom component (say JPanel), which has the ability of accepting Actions

I would then create a JButton per Action you add on this panel. I would then add this panel to the main, top level container.

This allows you to produce a configurable base menu and separate the logic of each menu item from the concerns of the menu interface.

Take a look at How to use Actions for more details

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
0

I think you should think about another possibilities if you're developing a web application, like, for instance, jQuery, JavaFX, JSF...

Crom
  • 83
  • 1
  • 7
0

There is a bit of confusion there I believe. Your Applet will be your application host, the JFrame is an object that is typically a "host" on its own (standalone application), so: "I use something different like a JFrame(I would rather use an Applet)" makes no sense.

You want to have an applet with a menu, and to get that you have to do what you normally do in a java standalone application:

JMenuBar - Part 1

You don't need to create a JFrame either, because an applet is a top level container, so using a JPanel will do.

MeTitus
  • 3,390
  • 2
  • 25
  • 49