Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help On BlueJ: Inputting Keys

ZeromatterZeromatter Member Posts: 3
I'm sorry for posting a topic that may have already been posted, but I REALLY need help!

how do you get it so that if a user presses a key, such as 's', a message is displayed via terminal that says something like, "you pressed s!!!"???

Any help would be GREATLY appreciated,

Comments

  • zibadianzibadian Member Posts: 6,349
    : I'm sorry for posting a topic that may have already been posted, but I REALLY need help!
    :
    : how do you get it so that if a user presses a key, such as 's', a message is displayed via terminal that says something like, "you pressed s!!!"???
    :
    : Any help would be GREATLY appreciated,
    :
    Implement the KeyListener interface. That interface defines a keyPressed() method, which is fired if the user presses a key.
  • ZeromatterZeromatter Member Posts: 3
    : Implement the KeyListener interface. That interface defines a keyPressed() method, which is fired if the user presses a key.
    :

    I'm sorry, but I am not too adept at programming in Java. Frankly, all I know is a semester course. If you would be so kind to give a code example, I would be extremely thankful.
  • zibadianzibadian Member Posts: 6,349
    : : Implement the KeyListener interface. That interface defines a keyPressed() method, which is fired if the user presses a key.
    : :
    :
    : I'm sorry, but I am not too adept at programming in Java. Frankly, all I know is a semester course. If you would be so kind to give a code example, I would be extremely thankful.
    :
    I myself also just took an introduction course in Java programming, but EventListeners were among the first things we learned. Here is the basic code, the you should look in the javadoc for the rest:
    [code]
    public class MyApplet extends Applet implements KeyListener
    {
    public void init()
    {
    thiss.addKeyListener(this);
    }

    public void keyPressed(KeyEvent event)
    {
    }
    }
    [/code]
  • ZeromatterZeromatter Member Posts: 3
    Thanks a great deal. This will be extremely useful.
Sign In or Register to comment.