?
Solved

what mistake have I made

Posted on 2006-11-05
4
Medium Priority
?
217 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

743 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