This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "event model for Rectangle2D object" Watch "event model for Rectangle2D object" New topic
Author

event model for Rectangle2D object

murugesan subramani
Greenhorn

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() {
addActionListener(this);
}
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.setColor(Color.red);
g2.setStroke(s1); // Tell the graphics context about it
for(int j=0;j<10;j++){
g2.draw(Device[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){
super(a,b,c,d);
g.drawString("D"+dno,a,b);
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");
deviceMenu.add(page);
}
}


Muru
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: event model for Rectangle2D object
 
Similar Threads
inconvertible type error
Popup menu not responding with mouse event
Drop Down Menu Buttons
Add image to JPanel
[newbie] The type MouseComponent must implement the inherited abstract method MouseMotionListener...