Solved

what mistake have I made

Posted on 2006-11-05
4
209 Views
Last Modified: 2010-03-31
When I declare this, "JMenuItem item;" now what mistake have I made in the code?

               menuBar = new JMenuBar();
           JMenu menu = new JMenu("Menu");
             item=new  JMenuitem()
             JMenuItem item = new JMenuItem("Item Labelxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            setJMenuBar(menuBar);
                  //item.addActionListener(actionListener);
                   File7.add(item);
                   File7.add(menu);
                   menu.add(item);
                  
            pane.add(File7);
                  //item.addActionListener(actionListener);
                  
                  item.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
       // this will get called
}});
//item.addActionListener(actionListener);

      setVisible(true);
     }
0
Comment
Question by:charliebaby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17876660
Delete

>> item=new  JMenuitem()
0
 

Author Comment

by:charliebaby
ID: 17876698
how come There is no fuction to select  "JMenuItem item = new JMenuItem("Item Labelxxxxxxxxxxxxxxxxxxxxxxxxxxx");" when I run the program All I get is a solid unfuctioning menu bar?
then I will close out the question, and thanks again and again.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 17876705
0
 

Author Comment

by:charliebaby
ID: 17876768

    frame.setJMenuBar(menuBar); is the only thing not included, been there before, constructed my menu from that link, Menu  shows up in the frame only with out any fuctionalty. Oh well any more advice would be great...heres your points thanks

USED THIS
 item.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
       // this will get called
}});

Deleated THIS
 "item.addActionListener(actionListener);" as well as what you suggested >> item=new  JMenuitem() (gone) I am going to include the whole code so you can have a look:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;

