Search Your Topic

config
Thursday, 25 May 2017 06:22

Painting in Applet

Written by
Rate this item
(0 votes)
We can perform painting operation in applet by the mouseDragged() method of MouseMotionListener.

Example of Painting in Applet:

 
  1. import java.awt.*;  
  2. import java.awt.event.*;  
  3. import java.applet.*;  
  4. public class MouseDrag extends Applet implements MouseMotionListener{  
  5.   
  6. public void init(){  
  7. addMouseMotionListener(this);  
  8. setBackground(Color.red);  
  9. }  
  10.   
  11. public void mouseDragged(MouseEvent me){  
  12. Graphics g=getGraphics();  
  13. g.setColor(Color.white);  
  14. g.fillOval(me.getX(),me.getY(),5,5);  
  15. }  
  16. public void mouseMoved(MouseEvent me){}  
  17.   
  18. }  
In the above example, getX() and getY() method of MouseEvent is used to get the current x-axis and y-axis. The getGraphics() method of Component class returns the object of Graphics.

myapplet.html

 

 
  1. <html>  
  2. <body>  
  3. <applet code="MouseDrag.class" width="300" height="300">  
  4. </applet>  
  5. </body>  
  6. </html>  
Read 355 times
Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

toshiyas.in

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

Java Training

Facebook