Results 1 to 11 of 11

Thread: keyboard input?[Resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103

    keyboard input?[Resolved]

    i've always used the non-standard Keyboard class. what is the standard way to get input from the keyboard? and how do you get its "type"? (like readInt, readString from the Keyboard class)
    Last edited by Dilenger4; Jun 27th, 2003 at 09:45 PM.

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Code:
    class X{
    
     JTextField() Jtf = new JTextField(); 
     jtf.addKeyListener(new Keyboard()); 
    
    }
    Code:
    class B extends KeyAdapter{
         
          public void keyPressed(KeyEvent ke){
           
           if(Character.isDigit(ke.getKeyChar())){
              int type = Character.getType(ke.getKeyChar()); 
               // ........
            }else if(Character.isLetter(ke.getKeyChar())) {
               // .............
            }
          }
       }

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103
    what about for normal, non-user interface (command line) input?

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    The arguments must be passed in when the program i run. ie
    C:\ java -classpath C:\Java; X arg1 arg2...........
    Code:
    class X{
     public static void main(String[] args){
      for(int i = 0; i < args.length; ++i){
      System.out.println(args[i]);
      }
     }
    }

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103
    what?!

  6. #6
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Or if you want.
    Code:
      import java.io.*; 
    
      public class Q{
       public static void main(String[] args){
    
      BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
      try{
    
       String s = buff.readLine();
       System.out.println(s);
    
      }catch(IOException e){;}
      }
    }

  7. #7

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103
    is

    BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
    the easiest way to achieve this? man, no wonder some guy wrote that Keyboard class...

    Is this correct:

    System.out.println("Please enter name: ");
    System.in;

  9. #9

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103
    okay got that, thanks
    could you possibly help me out in my windows thread?

  11. #11
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    I took a quick look at it but ill have to tacke that tommorow afternoon. I have an economics exam at 9am tommorow. Still gota study.
    Maybe someone else will get to it before me. Perhaps CornedBee or crptcblade.

Posting Permissions

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



Click Here to Expand Forum to Full Width