Advertisement
Dido09

Painter

Apr 3rd, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. package Paint;
  2.  
  3. import javax.swing.*;
  4.  
  5. import java.awt.*;
  6. import java.awt.event.MouseMotionListener;
  7. import java.awt.event.MouseEvent;
  8.  
  9. public class DrawArea extends JFrame implements MouseMotionListener {
  10.  
  11. private int x = -10, y = -10;
  12.  
  13. public DrawArea() {
  14. setTitle("Painter");
  15. setSize(800, 600);
  16. setDefaultCloseOperation(EXIT_ON_CLOSE);
  17. //layout
  18. JLabel instructions = new JLabel("Drag the mouse to draw", JLabel.RIGHT);
  19. Container c = this.getContentPane();
  20. c.setLayout(new BorderLayout());
  21. c.add(instructions, BorderLayout.SOUTH);
  22. //mouse configuration
  23. c.addMouseMotionListener(this);
  24.  
  25. setVisible(true);
  26. }
  27.  
  28. public void mouseMoved(MouseEvent e) {
  29.  
  30. }
  31.  
  32. public void mouseDragged(MouseEvent e) {
  33.  
  34. x = e.getX();
  35. y = e.getY();
  36. repaint();
  37. }
  38.  
  39. public void paint(Graphics g)
  40. {
  41. g.fillOval(x, y, 4, 4);
  42. }
  43. public static void main (String args[])
  44. {
  45. Painter p = new Painter() {
  46. @Override
  47. public void paint(Graphics2D graphics2D, Object o, int i, int i1) {
  48.  
  49. }
  50. };
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement