Estou lendo dados do teclado e mostrando informacoes na tela conforme o que leio. Depois de cada msg enviada para a tela, gostaria de executar um “readkey” (alá Pascal) para esperar que o user pressione uma tecla para continuar a execução do programa.
Alguém sugere uma forma simples de implementar isso?
Ps: não pode ser usando wait, sleep e derivados (não sei se esse são os nomes corretos, mas entenderam né?)
Kra… vc n pd esquecer d importar o pacote java.io!
Este metodo q o irmao falo assima…
Le caracteres do teclado!!
Espero q temos ajudado!!!
:razz:
M
mdsPJ
Blz! Mas tem um jeito + facil de fazer isso ae?
[]'s
C
CassolatoPJ
Kra, c n for usando a classe BufferedReader acho q n tem n kra!! :razz:
E
ErkoPJ
eae mano blz??
cara vc tem o livro java como programar 4ed??
capa amarela lah tem um exemplo de como tratar de eventos do teclado
pag.: 640 capitulo: 12 - Componentes da GUI: parte 1
vai o codigo ai que estah no livro:
:arrow:
// Fig. 12.22: KeyDemo.java// Demonstrating keystroke events.// Java core packagesimportjava.awt.*;importjava.awt.event.*;// Java extension packagesimportjavax.swing.*;publicclassKeyDemoextendsJFrameimplementsKeyListener{privateStringline1="",line2="";privateStringline3="";privateJTextAreatextArea;// set up GUIpublicKeyDemo(){super("Demonstrating Keystroke Events");// set up JTextAreatextArea=newJTextArea(10,15);textArea.setText("Press any key on the keyboard...");textArea.setEnabled(false);getContentPane().add(textArea);// allow frame to process Key eventsaddKeyListener(this);setSize(350,100);setVisible(true);}// handle press of any keypublicvoidkeyPressed(KeyEventevent){line1="Key pressed: "+event.getKeyText(event.getKeyCode());setLines2and3(event);}// handle release of any keypublicvoidkeyReleased(KeyEventevent){line1="Key released: "+event.getKeyText(event.getKeyCode());setLines2and3(event);}// handle press of an action keypublicvoidkeyTyped(KeyEventevent){line1="Key typed: "+event.getKeyChar();setLines2and3(event);}// set second and third lines of outputprivatevoidsetLines2and3(KeyEventevent){line2="This key is "+(event.isActionKey()?"":"not ")+"an action key";Stringtemp=event.getKeyModifiersText(event.getModifiers());line3="Modifier keys pressed: "+(temp.equals("")?"none":temp);textArea.setText(line1+"\n"+line2+"\n"+line3+"\n");}// execute applicationpublicstaticvoidmain(Stringargs[]){KeyDemoapplication=newKeyDemo();application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}// end class KeyDemo/************************************************************************** * (C) Copyright 2002 by Deitel & Associates, Inc. and Prentice Hall. * * All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * *************************************************************************/
dai soh vc modelar pra verificar a tecla que vc quizer
e tratar da ordem de execução atraves de métodos
[]'s
Erko Bridee
C
CassolatoPJ
Tinha esquecido do pacote java.awt.event!! :oops: :oops: