Working on a menu program

I got everything done on my program with a couple minor issues...first my clear button in the menu exits my program and my exit the program button does not do anything and everything looks right on my end...the other issue is I am getting two errors in the parsing and it looks right to me but I guess I am doing something wrong:
instructions:
1.     4 Labels (align them to the right by using the parameter Label.RIGHT when you construct your label� Label lengthLabel = new Label(�Enter the length: �, Label.RIGHT);)
2.     4 TextFields (2 for input and 2 for output� your output fields should be read-only). All of your TextFields can be length 10.
3.     2 Buttons� one to calculate the area and perimeter and one to exit� use the labels for the buttons shown below
area = length * width
perimeter = 2 * (length + width)
4.     create a menu for File -> Exit (to terminate the application)
5.     create a menu for Edit -> Clear (to clear all TextFields)
6.     only calculate/display the area and perimeter if length and width are valid and greater than zero� if not, display an error message in a dialog box, clear out all TextFields, and put the cursor in the length field.
7.     when you click the Calculate button, be sure all 4 values in the TextFields are formatted to two decimal places with a comma in the thousands place (see below)
8.     be sure to include code to terminate the application when the X is clicked
9.     use a GridLayout for the frame with 5 rows, 2 columns, and 5 pixels for spacing horizontally and vertically
10.     utilize the setActionCommand() method to allow for only one �exit� section of code in your actionPerformed() method
11.     have the Frame display in the center of the monitor with a width of 350 and height of 200
12.     have the Frame title of �Area and Perimeter of a Rectangle�
//import packages
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
//create a subclass at the fram class
public class RectangleApp extends Frame implements ActionListener
     //construct variables
     private Label lengthLabel = new Label("Enter the length: ", Label.RIGHT);
     private Label widthLabel = new Label("Enter the width: ", Label.RIGHT);
     private Label areaLabel = new Label("Area: ", Label.RIGHT);
     private Label perimeterLabel = new Label("Perimeter: ", Label.RIGHT);
     private Panel topPanel;
     private Button calculateButton = new Button("Calculate");
     private Button exitButton = new Button("Exit the Program");
     private TextField lengthField = new TextField(10);
     private TextField widthField = new TextField(10);
     private TextField areaField = new TextField(10);
     private TextField perimeterField = new TextField(10);
     private boolean first;
     private boolean clearText;
     private DecimalFormat calcPattern;
     private double length;
     private double width;
     private double area;
     private double perimeter;
     //constructor method
     public RectangleApp()
          //create an instance of the menu
          MenuBar mnuBar = new MenuBar();
          setMenuBar(mnuBar); //display the previously constructed MenuBar
          //construct and populate File Menu
          Menu mnuFile = new Menu("File"); //create a command on the MenuBar
          mnuBar.add(mnuFile);
          MenuItem mnuFileExit = new MenuItem("Exit");
          //construct a command to go under a menu
          mnuFile.add(mnuFileExit);
          //construct and populate the edit menu
          Menu mnuEdit = new Menu("Edit");
          mnuBar.add(mnuEdit);
          MenuItem mnuEditClear = new MenuItem("Clear");
          mnuEdit.add(mnuEditClear);
          //register the action listener with each of the menuitems
          mnuFileExit.addActionListener(this);
          mnuEditClear.addActionListener(this);
          //assign an ActionCommand to each of the MenuItems
          mnuFileExit.setActionCommand("Exit");
          mnuEditClear.setActionCommand("Clear");
          //construct components and initialize beginning values
          topPanel = new Panel();
          calcPattern = new DecimalFormat("###,###.##");
          topPanel.add(lengthLabel);
          topPanel.add(lengthField);
          length = 0.0;
          topPanel.add(widthLabel);
          topPanel.add(widthField);
          width = 0.0;
          topPanel.add(areaLabel);
          topPanel.add(areaField);
          area = 0.0;
          areaField.setEditable(false);
          topPanel.add(perimeterLabel);
          topPanel.add(perimeterField);
          perimeter = 0.0;
          perimeterField.setEditable(false);
          topPanel.add(calculateButton);
          topPanel.add(exitButton);
          //set layouts for the Frame and Panels
          setLayout(new BorderLayout());
          topPanel.setLayout(new GridLayout(5, 2, 5, 5));
          //add components to frame
          add(topPanel, BorderLayout.NORTH);
          //allow the x to close the application
          addWindowListener(new WindowAdapter()
               public void windowClosing(WindowEvent e)
                    System.exit(0);
          } //end window adapter
     } //end calculator[] constructor method
          public static void main(String args [])
               //construct an instance of the Frame (Calculator)
               RectangleApp f = new RectangleApp();
               f.setTitle("Area and Perimeter of a Rectangle");
               f.setSize(350, 200);
               f.setLocationRelativeTo(null);
               f.setVisible(true);
          } //end main
          public void actionPerformed(ActionEvent e)
               //test for menu item clicks
               String arg = e.getActionCommand();
          //exit was clicked
          if(arg == "Exit");
          System.exit(0);
          //clear was clikced
          if(arg.equals("Clear"))
               clearText = true;
               first = true;
          } //end if about
          //Calculate button was clicked
               if(arg.equals("Calculate"))
               convert data in TextField to int
               double length = Double.parseDouble(lengthField.getText());
               double width = Double.parseDouble(widthField.getText());
               double area = Double.parseDouble(areaField.getText());
               double perimeter = Double.parseDouble(perimeterField.getText());
               area = length * width;
               perimeter = length + width;
          } //end the if go
          //exitbutton was clicked
          if(arg.equals("Exit the program"))
               System.exit(0);
          } //end the if exit
     } //end action performed
} //end classby the way I know I have not done error checking just wanna make sure everything is right first before I check for errors

