source code name: KeyDemo4.java

    import java.awt.*;
     import java.awt.event.*;
 class KeyDemo4 extends Frame implements KeyListener
{

 public KeyDemo4()


addKeyListener(this);
}
 
public void keyPressed(KeyEvent ke)
{
System.out.println("key is Pressed");
char ch=ke.getKeyChar();
Graphics g=getGraphics();
if(ch=='M' || ch=='m')
g.drawString("Good Morning" ,100,100);

if(ch=='E' || ch=='e')
g.drawString("Good Evening" ,100,200);

if(ch=='A' || ch=='a')
g.drawString("Good Afternoon" ,100,150);


}
public void keyReleased(KeyEvent me){}
public void keyTyped(KeyEvent me){}

 public static void main(String[] args)

KeyDemo4 f=new KeyDemo4();
f.setTitle("Key Event program");
f.setSize(400,500); 
 f.setVisible(true); 
    }
}  

output: