Professional Documents
Culture Documents
Painting in Applet
Painting in Applet
Javatpoint
Home Core Java Servlet
Comment
Forum
Basics of Java OOPs Concepts String Handling Exception Handling Nested Classes Multithreading Synchronization I/O Serialization Networking AWT Event Handling Swing LayoutManager Applet Applet Basics Graphics in Applet Displaying image in Applet Animation in Applet EventHandling in Applet JApplet class Painting in Applet Digital Clock in Applet Analog Clock in Applet Parameter in Applet Applet Communication Reflection API Collection JDBC Java New Features RMI Internationalization
<<prev
next>>
Painting in Applet
We can perform painting operation in applet by the mouseDragged() method of MouseMotionListener.
import java.awt.*; import java.awt.event.*; import java.applet.*; public class MouseDrag extends Applet implements MouseMotionListener{ public void init(){ addMouseMotionListener(this); setBackground(Color.red); } public void mouseDragged(MouseEvent me){ Graphics g=getGraphics(); g.setColor(Color.white); g.fillOval(me.getX(),me.getY(),5,5); } public void mouseMoved(MouseEvent me){} }
In the above example, getX() and getY() method of MouseEvent is used to get the current x-axis and yaxis. The getGraphics() method of Component class returns the object of Graphics.
myapplet.html
<<prev
next>>
Tweet
Like
16k
Like the www.javatpoint.com on facebook / google+ / twitter / subscribe to get latest updates
Sitemap
Core Java
Servlet
JSP
Struts2
Hibernate
Spring
Android
Interview Questions
javatpoint.com is developed to provide easy and point to point learning and training in detail. Examples might be simplified to improve reading and basic und
Tutorials and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. If there is any mistake, please mail sonoojaiswal1987@gmail.com or sonoojaiswal@javatpoint.com. We provide assurance of 90% interview questions. While using this site, you agree to hav accepted our terms of use and privacy policy. 2011-2013 Javatpoint. All Rights Reserved.