我正在创建线条和其他组件,并希望它们像Swing按钮事件一样响应,因为线条可以点击:
class CustomLine extends JComponent {
private int destx = 100;
private int desty = 100;
private int startx = 0;
private int starty = 0;
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(startx, starty, destx, desty);
}
}
这是如何运作的?