class test {
public static void main(String[] args) {
Frame x = new Frame();
x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
x.setVisible(true);
}
}
class Frame extends JFrame {
public Frame() {
setSize(500,500);
addMouseListener(new Mouse());
}
class Mouse extends MouseAdapter {
public void mouseClicked(MouseEvent event) {
JLabel label = new JLabel("ss");
add(label);
Paint x = new Paint();
add(x);
}
}
class Paint extends JComponent {
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
Rectangle2D x = new Rectangle(20, 50, 100, 50);
g2.draw(x);
}
}
}
Dlaczego nie reaguje na zdarzenie klikniecia ? Chce aby po kliknieciu wyswietlil sie prostokat.