one last thing and thank you for all your help...calculates fine just only showing one decimal and I thought it is right how it is but must be doin something wrong with it
//import packages
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
//create a subclass at the fram class
public class RectangleApp extends Frame implements ActionListener
     //construct variables
     private Label lengthLabel = new Label("Enter the length: ", Label.RIGHT);
     private Label widthLabel = new Label("Enter the width: ", Label.RIGHT);
     private Label areaLabel = new Label("Area: ", Label.RIGHT);
     private Label perimeterLabel = new Label("Perimeter: ", Label.RIGHT);
     private Panel topPanel;
     private Button calculateButton = new Button("Calculate");
     private Button exitButton = new Button("Exit the Program");
     private TextField lengthField = new TextField(10);
     private TextField widthField = new TextField(10);
     private TextField areaField = new TextField(10);
     private TextField perimeterField = new TextField(10);
     private boolean first;
     private boolean clearText;
     private DecimalFormat calcPattern;
     private double length;
     private double width;
     private double area;
     private double perimeter;
     //constructor method
     public RectangleApp()
          //create an instance of the menu
          MenuBar mnuBar = new MenuBar();
          setMenuBar(mnuBar); //display the previously constructed MenuBar
          //construct and populate File Menu
          Menu mnuFile = new Menu("File"); //create a command on the MenuBar
          mnuBar.add(mnuFile);
          MenuItem mnuFileExit = new MenuItem("Exit");
          //construct a command to go under a menu
          mnuFile.add(mnuFileExit);
          //construct and populate the edit menu
          Menu mnuEdit = new Menu("Edit");
          mnuBar.add(mnuEdit);
          MenuItem mnuEditClear = new MenuItem("Clear");
          mnuEdit.add(mnuEditClear);
          //register the action listener with each of the menuitems
          mnuFileExit.addActionListener(this);
          mnuEditClear.addActionListener(this);
          //assign an ActionCommand to each of the MenuItems
          mnuFileExit.setActionCommand("Exit");
          mnuEditClear.setActionCommand("Clear");
          //construct components and initialize beginning values
          topPanel = new Panel();
          calcPattern = new DecimalFormat("###,###.00");
          topPanel.add(lengthLabel);
          topPanel.add(lengthField);
          length = 0.00;
          topPanel.add(widthLabel);
          topPanel.add(widthField);
          width = 0.00;
          topPanel.add(areaLabel);
          topPanel.add(areaField);
          area = 0.00;
          areaField.setEditable(false);
          topPanel.add(perimeterLabel);
          topPanel.add(perimeterField);
          perimeter = 0.00;
          perimeterField.setEditable(false);
          topPanel.add(calculateButton);
          calculateButton.addActionListener(this);
          topPanel.add(exitButton);
          exitButton.addActionListener(this);
          //set layouts for the Frame and Panels
          setLayout(new BorderLayout());
          topPanel.setLayout(new GridLayout(5, 2, 5, 5));
          //add components to frame
          add(topPanel, BorderLayout.NORTH);
          //allow the x to close the application
          addWindowListener(new WindowAdapter()
               public void windowClosing(WindowEvent e)
                    System.exit(0);
          } //end window adapter
     } //end calculator[] constructor method
          public static void main(String args [])
               //construct an instance of the Frame (Calculator)
               RectangleApp f = new RectangleApp();
               f.setTitle("Area and Perimeter of a Rectangle");
               f.setSize(350, 200);
               f.setLocationRelativeTo(null);
               f.setVisible(true);
          } //end main
          public void actionPerformed(ActionEvent e)
               //test for menu item clicks
               String arg = e.getActionCommand();
          //exit was clicked
          if(arg == "Exit")
          System.exit(0);
          //clear was clikced
          if(arg == "Clear")
               lengthField.setText("");
               widthField.setText("");
               areaField.setText("");
               perimeterField.setText("");
               first = true;
          } //end if about
          //Calculate button was clicked
               if(arg == "Calculate")
                    //convert data in TextField to int
                    double length = Double.parseDouble(lengthField.getText());
                    double width = Double.parseDouble(widthField.getText());
                    area = length * width;
                    perimeter = 2 * (length + width);
                    areaField.setText(String.valueOf(area));
                 perimeterField.setText(String.valueOf(perimeter));
          } //end the if calculate
               //exit the program was clicked
               if(arg == "Exit the Program")
               System.exit(0);
          } //end action performed
} //end class

