Results 1 to 5 of 5

Thread: Keyboard

  1. #1
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Keyboard

    Hello ,
    I am in a problem to use keyboard in my java code.


    Java Code:
    class getkeyboard{
    
    JTextField a=new JTextfield();
    JTextField b=new JTextfield();
    JFrame frm;
    
      InputMap map,map1;
       KeyStroke key,key1;
    
    public getkeyboard(){
    
    
    frm=new JFrame("Keyboard");
        frm.setSize(300,300);
        cnt=frm.getContentPane();
        frm.setLayout(null);
    
    
    
    a.setBounds(20,20,100,30);
    a.setBounds(20,70,100,30);
    
       key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Event.CTRL_MASK);
       map.put(key, DefaultEditorKit.insertTabAction);
    }
    
    public static void main(String ayu[]){
    
    getkeyboard a=new getkeyboard();
    
     }
    }


    By this when I press ctrl+enter then cursor remains in same textfield with tab.

    My problem is when I will press just Enter key then the cursor will go to the next textfield.

    How to do that??
    Thanks in advance.

    Ujjal
    Dhaka-Bangladesh

  2. #2
    baloda is offline Member
    Join Date
    Nov 2010
    Location
    New Delhi
    Posts
    50
    Rep Power
    0

    Default

    Dear Ujjal ur code is not complete can u put ur complete code to check out what is the problem.

  3. #3
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    Well,please run this code.You will see two textfield on a JFrame.

    I just need that if I press ENTER ,cursor must go to the next TextField.

    What I have done in this code is that,if I press ctrl+enter ,there occures a TAB pressing in the same textfield.


    Java Code:
    ////////NewClass.java///////
    
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.JScrollPane;
    import javax.swing.JOptionPane;
    import java.sql.*;
    import java.util.*;
    import javax.swing.text.*;
    import java.awt.event.*;
    import java.util.Calendar;
    
    
    
    class getkeyboard{
    
    JTextField a,b;
    JFrame frm;
    Container cnt;
      InputMap map,map1;
       KeyStroke key,key1;
    
    public getkeyboard(){
    
    
        frm=new JFrame("Keyboard");
    
      
        cnt=frm.getContentPane();
    
        frm.setLayout(null);
    
    
        a=new JTextField();
        b=new JTextField();
    
    
        frm.add(a);
        frm.add(b);
    
    a.setBounds(20,20,100,30);
    b.setBounds(20,70,100,30);
    
    
       map = a.getInputMap();
       key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Event.CTRL_MASK);
       map.put(key, DefaultEditorKit.insertTabAction);
    
    
       frm.setVisible(true);
     frm.setSize(300,300);
    }
    }
    
    
    
    public class NewClass{
    public static void main(String ayu[]){
    try{
    getkeyboard adfdf=new getkeyboard();
    }catch(Exception e){}
     }
    }
    If I am not clear to you,then please let me know.
    Last edited by UJJAL DHAR; 01-29-2011 at 01:24 PM.

  4. #4
    baloda is offline Member
    Join Date
    Nov 2010
    Location
    New Delhi
    Posts
    50
    Rep Power
    0

  5. #5
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    Yaa thanks for the link .I have learned somethimg from here a little. I can control keyboard a little.My problem is just that one.


    to do this what must be changed?
    Java Code:
    key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Event.CTRL_MASK);
    map.put(key, DefaultEditorKit.insertTabAction);

Similar Threads

  1. Keyboard not working
    By Robotuner in forum New To Java
    Replies: 0
    Last Post: 10-27-2009, 08:51 PM
  2. [Virtual KeyBoard] - Anybody know ?
    By Matheus Leandro Ferreira in forum Advanced Java
    Replies: 1
    Last Post: 09-30-2009, 09:22 PM
  3. KeyBoard Problem
    By arimakidd in forum Java Applets
    Replies: 3
    Last Post: 09-19-2008, 05:05 PM
  4. Reading Keyboard
    By ushigley in forum New To Java
    Replies: 4
    Last Post: 08-20-2008, 02:50 PM
  5. Help with keyboard events?
    By Bibendum in forum New To Java
    Replies: 2
    Last Post: 11-02-2007, 03:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •