Q:

Java Applet - Display the Polygon when the user presses the Keyboard

0

This Program is used to Display the Polygon when the user presses the Keyboard.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.awt.*;

import java.awt.event.*;

import java.applet.*;



public class keytest extends Applet implements KeyListener

 {

  int xa[] = { 120, 125, 150, 150, 200, 200 };

  int ya[] = { 175, 100, 100, 175, 175, 200 };

  Graphics g;

  public void init()

   {

      g=getGraphics();

      addKeyListener(this);  

   }

  public void paint(Graphics g)

   {

       g.drawString("Enter any Character in the keyboard....",20,20);      

   }

  public void keyPressed(KeyEvent e)

   {

         g.drawPolygon(xa, ya, 6);

         showStatus("key pressed");  

   }

  public void keyReleased(KeyEvent e)

   {     showStatus("key released - You have Realsed the Key");   }

  public void keyTyped(KeyEvent e)

   {    showStatus("key typed : "+e.getKeyChar());    }

 }



/* <applet code ="keytest.class" width = 350 height =350>

   </applet> */

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now