Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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);
}
}
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic