View Full Version : java menu

02-06-2008, 03:25 PM

I am trying to create a menu in Java.

I have looked at the Java sun website, and aside from their do it in visual studio tutorials, their only lesson on writing menu's doesn't seem to work...or rather I can't get it to work!!

Does anyone have some simple code I could look at to work this out...

Just a basic menu...no submenus required.



02-06-2008, 04:07 PM
Menu for what? A console application? A GUI? What have you written thus far? We wont do it all for you, but we will help you out.

If you're talking about GUI menus then you want:

Menu Tutorial (http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html)

If you're talking about console applications, then that's just a matter of printing to screen something and taking in user input.

public class menu

public static void main(String args[])
System.out.println("1) Do something");
System.out.println("2) Do Something Else");
System.out.print("Choice: ");

//// use keyboard input to get value
// do something

etc. etc.

02-06-2008, 04:46 PM

Thanks for your reply.

It is for a GUI.

I now have it working, I hadn't attached the menu items to the menu bar...

But...I'm struggling with getting FlowLayout to position the menu on the left hand side of the GUI.

How do I do this?