...

View Full Version : java menu



nickyfraggle
02-06-2008, 02:25 PM
Hello,

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.

Thanks!!

Nicola

Aradon
02-06-2008, 03: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("Menu:");
System.out.println("1) Do something");
System.out.println("2) Do Something Else");
System.out.print("Choice: ");


//// use keyboard input to get value
if(choice.equalsIgnoreCase("1"))
// do something
}
}

etc. etc.

nickyfraggle
02-06-2008, 03:46 PM
Hello,

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?

Nicola



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum