A calculator programe, I want to use NumberPad to calculate

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
class calculatorPanel extends JPanel implements ActionListener{
     private boolean first = true;
     private int result =0;
     private String op = "=";
     private JTextField screen;
     public calculatorPanel(){
          setLayout(new BorderLayout());
          screen = new JTextField(10);             //
//          screen.setEditable(false);
          screen.setHorizontalAlignment(JTextField.RIGHT);
/*          screen.addKeyListener(new KeyAdapter(){
               public void KeyTyped(KeyEvent e){
                    String s = "";
                    char c = e.getKeyChar();
                    if(c >= '0' && c <= '9'){
                         if(first){     
                              screen.setText(s+c);
                         else
                              screen.setText(screen.getText()+c);
                         first = false;
                    else{
                         if(first){
                              if(c == '-'){
                                   screen.setText(s+c);
                                  first = false;
                              else{
                                   op = s;
                         else{
                              String t = screen.getText();
                               int x = Integer.parseInt(t.substring(0,t.length()-1));
                               calculate(x);
                               op = s+c;
                               first = true;
                         if(c == 'c'){
                              screen.setText("0");
                              result = 0;
                              first = true;
                              op = "=";
          add(screen,"North");
          JPanel p = new JPanel();                         //??????????????????
          p.setLayout(new GridLayout(4,4,5,5));          //
          String buttons = "789/456*123-0c=+";          //
          for(int i=0;i < buttons.length();i++)          //
               addButton(p,buttons.substring(i,i+1));
          add(p,"Center");
     private void addButton(Container c,String s){
          JButton b = new JButton(s);
          c.add(b);
          b.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
          b.addActionListener(this);
//          b.addKeyListener(new KeyAdapter());
     public void actionPerformed(ActionEvent e){
          String s = e.getActionCommand();
          if(s.charAt(0) >= '0' && s.charAt(0) <= '9'){
               if(first)     screen.setText(s);
               else
                    screen.setText(screen.getText()+s);
                    first = false;
          else{
               if(first){
                    if(s.equals("-")){
                         screen.setText(s);
                        first = false;
                    else op = s;
               else{
                int x = Integer.parseInt(screen.getText());
                calculate(x);
                op = s;
                first = true;
               if(s.equals("c")){
                    screen.setText("0");
                    result = 0;
                    first = true;
                    op = "=";
     public void calculate(int n){
          if(op.equals("+")) result += n;
               else if (op.equals("-")) result -= n;
               else if (op.equals("*")) result *= n;
               else if (op.equals("/")) result /= n;
               else if (op.equals("=")) result  = n;
               screen.setText(""+result);
class calculatorFrame extends JFrame{
     public calculatorFrame(){
          setTitle("Calculator");
          setSize(200,200);
          Container contentPane = getContentPane();
          contentPane.add(new calculatorPanel());
          addWindowListener(new WindowAdapter(){//
               public void windowClosing(WindowEvent e){
                    System.exit(0);
public class calculator{
     public static void main(String args[]){
          JFrame frame = new calculatorFrame();
          frame.show();
//          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//          frame.setVisible(true);
//          frame.pack();
}

So what is your problem?
One obvious thing is that in your commented out code you have a method
public void KeyTyped(KeyEvent e){
but if you are expecting this to be invoked when a key is pressed then you will be disappointed. The method name should probably be 'keyPressed' or maybe 'keyReleased'.

Similar Messages

  • In email, when I click on a "pdf" file, how do i get it to just open instead of being asked what program I want to use?

    When I get a "pdf" in an email and I click on the "pdf" button, I am always asked what program I want to use. How do I get the file to just open automatically?

    You can specify in Windows what program to use for a given extension, for instance Adobe Acrobat Reader, for files with PDF extension. How you can connect the program and the extension, is described in this article; [http://windows.microsoft.com/en-US/windows-vista/Change-which-programs-Windows-uses-by-default "Change which programs Windows uses by default"]
    In Firefox PDF links get opened automatically with Acrobat reader. When clicking on PDF attachments in Thunderbird, however, you will need to associate the program and the extension as described in the above article.
    Hope it helps!

  • Trying to download a trial product but it keeps asking me what program I want to use to download it??

    Trying to download a trial product but it keeps asking me what program I want to use to download it??

    try a different brower.
    if that fails, what link and what product/version for what os?

  • I can't open the downloaded evaluation copy of Project Professional 2013. Asks me what program I want to use to open the file.

    I can't open the downloaded evaluation copy of Project Professional 2013.  Asks me what program I want to use to open the file.

    I think you have downloaded .img file. If you want to install that program follow the given instruction.
    download open source magic disc viewer software.
    http://www.magiciso.com/tutorials/miso-magicdisc-overview.htm
    After installation, right click on notification icon of magic disc, click Virtual CD/DVD ROM ->  No Media -> Mount,
    Select disc image file of project professional 2013.img.
    Open My Computer -> select mount drive and install that program.

  • Firefox is asking me what program I want to use to open firefox. It has never done this before.

    Several days ago an XP internet Security 2012 invaded my computer. It would not let me do anything except sign up for a $60 program. It did allow me to send a message to its support stall. But of course I could not get to my email to read their answer. Yesterday I went to safe mode Firefox and that allowed me to get to my email. The message from XP internet security apologized and suggested that I set the date on my computer 6 days ahead and that would remove their program. So I did and their program is gone. But now whenever I want to use firefox it asks me what program I want to use, I select Firefox and the site opens. Also I can not change to date back to normal. When I go to the control panel and click on date and time, it says application not found and does the same thing for most everything else in the control panel.

    '''''XP internet Security 2012''''' is malware masquerading as anti-malware. You may need to go to an un-infected computer to read the following article, to download the tools needed to remove it (then transport them to your infected system on a CD or DVD; avoid using a pin/jump/thumb/USB drive to transport the files as it can become infected).
    *http://www.bleepingcomputer.com/virus-removal/remove-xp-internet-security-2012
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    Not related to your question, but...
    You may need to update some plug-ins <u>after you get the infection cleared</u>. Check your plug-ins and update as necessary:
    *Plug-in check --> http://www.mozilla.org/en-US/plugincheck/
    *'''''Adobe Shockwave for Director Netscape plug-in''''': [https://support.mozilla.com/en-US/kb/Using%20the%20Shockwave%20plugin%20with%20Firefox#w_installing-shockwave Installing ('''''or Updating''''') the Shockwave plugin with Firefox]
    *'''''Adobe PDF Plug-In For Firefox and Netscape''''': [https://support.mozilla.com/en-US/kb/Using%20the%20Adobe%20Reader%20plugin%20with%20Firefox#w_installing-and-updating-adobe-reader Installing/Updating Adobe Reader in Firefox]
    *'''''Shockwave Flash''''' (Adobe Flash or Flash): [https://support.mozilla.com/en-US/kb/Managing%20the%20Flash%20plugin#w_updating-flash Updating Flash in Firefox]
    *'''Next Generation Java Plug-in for Mozilla browsers''': [https://support.mozilla.com/en-US/kb/Using%20the%20Java%20plugin%20with%20Firefox#w_installing-or-updating-java Installing or Updating Java in Firefox]

  • Instead of running firefox.exe, computer asks me to "choose the program you want to use to open this file".

    When I click on either the firefox shortcut or firefox.exe in the Mozilla folder, instead of running, the computer asks me to "Choose the program you want to use to open this file: firefox.exe". The recommended program is Adobe Reader 9.1, which obviously doesn't help.
    I have uninstalled firefox and downloaded it again, but now I am trying to run Firefox Setup 4.0.exe, and it asks me again to "Choose the program you want to use to open this file: firefox setup 4.0.exe" Help?

    This is a registry problem with your .exe entry
    The below program worked for me on my vista machine.
    http://windowsxp.mvps.org/exefile.htm
    You can download an exe file from there that automatically sorts the issue or you can edit the registry manually.

  • When i open firefox, i get asked what program i want to use to open this file.

    when i open firefox, i get asked what program i want to use to open this file. i select firefox to open firefox, and it opens to - Index of file:///C:/Documents and Settings/HP_Administrator/- instead of my home page. this has been going on for months. today i updated my kaspersky intrnet security 2011 and since then fire fox will only open in firefox safe, even if i shut down kaspersky. IE opens with no problems.
    thanks
    jeff

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • Trying to download a FIrefox and when I click on run it asks what program I want to use to open with so I cant finish install

    I've been using FF for years and lately have been having issues with internet access. Worked through the troubleshooting suggestions and got it working, but last night FF couldn't connect to internet after something updated and my Norton anti virus was gone too and I couldn't fix it. The last resort was to delete my ff and download new, so I did. When I clicked on run I got a pop up asking what program I wanted to open it with and of course nothing worked. By then it was 1:30 am so I quit. Today I'm having the same issue and I'm at the end of my rope trying to figure out what to do. I'm so disgusted and can't stand it.

    # Go to the following page and scroll down to the language you're interested in.
    #* http://www.mozilla.org/firefox/all/
    # Next to that language, right-click the arrow icon for Windows, choose Save Target As and save the file somewhere handy, like the desktop.
    # Run the installer you downloaded.

  • Wdows asks me which program I want to use but there is not a Firefox icon to click on to open a file.

    In windows I am having a problem when it ask what program do you want to open this file. I do not have a Firefox icon to click from the the list. Am I suppose to have an icon for Firefox Icon, or what do I do?
    I use Windows 7 an use Google for my searches

    You should never select Firefox as the program to handle a file when you get the "Open with" dialog.<br />
    If you would set an automatic action for this file type then you end up with tabs getting opened endlessly.<br />
    If Firefox would be able to handle this file then you wouldn't get this dialog.
    Can you tell us with which file type this happens?
    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    *https://support.mozilla.org/kb/how-do-i-create-screenshot-my-problem
    Use a compressed image type like PNG or JPG to save the screenshot.
    *https://support.mozilla.org/kb/Firefox+keeps+opening+many+tabs+or+windows
    *https://support.mozilla.org/kb/change-firefox-behavior-when-open-file

  • Since updating firefox to 5.0 my computer is having numerous problems and i'm asked what program i want to use to open firefox when i click on the desktop icon. What's the problem?

    When i click on control panel to remove the program i get the file not found box. if i try to use verizon or internet explorer, i get the file not found box. I tried to download a program i need to view netflix movies and after the program downloads i'm told file not found.

    '''''XP internet Security 2012''''' is malware masquerading as anti-malware. You may need to go to an un-infected computer to read the following article, to download the tools needed to remove it (then transport them to your infected system on a CD or DVD; avoid using a pin/jump/thumb/USB drive to transport the files as it can become infected).
    *http://www.bleepingcomputer.com/virus-removal/remove-xp-internet-security-2012
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    Not related to your question, but...
    You may need to update some plug-ins <u>after you get the infection cleared</u>. Check your plug-ins and update as necessary:
    *Plug-in check --> http://www.mozilla.org/en-US/plugincheck/
    *'''''Adobe Shockwave for Director Netscape plug-in''''': [https://support.mozilla.com/en-US/kb/Using%20the%20Shockwave%20plugin%20with%20Firefox#w_installing-shockwave Installing ('''''or Updating''''') the Shockwave plugin with Firefox]
    *'''''Adobe PDF Plug-In For Firefox and Netscape''''': [https://support.mozilla.com/en-US/kb/Using%20the%20Adobe%20Reader%20plugin%20with%20Firefox#w_installing-and-updating-adobe-reader Installing/Updating Adobe Reader in Firefox]
    *'''''Shockwave Flash''''' (Adobe Flash or Flash): [https://support.mozilla.com/en-US/kb/Managing%20the%20Flash%20plugin#w_updating-flash Updating Flash in Firefox]
    *'''Next Generation Java Plug-in for Mozilla browsers''': [https://support.mozilla.com/en-US/kb/Using%20the%20Java%20plugin%20with%20Firefox#w_installing-or-updating-java Installing or Updating Java in Firefox]

  • I need to reverse the command and let the computer use Windows to search the program I want to use t

    I am not sure if you can help me.  I need to command my computer to look for a program that is most suited to open files automatically.  I accidentally check the mannual mode and appointed Adobe Reader x to be the designated program.  Now nothing will open.  How can I undo what I did last night and reverse the process to restore my original setting?

    You made Adobe Reader the default progrm for what: .pdf files, or anything else?
    "Nothing will open" means what, programs, files, any files?
    Try a System Restore to a date before you made the change.

  • When desktop chortcut is clicked, it says choose the program you want to use to open this file

    When I click on FireFox in the recommended programs, it extracts data and asks me to re-install FireFox every time. This is for both the desktop shortcut and the toolbar shortcut.
    I recently had a virus that my McAfee got rid of that wouldn't let me go online

    Please download
    * http://www.sevenforums.com/attachments/tutorials/123734d1312706455-default-file-type-associations-restore-default_exe.reg
    restore your default '''exe''' file association and try
    * download it
    * run it
    * yes>yes>ok
    then try to run Firefox

  • When I click on the 'help' key in the elements 12 program it wants to open it in Firefox2. Firefox doesn't work on my Macbook Pro Air. I use Safari. How do I get it to open?

    When I click on the 'help' key in the elements 12 program it wants to open it in Firefox2. Firefox doesn't work on my Macbook Pro Air. I use Safari. How do I get it to open?

    Hmm, that is very strange. I agree with MichelB that it's probably best just to get the PDF, but you can try going to your username>library>preferences and deleting:
    com.adobe.PhotoshopElements.plist
    Adobe Photoshop Elements 12 settings
    Adobe Photoshop Elements 12 paths
    To see the library, click the Go menu in the Finder and hold down the option key and it will appear below the little house for your user account. While you're in there it wouldn't be a bad idea to go to the Saved Application States folder and delete anything pertaining to PSE.
    Repair permissions and see if that does it.

  • Don't Want To Use Apple Config, Device Enroll Program

    I have been reading a lot on how to implement profiles onto devices like the iPhone, this functionality is what I am looking for, mainly with iPhone for some businesses and schools I work with. I have red that with the new technology you don't have to us Apple Configurator, and I have red about the Device Enroll Program... for my purposes I don't want to use any Apple method (nor would the situation I have even qualify for the Device Enroll Program) I really would like to deploy custom configuration profiles, with restrictions specified by my customers.
    I have been scanning the developer guides and and slowly grasping what I need to do...it sounds like I don't need to use Apple methods if I don't want CORRECT???  If I can implement custom profiles and in some cases it might just be three iPhones... I was hoping to find the proper guidance for implementing those custom profiles, thru the webpage method  or e-mail message is more suitable for my needs.
    I found the Apple play by play on how to do that, but sometimes for myself finding another perspective helps me learn... Any places anyone has found that can give that play by play on how to deliver those custom profiles  thru web page or e-mail?
    I have looked at the Over the Air Profile Delivery and Configuration Developer Pages... I'm just looking for that alternate information source to help me out. Appreciate all the help 

    Using Get Info to change all documents to open with Pages 4.3 doesn't work. The Mac OS will always default to the newest installed version & has for as long as I can remember. It will work on individual files, but that could be a lot of files to reset.
    This is what worked for me. After I installed the new iWork updates I created a folder on an external drive & named it "Applications." I then moved the new iWork apps to this folder & renamed the applications Keynote 6, Pages 5 & Numbers 3. I have icons for two versions of Pages & Numbers (I rarely use Keynote) in my Dock. Even with two versions of Pages & Numbers running, double-clicking an existing file opens in Pages 4.3 or Numbers 2.3. This should also keep the Mac App Store from nagging you to update.
    Since the last update I've used the solution Peter Breis posted (4th post in that thread) in iWork Tips 'n' Tricks with a little "tweak."
    Making Numbers '09 the default whilst keeping Pages 5
    1. Move any new iWork apps in another clearly labelled folder (I created a new folder in Applications & named it iWork 13)
    2. Menu > Apple > System Preferences > Spotlight > Privacy > drag the above folder into the list
    2) Move the new iWork folder into the trash (temporarily)
    3) Select any Numbers file in Finder > Menu > Info (cmd+i) > Open with: > Pages '09 > Change all
    4) Re the new iWork folder from the trash (right-click > Put back)
    Pages 5 should no longer appear as a default App, and you won't have to keep a copy in a separate drive or dmg.
    IMPORTANT: Make a note of where and how Pages was installed for the next App Store update and temporarily move it back there before putting it away again in the folder concealed from Spotlight.

  • I want to use Boot Camp to run a tax program that will only use explorer. Whick windows program do I need to install in Boot Camp

    I want to use Boot Camp and windows 7 or 8, preferrably 7 to run a tax program that will only let me use explorer.  I am using a Mac Book Pro with OSX Maverick 10.9.  There are so many windows programs out there it is confusing which one I need.  I don't think that I will need Office.

    http://www.apple.com/support/bootcamp/
    I would use Windows 7 any full version except the trial, or a branded Dell, HP, etc. versions

Maybe you are looking for

  • Save the uploaded file in a different name ?

    Has anyone used the com.oreilly.MultipartRequest Class which is used to upload a file to a directory.I am able to that fine.I now need a way to save the uploaded file to a different name when it gets saved in its destination.I am not sure if com.orei

  • Change Slideshow Size Dynamically

    Wanted to see if I can change the Slideshow size while it plays using: http://labs.adobe.com/technologies/spry/articles/element_selector/index.html The factory script shows an error; (I added div.content and then copied and changed the content class)

  • How to update VM Server 2.1.1

    Hi, I am trying to install iscsi-target-0.4.16 in a VM Server (see Metalink doc. 567407.1) (The objective is to create a sharable disk for RAC on an Oracle VM environment). However, the VM Server does not have required packages (such as cc, the C com

  • Add custom fields

    Hi all,    Please provide me with some guidance for below activity . How to add custom fields to ERDK table (print doc header ) by creating our own Z FM similar to the existing FM provided in R436 event . suppose the field is FIELD NAME u2013 FLAG TY

  • Does it cost to download previously purchased songs/vides from I Phone onto I Pad 3

    does it cost to download previously purchased songs/vides from I Phone onto I Pad 3?