samedi 1 juillet 2017

JAVA Read Simple Key Press?

I want to read a simple a key - how can I add this? Please can anyone help?

public class Test {

public static void main(String[] args) throws IOException{


    SetUp_JFrame SetUp_JFrame =new SetUp_JFrame();
    SetUp_JFrame.PART1(); 

    READ_KEY READ_KEY =new READ_KEY();
    for(;;) { 
       READ_KEY.PART2();  
            }


}}
class SetUp_JFrame {

public JFrame f; // `f` is now an instance field of the SetUp class

void PART1()throws IOException {

    f = new JFrame();

    f.setTitle("Test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //    System.out.println(f);

    // SetUp g =new SetUp();
    // You don't need to create a new SetUp object, you can directly access 'f' here.
    f.setSize(128,128);
    f.setLocation(10,10);
    f.setVisible(true);

   //  System.out.println(f);
}
}

class READ_KEY {
  void PART2() {

    A = KeyPress
       System.out.println("You Pressed Key "+A);
    }
    }

stackoverflow asking for more detail not sure what more I can say? in Basic you would use something like
DO
A=Inkey$
Print A
Loop

Aucun commentaire:

Enregistrer un commentaire