Java Programming : Event Handle by Using Keyboard

What Will I Learn?

  • We will learn the concept of Event Handle in Java programming

Requirements

-Java Development Kit (JDK) must be installed.

-Also the computer system must have Java IDE installed. Probably Netbeans.

Difficulty

  • Intermediate

Tutorial Contents

we are going to learn the events handling in Java programming. Sometime, the users prefer clicking by using the keyboard than using the mouse. The sum operation can be done by entering keyboard below. The code is added is

if(e.getKeyCode()==e.VK_ENTER)

the full code below

private void resultKeyPressed(java.awt.event.KeyEvent evt) {                                  
        // TODO add your handling code here:
        if(e.getKeyCode()==e.VK_ENTER)
{
int x=Integer.parseInt(data1.getText());

int y=Integer.parseInt(data2.getText());
String z=String.valueOf(x+y);
result.setText(z);
}

    }                    

The result is displayed in picture below
jv.jpg

my project is in github

Curriculum

This is my first tutorial about Java programming



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center