Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

event model for Rectangle2D object

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}
 
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic