Re: How to make java dispatch mouse events to my component
From: Nomak (no.email_at_invalid.domain.fr)
Date: 10/29/04
- Next message: Andrew Thompson: "Re: How to make java dispatch mouse events to my component"
- Previous message: Steve W. Jackson: "Re: How to create a table in an RTF document"
- In reply to: Andrew Thompson: "Re: How to make java dispatch mouse events to my component"
- 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 21:36:19 +0200
Le 29/10/2004 à 18:17:43, Andrew Thompson <SeeMySites@www.invalid> a
écrit:
> Mixing light and heavywieght components can be problematic.
> Until you have a lot of experience with both and are familiar
> with why, you should avoid doing it.
> <http://www.physci.org/guifaq.jsp#5.1>
thx, i switch to JComponent.
> [...]
Sorry for not being precise.
1/ I don't know why it didn't work, but know it does:
// the HomePanel
public class HomePanel extends javax.swing.JPanel {
public HomePanel() {
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
HomePanel.this.mousePressed(evt);
}
});
}
private void mousePressed(MouseEvent evt) {
System.err.println("DEBUG: HomePanel.mousePressed");
add(New HomeComponent());
repaint();
}
}
// the HomeComponent
public class HomeComponent extends javax.swing.JComponent {
public HomeComponent() {
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
HomeComponent.this.mousePressed(evt);
}
});
}
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 by Netbeans code
getContentPane().add(homePanel);
...
}
Output:
DEBUG: MainFrame.main
DEBUG: HomePanel.mousePressed <= click on the panel
DEBUG: HomeComponent.paint
DEBUG: HomeComponent.mousePressed <= click on the component
the click on the component is not handled by the panel => success :D
2/ Adapter(s) avoid to define all the methods of Listener(s)
interface, and since Adapter are class and Java cannot multi-herit
everybody use inlive inner class definition of adapter.
Thank you and google ;)
-- Nomak
- Next message: Andrew Thompson: "Re: How to make java dispatch mouse events to my component"
- Previous message: Steve W. Jackson: "Re: How to create a table in an RTF document"
- In reply to: Andrew Thompson: "Re: How to make java dispatch mouse events to my component"
- 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
|