Practical 10 java

 avatar
Rohit143
java
2 years ago
970 B
3
Indexable
Never
import javax.swing.*;

import java.awt.BorderLayout;
import java.awt.event.*;

class MyFrame extends JFrame implements KeyListener {
    String str;
    JLabel label;

    MyFrame(){

        setVisible(true);
        setSize(400,500);
        setDefaultCloseOperation(3);


        add(new JLabel("Rohit Nandagawali"),BorderLayout.NORTH);

        label =new JLabel("No key is pressed");
        add(label,BorderLayout.CENTER);


        addKeyListener(this);
        
        
    }

    public void keyTyped(KeyEvent e){
        validate();
        label.setText("keyTyped -> "+e.getKeyChar());
    }
    public void keyPressed(KeyEvent e){
        validate();
        label.setText("keyPressed ->"+e.getKeyCode());

    }
    public void keyReleased(KeyEvent e){
        label.setText("keyRealeased");

    }
}
public class practical10 {
    public static void main(String[] args) {
        new MyFrame();
    }
    
}