Trapping and making use of keyboard keys in java

hello friends,
wish to seek your advice and help once again. i'm trying to create a 'calculator' application using java. i've created buttons that represent such keys like: '*', '/', '\', '+', '-' etc. and '1', '2', '3', '4', '5' etc. but i don't know what to do so that when i click on the button '2' and then the button '*' and again the button '5' and finally on the button '='; it will know how to multiply '2' with '5' and give me a result of '10' on the textfield. please, any advice from someone will be appreciated. thanks in advance.

If it's just clicking on a button you're asking, you need to add an actionListener to each button, then in actionPerformed() you need to identify the button to determine what action to take
e.g. if the button is 0 to 9, displayTextfield += button.getText()
if the button is +, currentTotal += displayTextfield.getText() etc
I have a working calculator at a website, which might give you a few ideas. A lot of the code deals with a strip list, and the order of the + - / * = keys
e.g if I want to deduct 2 from 4, the keystrokes are 4+2- , not like small calculators 4-2=
http://michael-dunn.freeservers.com/java/Calculator.htm

Similar Messages

  • When my most front window is a safari one and I use the shortcut key "Command N", it opens a new finder window and a new safari window at the same time. Why does it happen?

    When my most front window is a safari one and I use the shortcut key "Command N", it opens a new finder window and a new safari window at the same time. Why does it happen?

    I just found the solution!
    Niel
    Re: Why is my Finder window popping up when I open my Safari window? 
    Jan 20, 2008 7:58 PM (in response to alak)
    Open the General tab of the Safari preferences and correct the home page; the default page is this one. If it has become set to a folder on an FTP server or a local drive, that request will be sent to the Finder. (28252) 
    iMac Late 2007 Core 2 Duo, Mac OS X (10.5.1)

  • I have a G5 PPC Dual 20" Mac Displays - I want to incorporate a Mac Mini and still use my keyboard and Monitors and Switch back and forth. How do I do this?

    I have a G5 PPC Dual 20" Mac Displays - I want to incorporate a Mac Mini and still use my keyboard and Monitors and Switch back and forth. How do I do this?

    The Hatter,
    I am a novice at Mac so I read all I can.  From what I understand the NEC monitors I bought require Display Port for their maximum performance.  The GTX 680 only has DVI outputs.  Difference from what I understand is larger bandwidth with the DP.
    You said I have the 4000 for CUDA.  I am not all that familiar with CUDA and when I do read about it I do not understand it. 
    A concern I have is, that if I connect the 2 high end NEC monitors via the 5770, using it's 2 Display Ports I would have nothing connected to the 4000.  Is the 4000 doing anything with nothing connected?  I read where in a PC system the 2 cards would interact but in a Mac system they do not.
    Bottom line, as I see it, the 4000 will not be useful at all to me, since I want a dual monitor set-up.
    So far the 5870 seems the best choice, higher band width than the 5770, and it has 2 Display Ports to optimize the NEC monitors.
    I'm not sure how fine I am splitting hairs, nor do I know how important those hairs are.  I am just trying to set up a really fast reliable system that will mainly be used for CS6 and LR4.  Those NEC monitors are supposed to be top notch.

  • Cp4 and Accessibility - Using the Tab key

    What is the best way to create a Cp4 files where the viewer uses the Tab key to navigate through the course? 
    Thanks for your assistance.
    Sheri

    Hi Sheri,
    You might need to hard-code this --
    var so = new SWFObject("yourProjectName.swf", "Captivate", "640", "511", "10", "#CCCCCC"); // Below this Line
    so.addParam("seamlessTabbing", "false"); // Add This
    on the Published HTML file and save it.
    Thanks,
    Anjaneai

  • Making use of the Key.ALT isDown

    I need to make a keyhandler which will respond to the alt key
    being pressed, but all i get is the menu. in my experience most
    prgrams do not activate the menu's unless the altkey is released
    with no other action, OR if alt+? is selected.
    So, i am hoping that there is a way to make it so that
    alt+arrow_key can be targeted... anyone?
    -E

    VoxEcho,
    > I need to make a keyhandler which will respond to the
    > alt key being pressed, but all i get is the menu.
    What menu are you talking about? Are you in the IDE? Are you
    testing
    in a web page? In a Projector?
    > in my experience most prgrams do not activate the menu's
    > unless the altkey is released with no other action, OR
    if alt+?
    > is selected.
    On WinXP Home, I see the file menu take focus in Flash,
    Photoshop, and
    Word when I hit Alt by itself. Maybe I don't understand what
    you're asking?
    > So, i am hoping that there is a way to make it so that
    > alt+arrow_key can be targeted... anyone?
    Your subject line kind of points in the right direction. :)
    Look up
    the Key class in the ActionScript 2.0 Language Reference;
    specifically, the
    Key.isDown() method -- you'll see some sample code. Note:
    this is for
    *most* cases. For better or worse, though, Alt is the odd one
    out. Alt
    does not trigger the Key.onKeyDown or Key.onKeyUp event.
    You have to constantly check for the Alt key in a loop of
    some kind,
    such as setInterval() or MovieClip.onEnterFrame ...
    this.onEnterFrame = function() {
    if (Key.isDown(18)) {
    trace("Alt is being pressed!");
    ... and you have to know that the key code for Alt is 18. A
    big difficult,
    because that number is mysteriously missing from the Keyboard
    Keys and Key
    Code Values entry of the documentation.
    David Stiller
    Adobe Community Expert
    Dev blog,
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • Adobe Reader crashes during reading pdf whenever I use keyboard keys, like ctrl f or keyboard arrows.pls help

    I cannot normally read pdfs because it always crashes whenever I use any keyboard keys. Please help!

    wow, it works like a charm now! thank you SO much for your help! it was soooo annoying as you can only imagine

  • Several laptop keyboard keys not working

    Dear all,
    I hope you can help me. Several keys on my HP Spectre 13-3000ea ultrabook occassionally don't work. More specifically, the n,m,h,j,y,u,6,7 keys (if you check your keyboard you see they constitute a vertical area of keys) do not work, most often when the laptop boots from cold or resumes from sleep. I can get them to work by rapidly hitting other keys in the neighbourhood and swiping my finger across these keys. All of the sudden they 'wake up' again and they will work. Sometimes, randomly, they will stop functioning again and the problem appears to become worse.
    It is not a software related problem which support seems keen on, since I experience exactly the same problem in Ubuntu Linux and also in the BIOS. I have the feeling it is related to the connector ribbon but I'm having a bit of a difficult time convincing HP Support of this, especially because the occurrences seem random. If you have any ideas on how to solve this problem, please let me know.
    Edit: I forgot to mention I never spilled anything over my keyboard and I used a keyboard brush to clean under the keys as well as I could, since the keys are not removable.
    Thanks in advance

    Hello 
    Test the keyboard using UEFI diagnostics. http://h10025.www1.hp.com/ewfrf/wc/document?docname=c03467259&cc=us&dlc=en&lc=en#N341
     If the keyboard test fails, contact HP Support at 1-800-474-6836 and them know the test failed. 
    While I am an HP employee I am speaking for myself.

  • Have no mouse and a non-apple keyboard

    i recently got this computer as a hand me down so I could get accustomed to Mac OS. unfortunately it did not come with a keyboard or a mouse and all i have available right now is a non-apple keyboard. I'm having difficulty trying to navigate my way through anything. Can anyone help?

    Hi, s2loco -
    Eww is correct.
    For many things there are keyboard workarounds. For example, if you are looking at the desktop, press the up-arrow key - that should highlight the upper-leftmost icon on the desktop; you can then use the arrow keys to navigate from icon to icon on the desktop. Note though that you can only travel that way in a straight line, laterally or vertically.
    You can also press the initial letter of the filename of the item - even the first two if you're fast enough - and the alphabetical-earliest item whose filename starts with that lerr(s) will be selected. You can then press Command-O as before.
    You can also press 1 to select an item that starts with 1, or the earliest item alphanumerically, and then use the Tab key to move from one item to the next in alphanumerical order.
    These methods will also work in a folder set to List view as well as one set to Icon view.
    Once the icon of an item you want to activate (open if it is a folder, start if it is a program, open with its creator program if it is a document) is selected, pressing Command-O (that's the letter "O", lower case) will initiate that action.
    However - although the Enter key can be used in most windows to activate the default button, there is no keyboard solution to using pulldown menus, or to select items in a radio-button array (like in control panels), or (in most windows) to click a button other than the default one. For those a mouse is needed.
    Just as important is using a keyboard which is compatible with Apple command keys. Although there are many non-Apple keyboards which are Mac-compatible, many, if not most, PC keyboards are not - it is iffy whether the Window, Alt, or whatever-they-use keys on such will behave like the keys on Mac-compatible keyboards.
    If you have a working mouse, then you can sidestep the absence of keyboard command compatibility on such keyboards - except at startup. No matter how well we maintain our Macs, at some point or another we will need to use one or more startup commands - to zap the PRAM or rebuild the desktop; or to select an alternate boot volume; or to access Extensions Manager before the OS loads; or for some other crisis-based reason. For that reason it is wise to have a Mac-compatible keyboard available.

  • Use of keyboard

    Hello, My name is Gunner Hodgson and I recently started using a Macbook Pro. To start with, I would like to say that I love it. I also purchased the Apple Pro Keyboard, because as a student I have to type 10 page essays and I don't want to get carpel tunnel. I have some beef with both keyboards. The Macbook Pro keyboard is not wide enough, I tend to hit tab instead of Q, caps lock instead of A or shift instead of Z. My roommate has a macbook, and none of these problems are present. The keys are well spaced and typing is once again not a battle. I have none of these problems with my Apple Pro Keyboard, the key spacing is good, and mistypes are purely operator error. However, the key throw is so far my typing speed suffers dramatically from the Macbook Pro keyboard. You have to push the keys down so far that many times I end up having to go back and fix a mistake when I hit the key, but not hard enough. It sounds like I am whining, I know, but this problem could easily be solved. If apple could come out with an "Apple Pro II keyboard" with less of a keythrow, I beleive that that would be very helpful. or they could make the keyboard on the Macbook Pro wider, or more like the Macbook, with the wide spacing. If anyone echoes my thoughts, please let me know, and maybe we can try and get a request through to apple.
    Your reading is appreciated,
    Gunner Hodgson

    I can see how that may be a problem for some people however you may be then better off attaching a USB keyboard that is to your liking while you are typing long essays or at home and just use the keyboard while on the road so to speak.
    I personally dislike the Macbook keyboard and prefer the MBP keyboard even though I have large hands. I guess it may have something to do with the fact that i'm accustomed to small spacing and have modified my typing habits even on past laptops to squeeze my hands into the space that it is second nature.
    Good luck either way though but I don't believe that your comment will hold a lot of water here since people with the power to do this don't generally hang out on the message boards.
    You'd be better off sending an email directly to Apple stating your suggestion.

  • My backlit keyboard keys not working?

    How come my backlit keyboard keys not working? When I try to use them I get a circle with a line running through it?

    cpickrell wrote:
    Jax, the backlight is currently usinig a sensor to turn the light on and off for you. This uses the least amount of battery. If you want to test or control the lighting yourself, go to the Apple Menu, select System Preferences, click on the Keyboard icon. Here you can turn the automatic setting on and off. If it is off, you can use they keyboard keys to turn the keyboard lighting on and off.
    Exactly!

  • Bluetooth keyboard key sticking

    The letter "y" keeps sticking and producing a long string of "y's" Have tried turning on/off keyboard.
    Anybody know what else I can try short of taking it back to an Apple store
    Thanks
    Rick

    Did you spill something on the keyboard?
    Do a Google search using "sticky keyboard key". There's lots of "solutions". Here's one -
    http://www.associatedcontent.com/article/260783/computertips_how_to_unsticksticky.html?cat=59
     Cheers, Tom

  • Replacing keyboard keys

    Am I able to go to an Apple store and have a few keyboard keys replaced? A few of them have become sticky due to a minor liquid spill, (after clean-up) but are still fully functioning.

    Not likely. Stores don't usually stock keycaps, and I don't believe Apple supplies them individually. Your best bet is to find someone who has a dead keyboard to get them from.
    But stepping back to the actual problem: it's very unlikely that any liquid has remained on your own keycaps if you've given them a good wash, so it's equally unlikely that replacing them will remedy whatever is causing them to stick. The problem is almost certainly below them.

  • Load LiDAR data into Spatial 11g making use of Point Cloud Type?

    Dear all,
    from an aerial LiDAR scan I have approximately 226 million points, spread over 9 files. I would like to load them into Oracle Spatial 11g, making use of the new point cloud data type. I have the book "Pro Oracle Spatial for Oracle Database 11g" here and Appendix E explains how you have these two tables that together manage your point cloud. I find the example given in the book rather simplified though as they have only x, y and z and a row id colum. In addition to this I also have r, g, b and i (intensity) values.
    I was wondering if anyone could give me a hint on how to store all the information in one table and making use of the sdo_pc data type at the same time.
    Also, the example has the points already in a table, but I'd like to load it all directly from my files into the point cloud table (I know how to use sqlldr, but how do I get it into this point cloud table structure). What's the cleverest way to go about this?
    All ideas are greatly appreciated!!
    Regards,
    Bia.

    Hi,-
    Our LAS converter supports LAS 1.1 format.
    LAS version 1.0 has fewer entries for the data than LAS version 1.1 so you might just ignore those extra fields that donot exist in LAS 1.0.
    Therefore, i am expecting your data to be fine with our LAS to SDO_PC converter.
    Thanks

  • Using of function keys (F1, F2...) in Java Webdynpro

    Hi
    i would like to ask whether we can use the function keys like f1, f2, .....in the java webdynpro applications
    and if so how it is possible to do so
    Regards
    JM

    thanks
    where will i get a list of keys that you were refering
    " some keys are reserved by the browser and cannot be used by Web Dynpro applications. "
    and secondly i want to know about the function keys (f1, f2....)whether we can use these function keys in java webdynpro and not for hot keys
    if you can share the information with me it would be good
    Regards
    JM

  • Volume keyboard keys

    I recently bought my laptop and not my volume keyboard key short cuts have stopped working. 

    Hi @katiejay ,
    Thank you for visiting the HP Support Forums and Welcome. I have looked into your issue about your HP Pavilion 15 notebook and issues with special keys. You can do a system restore. System restore will help if something automatically updated and did not go well on the Notebook.
    When performing a System restore please note remove any and all USB devices. Disconnect all non-essential devices as they can cause issues.
    You could try in the Control Panel, Clock, Language and Region, Language click Advanced Settings in the left pane.Then in Advanced settings, click Change Language bar hot keys.
    In Text Services and Input Languages, click Change Key Sequence button and enable the the key sequence.
    Here is a link to uninstall the keyboard. Restart the computer after uninstalling, it should reinstall automatically.
    Let me know how this goes.
    Thanks
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the bottom to say “Thanks” for helping!

Maybe you are looking for