public class Hw_prog1     extends
                              JFrame {

     Hw_prog1Event TRON = new Hw_prog1Event(this);

     JButton Calculate;

     JButton Clear;

     JButton Exit;

     JTextArea area;

     JScrollPane scrollPane;
      
       JMenuBar menuBar;
      
        JMenuItem item;
          JComboBox term;
             

     JPanel File1 = new JPanel();
      
     JLabel PrincipalLabel = new JLabel("$Enter Loan Amount:", JLabel.CENTER); // create
                                                                                               // first
                                                                                               // row
                                                                                               // (File)

     JTextField LonAmt = new JTextField(8);

     JPanel File2 = new JPanel();

     JLabel RateLabel = new JLabel("0.0Enter Interest Rate:", JLabel.CENTER); // create
                                                                                               // second
                                                                                               // row
                                                                                               // (File)

     JTextField Rat = new JTextField(8);

     JPanel File3 = new JPanel();

     JLabel TermLabel = new JLabel("Enter Term-Years:", JLabel.CENTER); // create
                                                                                     // third row
                                                                                     // (File)

     JTextField Trm = new JTextField(8);

     JPanel File4 = new JPanel();

     JLabel PaymentLabel = new JLabel("Monthly Payments:", JLabel.CENTER); // create
                                                                                          // forth
                                                                                          // row
                                                                                          // (File)

     JTextField MthlyPymnt = new JTextField(8);

     JPanel File5 = new JPanel(); // create fifth row (Buttons)

     JPanel File6 = new JPanel();
      
       JPanel File7 = new JPanel();

     // create borders(Grid layout)
     public Hw_prog1() { // Reference the main method
          super("McBride.Financial.MortCal"); // Calling setSize
          setSize(890, 130); // set size
             

          // name Buttons
          Calculate = new JButton("Calculate");
          Clear = new JButton("New Amount");
          Exit = new JButton("Exit");
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // inform Frame to close

          GridLayout layout = new GridLayout(1, 5, 10, 10); // calls the
                                                                         // TextFeild & sets
                                                                           // paramerters
          Container pane = getContentPane(); // holds the feilds in place &
           //menuBar = new JMenuBar();                                            // generates a ‚ÄòContainer‚Äô
                                                 // object that represents the pane
          pane.setLayout(layout); // checks known parameters
          PrincipalLabel.setForeground(Color.magenta);
          RateLabel.setForeground(Color.blue);
          TermLabel.setForeground(Color.magenta);
          PaymentLabel.setForeground(Color.red);

          Calculate.setForeground(Color.magenta);
          Clear.setForeground(Color.blue);
          Exit.setForeground(Color.red);

          pane.setForeground(Color.blue);

          // TRON listens for Button fuctions
          Calculate.addActionListener(TRON);
          Clear.addActionListener(TRON);
          Exit.addActionListener(TRON);
//item.addActionListener(actionListener);
          // ‚ÄòFlowLayout‚Äô components fall into place from left to right
          FlowLayout mgr = new FlowLayout(FlowLayout.CENTER, 10, 10); // sets
// parameters
          File1.setLayout(mgr); // Directs the user were to place data
          File1.add(PrincipalLabel); // add Component
          File1.add(LonAmt); // add Component
               //JMenu menu = new JMenu("Menu Label");
   // menuBar.add(menu);
   
          pane.add(File1);

          FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER, 10, 10);
          File2.setLayout(layout2);
          File2.add(RateLabel);
          File2.add(Rat);
          pane.add(File2);

          FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER, 10, 10);
          File3.setLayout(layout3);
          File3.add(TermLabel);
          File3.add(Trm);
          pane.add(File3);

          FlowLayout layout4 = new FlowLayout(FlowLayout.CENTER, 10, 10);
          MthlyPymnt.setEditable(false);
          File4.setLayout(layout4);
          File4.add(PaymentLabel);
          File4.add(MthlyPymnt);
          pane.add(File4);

          FlowLayout layout5 = new FlowLayout(FlowLayout.CENTER, 5, 5);
          File5.setLayout(layout5);
          File5.add(Calculate);
          File5.add(Clear);
          File5.add(Exit);
          pane.add(File5);

          FlowLayout layout6 = new FlowLayout(FlowLayout.CENTER);
          File6.setLayout(layout6);
               JTextArea area = new JTextArea(5, 10); // 5 rows and 10 columns
          JScrollPane scrollPane = new JScrollPane(area); // add the text area to
               File6.add(scrollPane);
            pane.add(File6);
             FlowLayout layout7 = new FlowLayout(FlowLayout.CENTER);
          File7.setLayout(layout7);

               menuBar = new JMenuBar();
           JMenu menu = new JMenu("Menu");
             //item=new  JMenuitem()
             JMenuItem item = new JMenuItem("Item Labelxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            setJMenuBar(menuBar);
                  //item.addActionListener(actionListener);
                   File7.add(item);
                   File7.add(menu);
                   menu.add(item);
                  
   
            pane.add(File7);
                  //item.addActionListener(actionListener);
                  
                  item.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent event) {
       // this will get called
}});
//item.addActionListener(actionListener);

      setVisible(true);
     }

     public static void main(String[] arguments) {

          Hw_prog1 frame = new Hw_prog1();

     }

     class Hw_prog1Event implements ActionListener {
          Hw_prog1 virtual;

          public Hw_prog1Event(Hw_prog1 in) {
               virtual = in;              

          }

          public void actionPerformed(ActionEvent event) {
               String command = event.getActionCommand();
               if(event.getSource() == Calculate)
                    LaunchComputation();
               if(event.getSource() == Clear)
                    reset();
               if(event.getSource() == Exit)
                    System.exit(0);
          }

          void LaunchComputation() { // sub-program to do math
               try // when called
               {
                    double LonAmt = Double.valueOf(virtual.LonAmt.getText()).doubleValue(); // Object
                                                                                                              // &
                                                                                                              // string,
                                                                                                              // double
                                                                                                              // value
                                                                                                              // when
                                                                                                              // Tron
                                                                                                              // calls
                                                                                                              // virtual
                    double Rat = Double.valueOf(virtual.Rat.getText()).doubleValue();
                    int Trm = Integer.parseInt(virtual.Trm.getText());
                    int totalmonths = (Trm * 12);
                    double Payment = 0;
                    String monthlyPayment = new String();
                    NumberFormat currency = NumberFormat.getCurrencyInstance();
                    double I = (Rat / 100.0 / 12.0);

                    Payment = (LonAmt * I) / (1 - Math.pow(1 / (1 + I), totalmonths));
                    virtual.MthlyPymnt.setText(currency.format(Payment));
               } catch (NumberFormatException ex) {
               }
          }

          protected void reset() {
               virtual.LonAmt.setText(null);
               virtual.Rat.setText(null);
               virtual.Trm.setText(null);
               virtual.MthlyPymnt.setText(null);
          }
     }

}

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question