File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes event model for Rectangle2D object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "event model for Rectangle2D object" Watch "event model for Rectangle2D object" New topic

event model for Rectangle2D object

murugesan subramani

Joined: Jul 02, 2001
Posts: 10
I have my own class which creates a Rectangle derived from Rectangle2D. How do add an action listener for this object?
I have also coded the MouseAdapter class but dont know where to add.
See the code
thanks in advance.
import java.awt.*;
import java.applet.*;
import java.awt.geom.*;
import java.awt.event.*;
public class BT2 extends Applet implements ActionListener {
Graphics2D g2; // Reference to Graphics2D context
public BTDevice [] Device =new BTDevice[10];
private int x,y;
public BT2() {} // Construct the applet
public void init() {
public void paint(Graphics g){
g2 =(Graphics2D) g;
for(int i=0;i<10;i++){
x = (int)(Math.random()*getSize().height+10);
y = (int)(Math.random()*getSize().width+10);
Device[i] = new BTDevice(x+5,y+10,25,25,i,g2);
BasicStroke s1 = new BasicStroke(2);
g2.setStroke(s1); // Tell the graphics context about it
for(int j=0;j<10;j++){
public void actionPerformed(ActionEvent e){
class BTDevice extends Rectangle2D.Double implements ActionListener{
private int widht;
private int height;
private int px;
private int py;
private byte[] BD_ADDR;
public BTDevice(){
public BTDevice(int a,int b,int c,int d,int dno,Graphics2D g){
BD_ADDR = new byte[8];

class DeviceListener extends MouseAdapter {
private final int radius = 25;
public PopupMenu deviceMenu;
public void mousePressed(MouseEvent event) {
deviceMenu = new PopupMenu();
MenuItem page = new MenuItem("Page");

I agree. Here's the link:
subject: event model for Rectangle2D object
It's not a secret anymore!