Advertisements
Home > Java > Java Program to write an applet with Mouse Event Handling – Q50

Java Program to write an applet with Mouse Event Handling – Q50


Q50: Java Program to write an applet which does mouse event handling by extending MouseAdapter class.

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Ap_AdapterDemo extends Applet{
	public void init(){
		addMouseListener(new MyMouseAdapter(this));
		addMouseMotionListener(new MyMouseMotionAdapter(this));
	}
}

class MyMouseAdapter extends MouseAdapter{
	Ap_AdapterDemo adapterDemo;
	public MyMouseAdapter(Ap_AdapterDemo adapterDemo){
		this.adapterDemo = adapterDemo;
	}
	public void mouseClicked(MouseEvent me){
		adapterDemo.showStatus("Mouse clicked");
	}
}

class MyMouseMotionAdapter extends MouseMotionAdapter{
	Ap_AdapterDemo adapterDemo;
	public MyMouseMotionAdapter(Ap_AdapterDemo adapterDemo){
		this.adapterDemo = adapterDemo;
	}
	public void mouseDragged(MouseEvent me){
		adapterDemo.showStatus("Mouse Draged");
	}
}

… from College notes (BCA/MCA assignments):


Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: