/* B6. NEP Java Program to create a window when we press M or m the window displays Good Morning, A or a the window displays Good After Noon E or e the window displays Good Evening, N or n the window displays Good Night */
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="ProgB6" width=500 height=500> </applet>*/
public class ProgB6 extends Applet implements KeyListener
{
String msg="Press M or A or E or N";
int X=10,Y=20;
Font f1;
public void init()
{
f1= new Font("Georgia",Font.BOLD, 22);
addKeyListener(this);
}
public void keyPressed(KeyEvent ke)
{
int key=ke.getKeyCode();
switch(key)
{
case KeyEvent.VK_M: msg="Good Morning!";
break;
case KeyEvent.VK_A: msg="Good Afternoon!";
break;
case KeyEvent.VK_E: msg="Good Evening!";
break;
case KeyEvent.VK_N: msg="Good Night!";
break;
}
repaint();
}
public void keyReleased(KeyEvent ke)
{
//showStatus("Key UP");
}
public void keyTyped(KeyEvent ke)
{
repaint();
}
public void paint(Graphics g)
{
g.setFont(f1);
g.setColor(Color.blue);
g.drawString(msg,X,Y);
}
}
I have been looking around for this kind of information. Will you post some more in future? I’ll be grateful if you will.
ReplyDeleteStudent Flat in New york