Slide 1
Slide 2
Slide 3

Key Event in java programming (V70)

No Comments

KeyEvent
KeyEvent is an event that represents key actions on the keyboard, such as when a key is pressed, released, or typed.
 
Example:
Source Code:
Copied!
    private void txtcolorKeyPressed(java.awt.event.KeyEvent evt) {                                    
        char c = evt.getKeyChar();

    if (Character.isLetter(c)) {
        txtcolor.setBackground(new java.awt.Color(144, 238, 144)); // Light Green
    } else if (Character.isDigit(c)) {
        txtcolor.setBackground(new java.awt.Color(173, 216, 230)); // Light Blue
    } else {
        txtcolor.setBackground(new java.awt.Color(255, 182, 193)); // Light Pink
    }
    }                                                  

Result:


Watch the video:


Ebook: https://softkhpc.blogspot.com/2025/05/java-programming-ebooks.html

back to top