How to make java dispatch mouse events to my component
From: Nomak (no.email_at_invalid.domain.fr)
Date: 10/29/04
- Next message: kd dolezal/rob nishida: "text box orientation right to left"
- Previous message: Thomas Fritsch: "Re: JMenuItem with checkbox - on mac"
- Next in thread: Andrew Thompson: "Re: How to make java dispatch mouse events to my component"
- Reply: Andrew Thompson: "Re: How to make java dispatch mouse events to my component"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 29 Oct 2004 17:02:20 +0200
Hello,
I have a home made panel (which extend JPanel), and a home made
graphical component (which extend java.awt.Component).
What i want to do is:
- when i click on the HomePanel, it's add a HomeComponent to it.
- when i click on a HomeComponent in the HomePanel, it change it's
color.
Right now, my code is:
// the HomePanel
public class HomePanel extends JPanel {
}
// the HomeComponent
public class HomeComponent extends Component
implements MouseListener {
public void paint(Graphics g) {
...
}
public void mousePressed(MouseEvent e) {
System.err.println("DEBUG: HomeComponent.mousePressed");
}
...
}
// and the MainFrame:
public class MainFrame extends javax.swing.JFrame {
...
// generated code
homePanel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
homePanelMousePressed(evt);
}
});
getContentPane().add(homePanel);
...
private void homePanelMousePressed(java.awt.event.MouseEvent evt){
System.err.println("DEBUG: MainFrame.homePanelMousePressed");
homePanel.add(new HomeComponent());
homePanel.repaint();
}
}
1/ Why does it don't work?
2/ What is the interest of MouseAdaptater(s) over MouseListener(s)?
Thanks for your help.
-- Nomak
- Next message: kd dolezal/rob nishida: "text box orientation right to left"
- Previous message: Thomas Fritsch: "Re: JMenuItem with checkbox - on mac"
- Next in thread: Andrew Thompson: "Re: How to make java dispatch mouse events to my component"
- Reply: Andrew Thompson: "Re: How to make java dispatch mouse events to my component"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|