Results 1 to 5 of 5

Thread: How to use InputMap class?

  1. #1
    Join Date
    Dec 2009
    Posts
    67

    How to use InputMap class?

    Hi friends,

    I just started to learn advanced java programming. Some of the concept of advanced java programming are quit confusing for me. A 'InputMap class' is one these concept of java. I am not getting how to use this 'InputMap class' of java. Even I don't have any idea about it's methods also. Do you have knowledge about InputMap class of java? if yes then please let know that. Your help would be appreciated.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to use InputMap class?

    InputMap provides a binding between an input event (currently only KeyStrokes are used) and an Object. InputMaps are usually used with an ActionMap, to determine an Action to perform when a key is pressed. An InputMap can have a parent that is searched for bindings not defined in the InputMap. some of the methods of InputMap class cause a StackOverflowError to be thrown. This class implements 'Serializable' interface.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: How to use InputMap class?

    Hi,

    Following example will depict you how to use the InputMap class of java:
    Code:
    import javax.swing.InputMap;
    import javax.swing.KeyStroke;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    
    public class InputMapDM
     {
      public static void main(String[] arglv) throws Exception {
        InputMap inputMap1 = new InputMap();
    
        inputMap1.put(KeyStroke.getKeyStroke("F3"), "actionName");
    
        JButton component1 = new JButton("button");
        
    inputMap.setParent(component1.getInputMap(JComponent.WHEN_FOCUSED));
    
        component.setInputMap(JComponent.WHEN_FOCUSED, inputMap1);
    
      }
    }

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to use InputMap class?

    Hello friend,

    Please review following example which will help you to use properties of 'InputMap class':
    • setParent(InputMap map1)
    • remove(KeyStroke key1)
    • getParent()
    • put(KeyStroke keyStroke1, Object actionMapKey1)
    • get(KeyStroke keyStroke1)

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: How to use InputMap class?

    Example of InputMap class of java:
    Code:
    import javax.swing.InputMap;
    
    public class JMapMain {
      public static void main(String[] argbv) {
        InputMap im01 = new JTextArea().getInputMap(JComponent.WHEN_FOCUSED);
        im01.put(KeyStroke.getKeyStroke("F2"), "actionNam01e");
    
        ActionMap am01 = new JTextArea().getActionMap();
        am01.put("actionNam01e", new AbstractAction("actionNam01e") {
          public void actionPerformed(ActionEvent evt) {
            System.out.println((JTextComponent) evt.getSource());
          }    };
        im01.put(KeyStroke.getKeyStroke("F3"), "actionNam01e2");
        am01.put("actionNam01e2", new AbstractAction("actionNam01e2") {
          public void actionPerformed(ActionEvent evt) {
            System.out.println((JTextComponent) evt.getSource());
          }    };
        JButton component01 = new JButton("button 1");
        JButton component02 = new JButton("button 2");
    
        component01.setInputMap(JComponent.WHEN_FOCUSED, im01);
        component02.setInputMap(JComponent.WHEN_FOCUSED, im01);
    
        component01.setActionMap(am01);
        component02.setActionMap(am01);
      }
    }

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. What is the difference between Local class and global class in C++?
    By Dëfrim in forum Software Development
    Replies: 4
    Last Post: 03-01-2011, 10:44 PM
  3. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,132,915.62188 seconds with 16 queries