×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Check A Date Valid or not Object oriented Basic theory
Drawing Pad Using Applet - Java
2414    Arnab De    04/07/2018

Drawing Pad Using Applet

To create a drawing pad using applet we have to import java.awt.*; java.awt.event.*; java.applet.*; packages. Now implements MouseMotionListener, MouseListener interfaces and overrides the methods mouseMoved(), mouseDragged(), mouseClicked(), mousePressed(), mouseReleased(), mouseEntered(), mouseExited(). Now draw line from the old mouse position to current mouse position. this code written in mouseDragged() method.

softetechnologies
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class A extends Applet implements MouseMotionListener,MouseListener{
	float X,Y,X1,Y1;
	public void init(){
		addMouseListener(this);
		addMouseMotionListener(this);
	}
	public void mouseMoved(MouseEvent e){}
	public void mouseDragged(MouseEvent e){
		Graphics g=getGraphics();
		X1=e.getX();
		Y1=e.getY();
		g.setColor(Color.red);
		g.drawLine((int)X,(int)Y,(int)X1,(int)Y1);
		X=X1;
		Y=Y1;
	}
	public void mouseClicked(MouseEvent e){}
	public void mousePressed(MouseEvent e){
		X=e.getX();
		Y=e.getY();
	}
	public void mouseReleased(MouseEvent e){}
	public void mouseEntered(MouseEvent e){}
	public void mouseExited(MouseEvent e){}
}
Check A Date Valid or not Object oriented Basic theory
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Dalai Lama
When educating the minds of our youth, we must not forget to educate their hearts.
Dalai Lama
2773
38.7
Today So Far
Total View (Lakh)
softetechnologies
01/01/2018     34306
28/06/2017     30940
26/05/2018     30852
02/08/2017     28850
25/06/2018     26167
15/05/2017     24598
01/08/2017     23446
06/07/2017     23179
21/04/2018     19206
14/07/2017     18464
softetechnologies