You are on page 1of 2

New: JAXB | Junit

Javatpoint
Home Core Java Servlet

Development | Training | SEO Promotion | Consultancy


SSS IT (Powered by Javatpoint). Visit www.sssit.org for more details.
JSP Struts2 Mail API Hibernate Spring Android Quiz Projects Interview Q

Advertise Us | Ask Question | forum | login| 0120-4256464, +91-9990449

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.

Example of Painting in Applet:

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

<html> <body> <applet code="MouseDrag.class" width="300" height="300"> </applet> </body> </html>

download this example.

<<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.

You might also like