Also while writing the code of the Glass Pane you would have to provide our own glass pane so that it can paint. I have given you sample of code that explains how to provide our own glass pane :
Code:
class MyGlassPane extends JComponent
implements ItemListener {
Point point;
public void itemStateChanged(ItemEvent ie) {
setVisible(ie.getStateChange() == ItemEvent.SELECTED);
}
protected void paintComponent(Graphics g) {
if (point != null) {
g.setColor(Color.blue);
g.fillOval(point.x - 20, point.y - 20, 30, 30);
}
}
public void setPoint(Point p) {
point = p;
}
public MyGlassPane(AbstractButton aButton,
JMenuBar menuBar,
Container contentPane) {
CBListener listener = new CBListener(aButton, menuBar,
this, contentPane);
addMouseListener(listener);
addMouseMotionListener(listener);
}
}
Bookmarks