Archive

Posts Tagged ‘Java Mouse Handling’

Java Program to write an applet with Mouse Event Handling using inner class which extends MouseAdapter – Q51

January 26, 2009 Leave a comment

Q51: Java Program to write an applet which does mouse event handling using concept of inner class which extends MouseAdapter.

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

public class Ap_MousePressedDemo extends Applet{
	public void init(){
		addMouseListener(new MyMouseAdapter(this));
	}
}

class MyMouseAdapter extends MouseAdapter{
	Ap_MousePressedDemo mousePressedDemo;
	public MyMouseAdapter(Ap_MousePressedDemo mousePressedDemo){
		this.mousePressedDemo = mousePressedDemo;
	}
	public void mousePressed(MouseEvent me){
		mousePressedDemo.showStatus("Mouse Pressed.");
	}
} 

… from College notes (BCA/MCA assignments):


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

January 25, 2009 Leave a comment

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):