Multiple key-bound Action

Lets say I have a Navigation action
     class NavigationAction extends AbstractAction {
          static final String START = "START";
          static final String BACK = "BACK";
          static final String FORWARD = "FORWARD";
          static final String END = "END";
          public void actionPerformed(ActionEvent e) {
               String cmd = e.getActionCommand();
               if (cmd.equals(START)) {
                    navigationStart();
               } else if (cmd.equals(BACK)) {
                    navigationBack();
               } else if (cmd.equals(FORWARD)) {
                    navigationForward();
               }  else if (cmd.equals(END)) {
                    navigationEnd();
     }This single action is set to 4 buttons. Each button has a one of the NavigationAction static fields as action command and actual method call is distinguished with command string.
That is all fine.
BUT,
Now i want to assign arrow keys to each for navigation. All I can do is
navigationAction.putValue(Action.ACTION_COMMAND_KEY, NavigationAction.FORWARD);and this way I can have a single action class respond to ONLY ONE key binding.
Is there any way to use multiple keybindings with single action? This would mean adding command string to inputMap for a specific JComponent, but is not supported now.
Any other options?

A simple answer to this question is to use getActionCommand() from the source of the event which is a JButton (with the correct action command) instead of ActionEvent#getActionCommand(). Like this:
class NavigationAction extends AbstractAction {
     static final String START = "START";
     static final String BACK = "BACK";
     static final String FORWARD = "FORWARD";
     static final String END = "END";
     public void actionPerformed(ActionEvent e) {
          String cmd = "none";
          if (e.getSource() instanceof JButton) {
               cmd = ((JButton)e.getSource()).getActionCommand();
          if (cmd.equals(START)) {
               navigationStart();
          } else if (cmd.equals(BACK)) {
               navigationBack();
          } else if (cmd.equals(FORWARD)) {
               navigationForward();
          }  else if (cmd.equals(END)) {
               navigationEnd();
}

Similar Messages

  • How do you register multiple key presses at the same time?

    Hi. I'm trying to write a first person game in OpenGL and I'm having some trouble with key listening. Right now I just use the basic AWT KeyListener. The problem that arises is that whenever I hold down a key, such as a movement key, there is a short pause after it moves me in the appropriate direction, and only after the pause does it start continuously moving me. In addition to that, I can't press multiple keys at once to get diagonal movement (I use WASD for movement). Is there something I can do with AWT to fix both of these problems, or is there something other than AWT that I should use that would be better?

    the pause is the typomatic rate of the keyboard, you can avoid that by using the keyPressed and setting a flag then a sleep(myDelayTime).... if they keyRelease--and clearing of the flag--hasn't happened after the sleep, then you're key is still down so keep firing, moving, or what ever.

  • How to get Multiple Key Combinations

    Hi,
    I am trying to get the event for multiple key combinations, ie some thing like "*Ctrl + I + M*" or "*Alt + A + S + D*".
    For two key combinations ( like Ctrl+I or Ctrl+M) i am able to get, but for more than two keys combinations, can someone give an idea how to get it.
    I tried with both KeyCodeCombination and KeyCharacterCombination.
    Below is a quick example to check for the key combination demo.
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.input.KeyCharacterCombination;
    import javafx.scene.input.KeyCode;
    import javafx.scene.input.KeyCodeCombination;
    import javafx.scene.input.KeyCombination;
    import javafx.scene.input.KeyEvent;
    import javafx.scene.layout.StackPane;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    public class KeyCombinationDemo extends Application {
         Stage stage;
         Scene scene;
         StackPane root;
         public static void main(String[] args) {
              Application.launch(args);
         @Override
         public void start(Stage stage) throws Exception {
              this.stage = stage;
              root = new StackPane();
              root.getChildren().add(new Label("Enter any Key"));
              this.scene = new Scene(root, Color.LINEN);
              stage.setTitle(this.getClass().getSimpleName());
              stage.setWidth(600);
             stage.setHeight(600);
             stage.setScene(this.scene);
             stage.show();
              final KeyCombination keyComb1=new KeyCodeCombination(KeyCode.I,KeyCombination.CONTROL_DOWN);
              final KeyCharacterCombination keyComb2 = new KeyCharacterCombination("M",KeyCombination.CONTROL_DOWN);
              this.scene.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
                   @Override
                   public void handle(KeyEvent event) {
                        if(keyComb1.match(event)){
                             System.out.println("Ctrl+I pressed");
                        }else if(keyComb2.match(event)){
                             System.out.println("Ctrl+M pressed");
    }Thanks in Advance.
    Regards,
    Sai Pradeep Dandem.

    Hi John,
    Thanks for the prompt response.
    I tried the way you suggested and it worked well !! Thanks :)
    But, still i am expecting a direct way to handle this. :p
    Anyway here is code which i modified accordingly
    final String keyCombination1 = "_ALT_E_O";
    final String keyCombination2 = "_ALT_E_P";
    final String keyCombination3 = "_CONTROL_H";
    final StringBuilder key = new StringBuilder();
    this.scene.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
         @Override
         public void handle(KeyEvent event) {
              String codeStr = event.getCode().toString();
              if(!key.toString().endsWith("_"+codeStr)){
                   key.append("_"+codeStr);
    this.scene.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
         @Override
         public void handle(KeyEvent event) {
              if(key.length()>0){
                   if(key.toString().equals(keyCombination1)){
                        System.out.println("Key Combination 1 pressed");
                   }else if(key.toString().equals(keyCombination2)){
                        System.out.println("Key Combination 2 pressed");
                   }else if(key.toString().equals(keyCombination3)){
                        System.out.println("Key Combination 3 pressed");
                   key.setLength(0);
    });Thanks & Regards,
    Sai Pradeep Dandem

  • Multiple key level associations

    Hi,
    I am getting the below error during the consistency check.
    Table, X, has multiple key level associations.
    Can anyone please let me know the reason for the same.
    Also, when I drag the physical tables from the physical layer to the BMM Layer, there are some default primary keys in the Logical Table.What considerations does OBIEE take into when deciding upon the Primary Key in the Logical table.
    Thanks in Advance
    Akshatha

    "can you check the keys foreign keys for those table "
    You didn't mention what I should be checking for.
    However, I think I've worked it out now.
    I have a dimension table that is referenced by both other dimension tables and the fact tables. Therefore, when imported into BI, both the dimension tables and the fact tables have foreign keys to this common dimension table.
    I'm guessing that the foreign keys on the dimension tables are not required - because there are foreign key references from the fact tables to the common table anyway. Bearing in mind that this is a star schema and not a snowflake schema.
    => I deleted all the foreign keys from all my dimension tables, and now the consistency check works ok.

  • BPC for Excel: Are multiple key ranges really possible?

    Hi Experts,
    in a training document I found to possibility of multiple key ranges, to make an input schedule sheet more attractive or insert rows with excel formulas etc.
    For example: ColKeyRange: EVRNG(H13:J13;M13:O13)
    RowKeyRange: EVRNG(G15:G20;L15:L20)
    In my case I want the balance sheet separated. On the left side asset positions, on the right side liability positions (in columns for bot: Previous Year | Actual | Plan
    If I define my input schedule like that it gets messed up. No figures, weird formatting etc. Have you implemented an input schedule with multiple key ranges and did it work ok?
    Thank you,
    Cora

    Hi Cora,
    Yes, multiple key ranges do work, but it is a bit complicated as Dzmitry suggests. Your example row expansion will not work, as the row expansion needs to remain in the same columns for each part of the expansion. (In other words, EVRNG(G15:G20;L15:L20) is wrong but EVRNG(G15:G20;G25:G30) is ok.) To achieve your result, Dzmitry is correct that you will probably need to use two EVDREs.
    That said, multiple expansions work as follows:
    If you are not using an expansion, or you use NOEXPAND in your columns or rows, you can use a multiple key range for formatting purposes and simply hardcode in the members that you wish to see in each key range.
    If you want to see different expansions in each key range, then you need to use a special expansion syntax. To take your example, say you have a single dimension in your column with column range defined EVRNG(H13:J13;M13:O13). You could have your column expansion on the category dimension be "PRIORYR,ACTUAL,PLAN|PLAN,ACTUAL,PRIORYR", giving you the same set of categories reversed in each column.
    Ethan

  • Thinkpad keyboard problem - some keys generate multiple keys when pressed

    thinkpad keyboard problem - some keys generate multiple keys when pressed
    For example, "t" generates "tr", "y" generates "yu", "backspace" generates "backspace" plus "IBM access connections", "m" generates "mn" and "n" generates "mn".  Not all keys are wrong. 
    For what it's worth, the odd behaviour started shortly after a trip to Miami in which I had a meeting at a cafe in which we were undercover but it was pouring cats and dogs - it was like having a meeting in a sauna - so I am wondering if the high humidity could have caused the behaviour.
    I tried replacing the keyboard but the new keyboard has the same problem.  
    The machine in question is a Thinkpad T23 running Windows XP Pro
    Any help would be appreciated as I am now in Los Angeles using a borrowed Mac! :-) 

    i have something along the lines of the same problem.
    http://bbs.archlinux.org/viewtopic.php?id=56777
    my conclusion is something in the last system update screwed it up.

  • How to sort on MULTIPLE Keys which are elements of VO's stored in  list

    How to sort on MULTIPLE Keys which are elements of VO's stored in a list.. without disturbing the ordering done by previous sorting...?
    Is there any best soln for the same...
    Thanks..

    How to sort on MULTIPLE Keys which are elements of
    VO's stored in a list.. without disturbing the
    ordering done by previous sorting...?Do you mean you want to do a heirarchical sort? Where the secondary key is only used when the primary keys are equal etc.? That's pretty trivial. If the primary keys are equal, check the secondary key. How do you sort words in alphabetical order? It's the same process.

  • BDB- Recno multiple key/data pairs retrieval

    Hey,
    I am new to BDB and have just started to work with Berkley DB (ver. 5.3.15) using the Linux C API.
    I set up a simple Recno DB which is populated with sequential keys 1,2,3….100. DB Records are in variable length size, although, I am limiting them to a max size.
    Below are the environment and DB open flags I am using:
    dbenv->open(dbenv, DB_HOME_DIR, DB_SYSTEM_MEM | DB_INIT_LOCK | DB_CREATE | DB_INIT_MPOOL, 0)
    dbp->open(dbp, NULL, NULL,DATABASE_NAME, DB_RECNO, DB_CREATE, 0664))
    Single record get/put or using cursor to iterate over the all DB works well.
    However, I would like to retrieve multiple records in a single get call.
    These records can be non-sequential.
    For example, retrieving 3 records with the keys 4,89,90. I prefer the bulk buffer to be as minimal as possible (avoiding stack or heap unnecessary memory allocation).
    I was reading and saw few examples about using bulk retrieval. Though, I couldn’t find any example for racno bulk get on multiple specified keys.
    From what I figured out till now, it seems that I should use:
    Get flags: DB_SET_RECNO, DB_MULTIPLE_KEY. And the macros: DB_MULTIPLE_INIT and DB_MULTIPLE_RECNO_NEXT to iterate over a bulk buffer received.
    But, I couldn’t figure it out where and how I should specify the list of Keys.
    Beside, the BDB man says: "For DB_SET_RECNO to be specified, the underlying database must be of type Btree, and it must have been created with the DB_RECNUM flag."
    Does the BDB open with DB_RECNO flag imply that the underlying database is Btree? If creating Btree instead of recno, wouldn’t I loss access performances?
    I would appreciate if anyone could supply some guidelines or an example which will assist me to figure it out how to retrieve multiple key/data pairs from a recno DB.
    Thanks in advance
    Kimel

    I am checking the BDB to see if it can suit my needs (mostly performance wise).
    It should work on a simple home router device and should hold router runtime information (static/dynamic).
    This information should be accessible for process in the system which can write or read the device info.
    The DB is not require to be persistent and is recreated every reboot (memory only).
    I believe the DB will hold not more then 200 parameters at max.
    DB access rate is around 30 records per sec (write/read)...
    Currently, I think of either BDB or maybe just use a normal Linux shared memory (random access + semaphore).
    Cons and pros to each...
    If I choose BDB, I will use the in memory DB and recno due to access performance considerations.
    Getting back to my question, I would like to be able to read a list of parameters in a single get call.
    In order to use recno, I will give every parameter a unique id (1 - ip, 2 - subnet , 3 - default gateway).
    e.g: ip , subnet , default gateway. (get keys 1,2,3)
    Hope you have the relevant info.
    Thanks

  • Copy & paste multiple key frames?

    Is there a way to copy and paste multiple key frames?
    Thanks.

    Drawing a marque around multiple keyframes is easy, too. You can select a property and all of its keyframes will be selected. You can performa sophisticated choices of non-continguous keyframes with command-select. You can also do lots of editing in the graph view.

  • IsKeyDown - Multiple key detection ?

    does anyone know of how to read two keys or check two keys are down/pressed?
    I am trying to do a game where the object can mover diagonally so i need the game to react differently if 2 cursor keys are down?
    Any ideas about the isKeyDown() function?
    The keypressed/ keyreleased function i think will only detect one at a time.
    cheers all

    Try this quick Swing App I knocked up using Sun One. It shows multiple key detection, doesn't mind simultaneous key presses.
    I wrote the code for clarity more than anything else.
    Run it, see what it does and how it reacts to the cursor keys being pressed.
    * KeyEvents.java
    * Created on 05 December 2002, 16:21
    package andy.apps.KeyEvents;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class KeyEvents extends javax.swing.JFrame {
        /** Creates new form KeyEvents */
        public KeyEvents() {
            initComponents();
            upPanel.registerKeyboardAction(new UpOnListener(), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, false), JComponent.WHEN_IN_FOCUSED_WINDOW);
            upPanel.registerKeyboardAction(new UpOffListener(), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, true), JComponent.WHEN_IN_FOCUSED_WINDOW);
            downPanel.registerKeyboardAction(new DownOnListener(), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, false), JComponent.WHEN_IN_FOCUSED_WINDOW);
            downPanel.registerKeyboardAction(new DownOffListener(), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, true), JComponent.WHEN_IN_FOCUSED_WINDOW);
            leftPanel.registerKeyboardAction(new LeftOnListener(), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, false), JComponent.WHEN_IN_FOCUSED_WINDOW);
            leftPanel.registerKeyboardAction(new LeftOffListener(), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, true), JComponent.WHEN_IN_FOCUSED_WINDOW);
            rightPanel.registerKeyboardAction(new RightOnListener(), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0, false), JComponent.WHEN_IN_FOCUSED_WINDOW);
            rightPanel.registerKeyboardAction(new RightOffListener(), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0, true), JComponent.WHEN_IN_FOCUSED_WINDOW);
        class UpOnListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.upPanel.setBackground(Color.black);
        class UpOffListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.upPanel.setBackground(Color.white);
        class DownOnListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.downPanel.setBackground(Color.black);
        class DownOffListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.downPanel.setBackground(Color.white);
        class LeftOnListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.leftPanel.setBackground(Color.black);
        class LeftOffListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.leftPanel.setBackground(Color.white);
        class RightOnListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.rightPanel.setBackground(Color.black);
        class RightOffListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.rightPanel.setBackground(Color.white);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            upPanel = new javax.swing.JPanel();
            leftPanel = new javax.swing.JPanel();
            downPanel = new javax.swing.JPanel();
            rightPanel = new javax.swing.JPanel();
            getContentPane().setLayout(new java.awt.GridLayout(2, 2));
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            upPanel.setBorder(new javax.swing.border.TitledBorder("Up"));
            upPanel.setBackground(new java.awt.Color(255, 255, 255));
            getContentPane().add(upPanel);
            leftPanel.setBorder(new javax.swing.border.TitledBorder("Left"));
            leftPanel.setBackground(new java.awt.Color(255, 255, 255));
            getContentPane().add(leftPanel);
            downPanel.setBorder(new javax.swing.border.TitledBorder("Down"));
            downPanel.setBackground(new java.awt.Color(255, 255, 255));
            getContentPane().add(downPanel);
            rightPanel.setBorder(new javax.swing.border.TitledBorder("Right"));
            rightPanel.setToolTipText("null");
            rightPanel.setBackground(new java.awt.Color(255, 255, 255));
            getContentPane().add(rightPanel);
            pack();
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new KeyEvents().show();
        // Variables declaration - do not modify
        private javax.swing.JPanel upPanel;
        private javax.swing.JPanel leftPanel;
        private javax.swing.JPanel rightPanel;
        private javax.swing.JPanel downPanel;
        // End of variables declaration
    }

  • Combine multiple key figures in single key figure

    Hi,
    We have a requirement where we need to put multiple key figures into a single key figure
    For example source DSO is as follows (+ Unit object):
    Region    |   Date           |    Amount  |    Quantity
    Asia        |  01-01-2008  |    100        |    1000
    Eurpoe    |  02-02-2008  |     200       |     2000
    In Target DSO / Cube, the data must appear like this (no Unit Object)
    Region    |   Date            |  Type        |    Value
    Asia       |   01-01-2008   |   Amount   |    100
    Asia       |   01-01-2008   |   Quantity  |    1000
    Eurpoe   |   02-02-2008   |   Amount   |     200
    Eurpoe   |   02-02-2008   |   Quantity  |     2000
    How do we achieve this?
    Regards,
    Nikhil

    Hi
    Write a strart routine that maps Type ->Amount and Quantity,Value -> Kf of Amount or Quantity
    Put these chars into Key fields in target DSO = Region | Date | Type ,that will assure unique entries
    Bye

  • Model multiple key figures of BI cube to BPC

    Hi Experts,Probably a good way of having multiple Key figure values from BI to BPC is to convert it into a account based model (create a dimension and have the key figures as dimension members).I have this scenraio where we are using COPA (costing based) for BPC mgmt consol.This costing based COPA cube in BI has around 120 Key figures.Pls advice on the best way to medel this scnerio in BPC where i would probably need most of those Kf's.I am also looking at how i could reduce separate transformation files/mappings from BI to BPC also on the same..
    Many thanks
    savvvy

    Hi ,
    Thank you Pravin and Ajay for your valuable suggestions and time.what i would like to clarify is on the transformations.Let us say i have my BI cube as costing based itself and this i need to map to BPC dimension.
    BI structure- char1 ,char 2,char 3 ,KF1(value field 1),KF2(value field 2),KF3(valuefield3),KF4....
    In BPC ,lets say we have  a separate dimension (i guess this should be of account type or probably user defined one)  which would have dimension members as KF1,KF2,KF3,KF4....
    Now how would i do the mapping/transformations from BI to BPC? would i need to have 4different transformation files (assuming i have 4 KF's in my BI cube) for each KF & char combination and thus to load data also many times.
    How to achieve modelling side of this situation.any suggestions on this would be greatly appreciated.
    many thanks
    savvvy

  • EVDRE - Multiple Key Ranges - Formatting

    I am building a report that uses Multiple Key Ranges, both column and row, as shown below.
    ColKeyRange
    Sheet1!$N$101:$AA$104,Sheet1!$N$164:$AA$167,Sheet1!$N$213:$AA$216
    RowKeyRange
    Sheet1!$I$110:$I$160,Sheet1!$I$173:$I$209,Sheet1!$I$222:$I$261
    My formatting range has a line with HEADING="GREYBG" in the Criteria column.
    However, when I use keywords in my COL Heading area, only the column heading on the first key range is used.  For example, if I use a keyword GREYBG in cell N168, it wonu2019t apply to my second data range.  The second data range is formatted only from what is in the first column header.
    Is this the normal behavior?  Is there any way to make the second data range use the formatting from the second column header?

    Hi,
    Did you manage to find an answer to this?
    I have tried doing similar, with HEADING="B" and putting B in the column directly to the left of the key, yet it doesn't work on any of the data sets except the first

  • Associating multiple key fields.

    Is it common practice to associate multiple key fields with a dimension level or fact? For example, if ITEM dimension has two primary key fields (inventory_item_id, sr_instance_id) to identify one single item, PLAN fact table the same, I can't manually associate ITEM dimension or PLAN cube with their tables from Analytic Workspace Manager. But I can do this with OLAP Analytic Workspace Java API. Problem with Java approach is that my AW can't be viewed corrected in AWM.
    Is it "right way" to associate multiple key fields? Or should I avoid this (say concatinate keys into one item_key field)?

    Hi,
    Refer below code of FM 'F4IF_INT_TABLE_VALUE_REQUEST',it will useful to you.
    DATA: IL_RETURN   TYPE TABLE OF DDSHRETVAL,                              
          WAL_RETURN  TYPE DDSHRETVAL,
          IL_FIELDS   TYPE TABLE OF DFIES ,
          WAL_FIELDS  TYPE DFIES,
          VL_RETFIELD LIKE DFIES-FIELDNAME.
    CLEAR IL_FIELDS.
      REFRESH IL_FIELDS.     
      LOOP AT FIELDS.                    
          WAL_FIELDS-FIELDNAME = FIELDS-FIELDNAME .                    
          WAL_FIELDS-TABNAME   = FIELDS-TABNAME.
          WAL_FIELDS-KEYFLAG   = FIELDS-SELECTFLAG.
          APPEND WAL_FIELDS TO IL_FIELDS.
      ENDLOOP.
       VL_RETFIELD = 'TABNAME'.
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
        DDIC_STRUCTURE         = ''
          RETFIELD               = VL_RETFIELD
        VALUE_ORG              = ''
        TABLES
          VALUE_TAB              = VALUES
          FIELD_TAB              = IL_FIELDS
          RETURN_TAB             = IL_RETURN
        EXCEPTIONS
          PARAMETER_ERROR        = 1
          NO_VALUES_FOUND        = 2
          OTHERS                 = 3.
      READ TABLE IL_RETURN INTO WAL_RETURN WITH KEY FIELDNAME = VL_RETFIELD.
      IF SY-SUBRC EQ 0.
          VIEWNAME = WAL_RETURN-FIELDVAL.                    
      ENDIF.
    Best regards,
    Syf

  • Multiple Key Pressing

    When I hold Tab + w space doesn't work click (I have my controls set as this for a game).
    Is there anyway to make it so i can hold those two keys and have spacebar work?
    Im on a MacBook Pro Retina 13 inch with latest version of yosemite
    Thanks for the help

    Here is an example of both multiple key press and repeat delay ignore. It is a terrible example of animation. Do not us this animation loop in a game. It will flicker far too much.import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Test extends JFrame implements Runnable {
      boolean upPressed=false, downPressed=false, leftPressed=false, rightPressed=false;
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addKeyListener(new KeyAdapter() {
          public void keyPressed(KeyEvent ke) {
         switch (ke.getKeyCode()) {
           case KeyEvent.VK_UP: upPressed = true; break;
           case KeyEvent.VK_DOWN: downPressed = true; break;
           case KeyEvent.VK_LEFT: leftPressed = true; break;
           case KeyEvent.VK_RIGHT: rightPressed = true; break;
          public void keyReleased(KeyEvent ke) {
         switch (ke.getKeyCode()) {
           case KeyEvent.VK_UP: upPressed = false; break;
           case KeyEvent.VK_DOWN: downPressed = false; break;
           case KeyEvent.VK_LEFT: leftPressed = false; break;
           case KeyEvent.VK_RIGHT: rightPressed = false; break;
        setSize(250,250);
        setVisible(true);
        Thread timer = new Thread(this);
        timer.start();
      public static void main(String[] args) {
        new Test();
      public void run() {
        while (true) {
          repaint();
          try { Thread.sleep(30);} catch (Exception e) {}
      public void paint(Graphics g) {
        g.setColor(Color.white);
        g.fillRect(0,0,getWidth(), getHeight());
        g.setColor(Color.black);
        g.drawString("Up",40,40);
        if (upPressed) g.drawString("Pressed",100,40);
        g.drawString("Down",40,60);
        if (downPressed) g.drawString("Pressed",100,60);
        g.drawString("Left",40,80);
        if (leftPressed) g.drawString("Pressed",100,80);
        g.drawString("Right",40,100);
        if (rightPressed) g.drawString("Pressed",100,100);
    }

Maybe you are looking for

  • Which OAM setting for passing values in HTTP header to application

    Experts, what is the setting in OAM 11gR2 that is set to pass a userid pulled from a LDAP directory (which is already configured with OAM) as a HTTP Header to an application. This is typically in cases where OAM is protecting or providing to protecte

  • Unable to see images in iTunes Store

    Everything seems to be working fine except for the images. The only thing I see are grey boxes. I have no idea what caused this problem and I don't know how to fix it. Any ideas? SAMSUNG R540

  • Recording video on the Pre?

    Maybe I'm just missing something, but it appears that the Pre has no way to record video. Even my ancient Razr could do that, although not very well. If I am correct, and there is no ability to record, does anyone have any idea whether that feature m

  • CR2 (RAW) to JPEG Conversion

    Hello and thanks in advance. I'm new to using RAW images in iPhoto. I was given a folder of RAW (CR2) images, and I want to convert them to JPEG to conserve disk space. I have no need to GB's of images that are each 15mb in size. I've read that iPhot

  • Unexpected end of file, photoshop will no longer start up

    Hi, I have been using CS6 for several years now and all of a sudden I get this message when I try to open PS, so I do not even open a file, I just try to open PS: Followed by this: I have de- and reinstalled photoshop but I still get this message. Co