Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Paint;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.MouseMotionListener;
- import java.awt.event.MouseEvent;
- public class DrawArea extends JFrame implements MouseMotionListener {
- private int x = -10, y = -10;
- public DrawArea() {
- setTitle("Painter");
- setSize(800, 600);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- //layout
- JLabel instructions = new JLabel("Drag the mouse to draw", JLabel.RIGHT);
- Container c = this.getContentPane();
- c.setLayout(new BorderLayout());
- c.add(instructions, BorderLayout.SOUTH);
- //mouse configuration
- c.addMouseMotionListener(this);
- setVisible(true);
- }
- public void mouseMoved(MouseEvent e) {
- }
- public void mouseDragged(MouseEvent e) {
- x = e.getX();
- y = e.getY();
- repaint();
- }
- public void paint(Graphics g)
- {
- g.fillOval(x, y, 4, 4);
- }
- public static void main (String args[])
- {
- Painter p = new Painter() {
- @Override
- public void paint(Graphics2D graphics2D, Object o, int i, int i1) {
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement