201-33P - Programming Lab Java-Algorithm - Drawing Shapes with Mouse clicks
201-33P - Programming Lab Java-Algorithm - Drawing Shapes with Mouse clicks
Write a Java Program to draw circle, square, ellipse and rectangle at the mouse click
positions.
Algorithm:
Aim: Drawing the Shapes Circle, Square, Ellipse and Rectangle at the mouse click positions
Step No. Instructions
1 Start
2 Create an Applet called “list11” by
a) Inheriting the Applet class
b) Implementing the Interfaces namely, KeyListener and MouseListener
3 Use addKeyListener( ) and addMouseListener( ) functions in init( ) method
4 Catch the Key Events using keyTyped( ), keyReleased( ) and keyEntered( )
5 Catch the Mouse Event for the Mouse using mouseClicked( ), mouseReleased( ),
mouseEntered( ), mouseDragged( ), mouseMoved( ), mouseExited( ) and
mousePressed( ) functions
6 Draw the shapes associated with mouse in the paint( ) method using the functions
namely, drawOval( ), drawLine( ) anddrawRect( )
7 Save the Applet code in the name of list11.java
8 Compile the Applet code using javac
9 Create a HTML code with <APPLET> tag with its CODE attribute as list11.class
10 Save the HTML code as list11.html
11 Run the HTML code using appletviewer
12 Stop