In this video, we will continue AWT Drawing to draw line with mouse press and release. Here, you will learn the role of AWT paint method and how we use Graphics object to draw a line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public void mousePressed(MouseEvent e) { //Sample 05: Set First Point FirstPoint.setLocation(0, 0); SecondPoint.setLocation(0, 0); FirstPoint.setLocation(e.getX(), e.getY()); } @Override public void mouseReleased(MouseEvent e) { //Sample 06: Set Second Point SecondPoint.setLocation(e.getX(), e.getY()); repaint(); } //Sample 07: Register with Mouse Listener addMouseListener(this); |
- AWT Drawing – Part 1 – Prepare Frame Window #23
- AWT Drawing – Part 3 – Perform Rectangle Drawing with Mouse #25
Categories: AWT-Tube