473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Display Menu

Hi All

I'm a total newbie to Java.

I'm creating a very simple banking system as a college project. I'm doing ok... logging in the user, the displaying a Main Menu with options to select from. However Im using a If statement for the selection and once I have selected an option (for example = check account balance) I cant go back to the Main Menu (unless I write the whole thing out again, which would be daft).

I have tried to write a method (?) to display the menu, I can then put this at the end of my if statement to return the user to the Main Menu. However I can get it to work... Below is my menu code and below that the code i attempted for the method, if I can resolve this then im pretty much flying at the minute its the only thing holding me back!!!

Expand|Select|Wrap|Line Numbers
  1. //Show menu and get users choice
  2.         accChoice = JOptionPane.showInputDialog(null, "Account Menu \n" +
  3.                                           "What would you like to do? \n" +
  4.                                           " 1 - Check Balance.\n" +
  5.                                           " 2 - Make A Withdrawl.\n" +
  6.                                           " 3 - Make A Deposit.\n"+
  7.                                           " 4 - Amend Overdraft.\n" +
  8.                                           " 5 - Exit.\n" +
  9.                                           "Please enter your choice:");
  10.  
  11.     //direct users choice
  12.         if (accChoice.equals(accChoice1))
  13.         {
  14.             System.out.println("1 - Check Balance.");
  15.         }
  16.         else if (accChoice.equals(accChoice2))
  17.         {
  18.             System.out.println("2 - Make A Withdrawl");
  19.         }
  20.         else if (accChoice.equals(accChoice3))
  21.         {
  22.             System.out.println("3 - Make A Deposit.");
  23.         }
  24.         else if (accChoice.equals(accChoice4))
  25.         {
  26.             System.out.println("4 - Amend Overdraft.");
  27.         }
  28.         else if (accChoice.equals(accChoice5))
  29.         {
  30.             System.out.println("5 - Exit");
  31.         }
below is my method(s) code:

Expand|Select|Wrap|Line Numbers
  1. private String displayMainMenu()
  2.     {
  3.         String accChoice;
  4.         accChoice = JOptionPane.showInputDialog(null, "Account Menu \n" +
  5.                                           "What would you like to do? \n" +
  6.                                           " 1 - Check Balance.\n" +
  7.                                           " 2 - Make A Withdrawl.\n" +
  8.                                           " 3 - Make A Deposit.\n"+
  9.                                           " 4 - Amend Overdraft.\n" +
  10.                                           " 5 - Exit.\n" +
  11.                                           "Please enter your choice:");
  12.         return accChoice;
  13.  
  14.    }
May 22 '09 #1
2 9386
JosAH
11,448 Expert 8TB
If you can wait one more day or so then I'll post a little article about this topic because I've seen people struggle with this item more than often. The solution (which you can reuse over and over again!) will be a bit of code that represents a single menu item as well as an entire menu. You can nest menus at will and put in "back" and "quit" menu items whereever you want.

kind regards,

Jos

edit: done; read the 'insights' section of the Java forum: it contains a little article about this very topic.
May 30 '09 #2
Hi Josah,

Can I check where I can find the article on the display menu in java? Thanks!!
Jul 28 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Al Sav | last post by:
Hi, I am trying to create a menu for asp.net page. The menu-detail list display, when mouse hovers over the main menu list, like you see in regular windows apps. When the detail-menu-list window...
6
by: Jamie | last post by:
Hi all, I have a page in which I display a menu which is a table within a div element. Each cell in the table is a menu item with an "onclick" event handler assigned. I want to make it so...
7
by: Marc | last post by:
Hi everyone. I am having trouble with a stylesheet in mozilla. It is part of turning a list into a menu: #menu li{ margin: 0; display: inline; vertical-align: bottom;
12
by: mdb | last post by:
My app has a notify icon in the systray. I want the left mouse click to initiate a menu, and a right-mouse click to do something else. Normally, for a button, I would listen to MouseDown and if I...
4
by: txican | last post by:
the HTML is: ---------------------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html> <head> <title>foo</title>...
3
by: hzgt9b | last post by:
Using VS2005, VB.NET, I am developing a windows app that has a DataGridView. I want to enable the display of a context menu on this DataGridView only when a specific set of keys is also pressed...
0
by: rehanmomin | last post by:
Just to start off, I am writing a web application using C#. I have a Menu which is binded to an XML datasource. There are three menu items each with submenus and a textbox where I want to display...
2
by: giandeo | last post by:
Hello all, It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help....... I am working with an asp page...
2
by: wreed06 | last post by:
Hello, I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.