Similar Messages

  • When I click on any of my movie or TV shows in Itunes I immediately get an error message that says Itunes has stopped working and closes the program. I can sync the movies and shows to my phone okay but I can't watch on Itunes. Can anyone help?

    When I click on any of my movie or TV shows in Itunes I immediately get an error message that says Itunes has stopped working and closes the program. I can sync the movies and shows to my phone okay but I can't watch on Itunes. Can anyone help?

    Let's try the following user tip with that one:
    iTunes for Windows 10.7.0.21: "iTunes has stopped working" error messages when playing videos, video podcasts, movies and TV shows

  • I have reloaded Icloud on my Windows 7 PC and it just says it stopped working and closes the program after I enter my apple password, what can I do?

    I am unable to use Icloud on my Dell PC. I have uninstalled it twice and reloaded it. When I enter my Apple password, it tells me that it has stopped working and closes the program. What can I do to correct this.

    Hi MamaTabs,
    If you are having issues signing in to iCloud on your Windows machine, you may find some of the troubleshooting in the following article helpful:
    iCloud: Account troubleshooting
    http://support.apple.com/kb/ts3988
    Also, you may want to make sure that you are running the most recent version of iCloud Control Panel for Windows:
    Apple: iCloud Control Panel 3.1 for Windows
    http://support.apple.com/kb/dl1455
    Regards,
    - Brenden

  • Itunes updated and now it won't work.  I unstalled it and reinstalled the older version and it still won't open. Says the itunes library won't work with the older program. Help

    Itunes updated and now it won't work.  I unstalled it and reinstalled the older version and reinstalled a older version and it still won't open.  Says the itunes
    library won't work with the older program.  Please help

    It says it cannot removed the older version of iTunes.
    Doublechecking before proceeding ... what's the precise text of that message, please? (There's a couple of different ones I can think of that you might be getting.)

  • Error message-The installer has insufficent privileges to modify this file:C:\Program Data\microsoft\windows\start menu\programs\iTunes\.iTunes.ink

    error message-The installer has insufficent privileges to modify this file:C:\Program Data\microsoft\windows\start menu\programs\iTunes\.iTunes.ink     
    How do I correct this to download iTunes so it will run?

    That one's consistent with disk/file damage. The first thing I'd try with that is running a disk check (chkdsk) over your C drive.
    XP instructions in the following document: How to perform disk error checking in Windows XP
    Vista instructions in the following document: Check your hard disk for errors
    Windows 7 instructions in the following document: How to use CHKDSK (Check Disk)
    Select both Automatically fix file system errors and Scan for and attempt recovery of bad sectors, or use chkdsk /r (depending on which way you decide to go about doing this). You'll almost certainly have to schedule the chkdsk to run on startup. The scan should take quite a while ... if it quits after a few minutes or seconds, something's interfering with the scan.
    Does the chkdsk find/repair any damage? If so, can you get an install to go through properly afterwards?

  • The credit card info on the account has changed but for some reason there is no option for me to make the changes.  In addition, cloud has stopped working and all other programs that need to be updated cannot be.

    the credit card info on the account has changed but for some reason there is no option for me to make the changes.  In addition, cloud has stopped working and all other programs that need to be updated cannot be??

    Make sure that EVERY DETAIL is the same in every place you enter your information
    -right down to how you spell and punctuate the parts of your name and address
    Change/Verify Account https://forums.adobe.com/thread/1465499 may help
    -Credit card https://helpx.adobe.com/utilities/credit-card.html
    -email address https://forums.adobe.com/thread/1446019
    -http://helpx.adobe.com/x-productkb/global/didn-t-receive-expected-email.html

  • ID & password is NOT working with the Menu Bar CC icon

    ID & password that I use for the Adobe CC web page login is NOT working with the Menu Bar CC icon (Mac OS 10.10.2). I have two updates to download, but the ID and/or password is rejected. Also the the "Hint" field is blank.https://forums.adobe.com/discussion/create.jspa?containerType=14&containerID=4670&question =true&subject=ID+%26+password+…

    If the is prompts like Creative Cloud wants to make changes to system :  Please enter Mac username and Password.

  • ITunes has stopped working: (Aproblem caused the program to stop...

    After I installed the the 64 bit I-Tune for widows 8, iTunes is crashing and I am getting the following message: iTunes has stopped working: (Aproblem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available). Please advise on how to solve this problem.

    Hi CCGoldwing,
    Thanks for using Apple Support Communities.  This article has steps you can take if iTunes is unexpectedly quitting:
    iTunes for Windows Vista, Windows 7, or Windows 8: Fix unexpected quits or launch issues
    http://support.apple.com/kb/ts1717
    Cheers,
    - Ari

  • Touchsmart webcam not working with any messenger programs.

    My Cam doesnt work with any messenger programs.. (yahoo, msn, skype...)  Just bought it right before christmas and appearantly im not alone in this... can anyone help? its the only way my husband and i can see each other because he is deployed to Iraq. Please help!!!

    Hi.
    first - please go to tools>options on skype, choose whichever is right for camera options and make sure the correct camera is appears in the drop-box. Anything with "hp-camera" or "cybershot" will do.
    if it still doesn't work you will need to open the touchsmart software and disable the camera usage through that software - because once a software uses the webcam - any other software cannot do use it. ( just like you cannot use the camera on skype and on msn messenger at the same time.
    here is the HP artical about hoe to enable webcams on touchsmarts - its long , but might be helpful
    http://h10025.www1.hp.com/ewfrf/wc/document?lc=en&dlc=en&cc=us&docname=c01923517
    hope this helps, let us know how it goes.

  • Cannot get my "attach" to work on my email program. I press it but it is not allowing to open window to browsw files that I want to attach to email

    Cannot get my "attach" to work on my email program. I press it but it is not allowing to open window to browsw files that I want to attach to email

    Hello William,
    Are you referring to Sony MiniDisc Recorder?
    Locate the model # from the below link.
    http://esupport.sony.com/US/p/support-info.pl?info_id=264
    The MiniDisc Recorder is not compatible with Windows 7 Operating System (OS) as these devices were released prior to the release of Windows 7 OS.
    If my post answers your question, please mark it as an "Accepted Solution."

  • I have Photoshop Elements 7.0 and when I go to sort the photos in order (from oldest date) I keep getting the message "Photoshop Elements 7.0 has stopped working" and then the program closes.  Sometimes, eventually it has sorted as I request but today thi

    I have Photoshop Elements 7.0 and when I go to sort the photos in order (from oldest date) I keep getting the message "Photoshop Elements 7.0 has stopped working" and then the program closes.  Sometimes, eventually it has sorted as I request but today this has been rejected over 15 times.  What is wrong?

    Try the licensing service update:
    http://helpx.adobe.com/creative-suite/kb/error-licensing-stopped-windows.html
    EDIT I see that maybe you did (is that the patch you mean? ); if so, try the other suggestions there.

  • After installation, why isn't PP CS4 showing up as a desktop shortcut or in Start Menu Programs?

    I have a new desktop for editing and have Windows 7 Pro loaded. With all other applications off, I installed PP CS4 with my program CD. Everything went smoothly without errors. When I wanted to open PP from Start Menu Programs, it wasn't listed. All of the accompanying Adobe software was listed except for Premiere. A shortcut on the desktop didn't appear either. Premiere is listed in the Control Panel under Programs & Features. It is also present in my C drive Program Files (x86) folder. Any thoughts about what happened and how I can fix it? Thanks!

    Hi Jim!
    Sorry I haven't responded for a month. I've been out-of-state on a family matter and have just returned.
    Here is what's in the PP CS4 folder:
    I followed the links to install the Windows Virtual PC feature into my Windows 7 Pro OS. I have attched the following screen shot that shows in the Note section at the bottom that the virtual application feature is not supported in Windows 7 Pro.
    Please let me know which way I should go from here.
    Thx!
    Sigrid

  • Nothing will print. My printer works with every other program, but not this one!

    Nothing will print. My printer works with every other program, but not this one!

    I see the printer, in blue when I click on the hardware tab. Actually there are 2 things listed that have to do with the printer.
    The first one is called:
                    HP Photosmart Prem C410 series (DOT4PRIN.... and under the Type it is listed as IEEE1284.4...
    The next is listed as:
                    HP Phototsmart Prem C410 series and under the Type heading it says Printers.
    I don't know which one to pick.  So when I choose the name highlighted in blue, what do I do to change the name?

  • TS3276 Sound works fine on all programs, but has suddenly stopped on Apple Mail.  No "submarine" sound when I send or receive email.  I checked the settings in "Preferences" in Apple Mail and it is set to "submarine" as the sound.  Any help?

    Sound works fine on all programs, but has suddenly stopped on Apple Mail.  No "submarine" sound when I send or receive email.  I checked the settings in "Preferences" in Apple Mail and it is set to "submarine" as the sound.  Any help?

    deleted previously imported key chain originated from the previous system (why doesn't apple provide a migration for my key chain?). after the deletion mail can receive and send again and dreamweaver starts without hanging.

  • Why is showing the message that  Photoshop has stopped working? Then the program closes alone

    Why is showing the message that  Photoshop has stopped working? Then the program closes alone
    I bought the program today and does't work

    These questions below may be for a different product... but the KIND of information you need to supply is the same, for the products you use
    More information needed for someone to help... please click below and provide the requested information
    -Premiere Pro Video Editing Information FAQ http://forums.adobe.com/message/4200840

Maybe you are looking for

  • How can i find out which of  my contacts do not use whatsapp?

    I am using iPhone 5S on iOs 7.0.2 I am conducting an event where I want to send invitations to almost all my contacts. Since there is daily limit on the number of Text Messages I can send out in a single day in my country, I want to segregate my cont

  • The ultimate java problem: can't fix it anyway...

    Folks, Somehow I am stuck in this strange situation where I can't get my java to work properly. Some background: 1) I migrated from an old mac with Snow Leopard to a new mac with Lion (migration assistant) 2) I try to do some fixing by myself (good o

  • Database in recovery

    Our server ran out of disk space during a stored procedure process. We were able to free up some space, stopped all SQL services, restarted all SQL services and now SQL Management Studio shows the database to be in recovery.  Is there a way to monito

  • BAPI to update XREF3 in FB01

    Hi Gurus, Do you know some BAPI that can be use to update XREF3 field or the Reference Key 3 in FB01 using  (inbound) IDOC? Thanks!

  • Need help for Work flow

    Hi there! I logged into SAP and I can see TRIPS in my inbox for processing. However, i need to have the parked documents from Affordable Housing in my inbox as well.  Can any one guide me How can i resolve this one? Thanks in advance