473,394 Members | 1,965 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,394 software developers and data experts.

Menu help using JSwing

nomad
664 Expert 512MB
Hello everyone.
I have being trying to under stand a simple menu, and I have read alot of text on this, but I'm still confused.
I have found and re worked a simple menu and I need to find out how to make it work.
When you click on New how does it know where to go.
I'm working a project when a client click on "New" they will be prompt to enter a persons ID number, thou a Scanner. The scanner will check to see if the id number is listed or not. Info or data is stored in Arraylist.
Any advice or direction on how to do this would be great.

thanks
nomad


Expand|Select|Wrap|Line Numbers
  1. package company;
  2.  
  3.  
  4. import java.awt.*;
  5. import javax.swing.*;
  6. import java.awt.event.*;
  7.  
  8.  
  9.  
  10. /**
  11. * @param args
  12. */
  13.  
  14.     // TODO Auto-generated method stub
  15.     /*
  16.     <APPLET
  17.      CODE = menu.class
  18.          WIDTH = 350
  19.          HEIGHT = 280 >
  20.     </APPLET>
  21.     */
  22.  
  23. public class Sample_menu extends JApplet implements ActionListener
  24.         {
  25.             public void init()
  26.             {
  27.     JMenuBar jmenubar = new JMenuBar();
  28.  
  29.     JMenu jmenu1 = new JMenu("File");
  30.     JMenuItem jmenuitem1 = new JMenuItem("New..."),
  31.             jmenuitem2 = new JMenuItem("Find.."),
  32.             jmenuitem3 = new JMenuItem("Exit");
  33.  
  34.     jmenu1.add(jmenuitem1);
  35.     jmenu1.add(jmenuitem2);
  36.     jmenu1.addSeparator();
  37.     jmenu1.add(jmenuitem3);
  38.  
  39.     jmenuitem1.setActionCommand("You selected New");
  40.     jmenuitem2.setActionCommand("You selected Find");
  41.  
  42.     jmenuitem1.addActionListener(this);  //
  43.     jmenuitem2.addActionListener(this);
  44.  
  45.  
  46.         jmenubar.add(jmenu1);
  47.         setJMenuBar(jmenubar);
  48.             }
  49.  
  50.  public void actionPerformed(ActionEvent e)
  51.         {
  52.              JMenuItem jmenuitem = (JMenuItem)e.getSource();
  53.  
  54.              showStatus(jmenuitem.getActionCommand());
  55.          }
  56.  
  57. }
  58.  
  59. kbd = new Scanner(System.in);
  60.         System.out.print("\nPlease press Enter afer each response");
  61.         System.out.print("Enter ther Employee ID Number");
  62.        abc_flag  = kbd.nextInt();
  63.  
  64.  
Mar 22 '07 #1
1 1807
r035198x
13,262 8TB
Hello everyone.
I have being trying to under stand a simple menu, and I have read alot of text on this, but I'm still confused.
I have found and re worked a simple menu and I need to find out how to make it work.
When you click on New how does it know where to go.
I'm working a project when a client click on "New" they will be prompt to enter a persons ID number, thou a Scanner. The scanner will check to see if the id number is listed or not. Info or data is stored in Arraylist.
Any advice or direction on how to do this would be great.

thanks
nomad


Expand|Select|Wrap|Line Numbers
  1. package company;
  2.  
  3.  
  4. import java.awt.*;
  5. import javax.swing.*;
  6. import java.awt.event.*;
  7.  
  8.  
  9.  
  10. /**
  11. * @param args
  12. */
  13.  
  14.     // TODO Auto-generated method stub
  15.     /*
  16.     <APPLET
  17.     CODE = menu.class
  18.          WIDTH = 350
  19.          HEIGHT = 280 >
  20.     </APPLET>
  21.     */
  22.  
  23. public class Sample_menu extends JApplet implements ActionListener
  24.         {
  25.          public void init()
  26.          {
  27.     JMenuBar jmenubar = new JMenuBar();
  28.  
  29.     JMenu jmenu1 = new JMenu("File");
  30.     JMenuItem jmenuitem1 = new JMenuItem("New..."),
  31.          jmenuitem2 = new JMenuItem("Find.."),
  32.          jmenuitem3 = new JMenuItem("Exit");
  33.  
  34.     jmenu1.add(jmenuitem1);
  35.     jmenu1.add(jmenuitem2);
  36.     jmenu1.addSeparator();
  37.     jmenu1.add(jmenuitem3);
  38.  
  39.     jmenuitem1.setActionCommand("You selected New");
  40.     jmenuitem2.setActionCommand("You selected Find");
  41.  
  42.     jmenuitem1.addActionListener(this); //
  43.     jmenuitem2.addActionListener(this);
  44.  
  45.  
  46.         jmenubar.add(jmenu1);
  47.         setJMenuBar(jmenubar);
  48.          }
  49.  
  50. public void actionPerformed(ActionEvent e)
  51.         {
  52.          JMenuItem jmenuitem = (JMenuItem)e.getSource();
  53.  
  54.          showStatus(jmenuitem.getActionCommand());
  55.          }
  56.  
  57. }
  58.  
  59. kbd = new Scanner(System.in);
  60. System.out.print("\nPlease press Enter afer each response");
  61. System.out.print("Enter ther Employee ID Number");
  62. abc_flag = kbd.nextInt();
  63.  
  64.  
You are using swing and yet you are trying to get input using the console.
Use swing to get the input as well. You put the code for taking the input inside the appropriate action handling method.
Mar 23 '07 #2

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

Similar topics

1
by: Rick | last post by:
Hi, I'm having problems with Java applets. I just generated a JApplet (also tried normal Applet) in Netbeans which is delivered with the newest JDK. When I compile it in Netbeans it seems to...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
8
by: Dennis C. Drumm | last post by:
Is there a way to modify the standard context menu shown when someone right clicks in a windows text box and that would work for all open windows applications? The standard context menu for...
7
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote...
1
by: goRide | last post by:
Hi, I'm looking of a way (preferred - a ready class or dll) to customize the context menu. many application has more controls inside the context menu (like textbox, sliders, checkbox, panel...
4
by: Bob Homes | last post by:
In VB6, I used a system, which I loved, whereby I assigned a "helpId" to each menu item; that way, you could rest the cursor on the item (without actually running it) and then press F1 to get...
6
by: Ben Fidge | last post by:
Hi I've just created a new Master Page for my site and it uses the native Menu control. Strange behaviour is happening on page that use the master page. For some reason, the menu controls...
2
by: Gary Wessle | last post by:
Hi I need help organizing this program in the right way. I included the code below which compiles and runs and gives the desired effect to a certain point, but I don't know what the next step...
1
by: Anthony | last post by:
Below is a script I found at http://javascript.internet.com/ for a cascading menu. The script works great but there is one thing that I would like modified. BecauseI am just learning javascript,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.