Howdy.


import javax.swing.*;
import java.awt.*; 

public class Something extends JComponent {
  int count;
  public void paintComponent(Graphics g) {
    g.drawString("How are you " + count++, 200, 200);  
  }
  public static void main(String[] args) {
    JFrame a = new JFrame();
    a.add(new Something()); 
    a.setVisible(true); 
    a.setSize(500, 500); 
  }
}

--


import javax.swing.*;
import java.awt.*; 
import java.awt.event.*;

public class Something extends JComponent implements MouseMotionListener {
  ArrayList<Circle> drawing = new ArrayList<Circle>(); 
  public void mouseMoved(MouseEvent e) { }
  public void mouseDragged(MouseEvent e) { 
    int x = e.getX(), y = e.getY(); 
    
    Graphics g = this.getGraphics();
    g.drawOval(x, y, 20, 20); 
  }
  int count;
  public void paintComponent(Graphics g) {
    // g.drawString("How are you " + count++, 200, 200);  
    for (Circle c : this.drawing)
      c.draw(g);
  }
  public static void main(String[] args) {
    JFrame a = new JFrame();
    Something b = new Something(); 
    a.add(b); 
    a.setVisible(true); 
    a.setSize(500, 500); 
    a.addMouseMotionListener(b); 
  }
}

--

import javax.swing.*;
import java.awt.*; 
import java.awt.event.*;
import java.util.*; 

public class Something extends JComponent implements MouseMotionListener {
  ArrayList<Circle> drawing = new ArrayList<Circle>(); 
  public void mouseMoved(MouseEvent e) { }
  public void mouseDragged(MouseEvent e) { 
    System.out.println("Dragging... " + count++); 
    this.drawing.add( new Circle(e.getX(), e.getY(), 10) ); 
    this.repaint(); // what if I forget to put this here?    
  }
  int count;
  public void paintComponent(Graphics g) {
    // g.drawString("How are you " + count++, 200, 200);  
    for (Circle c : this.drawing)
      c.draw(g);
  }
  public static void main(String[] args) {
    JFrame a = new JFrame();
    Something b = new Something(); 
    a.add(b); 
    a.setVisible(true); 
    a.setSize(500, 500); 
    a.addMouseMotionListener(b); 
  }
}

--

import javax.swing.*;
import java.awt.*; 
import java.awt.event.*;
import java.util.*; 

public class Something extends JComponent implements MouseMotionListener {
  ArrayList<Circle> drawing = new ArrayList<Circle>(); 
  public void mouseMoved(MouseEvent e) { }
  public void mouseDragged(MouseEvent e) { 
    // System.out.println("Dragging... " + count++); 
    this.drawing.add( new Circle(e.getX(), e.getY(), 1) ); 
    this.repaint(); // what if I forget to put this here?    
  }
  int count;
  public void paintComponent(Graphics g) {
    g.drawString("How are you " + count++, 200, 200);  
    for (Circle c : this.drawing)
      c.draw(g);
  }
  public static void main(String[] args) {
    JFrame a = new JFrame();
    Something b = new Something(); 
    a.add(b); 
    a.setVisible(true); 
    a.setSize(500, 500); 
    b.addMouseMotionListener(b); 
  }
}

--

import java.awt.*; 

public class Circle {
  int x, y, R; // center coordinates 
  public Circle(int x, int y, int R) {
    this.x = x;
    this.y = y;
    this.R = R; 
  }
  public void draw(Graphics g) {
    g.drawOval(x - R, y - R, 2 * R, 2 * R); // center coordinates x and y
  }
}

--

import java.awt.*; 

public class Circle {
  int x, y, R; // center coordinates 
  public Circle(int x, int y, int R) {
    this.x = x;
    this.y = y;
    this.R = R; 
  }
  public void draw(Graphics g) {
    g.drawOval(x - R, y - R, 2 * R, 2 * R); // center coordinates x and y
    g.drawString("(" + x + ", " + y + ")", x, y);  
  }
}

--

import javax.swing.*;
import java.awt.*; 
import java.awt.event.*;
import java.util.*; 

public class Something extends JComponent implements MouseMotionListener {
  int R = 30;
  ArrayList<Circle> drawing = new ArrayList<Circle>(); 
  public void mouseMoved(MouseEvent e) { }
  public void mouseDragged(MouseEvent e) { 
    // System.out.println("Dragging... " + count++); 
    if (this.drawing.size() == 0) 
      this.drawing.add( new Circle(e.getX(), e.getY(), R) ); 
    else 
      this.drawing.set( 0, new Circle(e.getX(), e.getY(), R) ); 
    this.repaint(); // what if I forget to put this here?    
  }
  int count;
  public void paintComponent(Graphics g) {
    // g.drawString("How are you " + count++, 200, 200);  
    for (Circle c : this.drawing)
      c.draw(g);
  }
  public static void main(String[] args) {
    JFrame a = new JFrame();
    Something b = new Something(); 
    a.add(b); 
    a.setVisible(true); 
    a.setSize(500, 500); 
    b.addMouseMotionListener(b); 
  }
}

--

import java.awt.*; 

public class Circle {
  int x, y, R; // center coordinates 
  public Circle(int x, int y, int R) {
    this.x = x;
    this.y = y;
    this.R = R; 
  }
  public void draw(Graphics g) {
    g.fillOval(x - R, y - R, 2 * R, 2 * R); // center coordinates x and y
    // g.drawString("(" + x + ", " + y + ")", x, y);  
  }
}

--

import javax.swing.*;
import java.awt.*; 
import java.awt.event.*;
import java.util.*; 

public class Something extends JComponent implements MouseMotionListener {
  int R = 3;
  
  ArrayList<Circle> drawing = new ArrayList<Circle>(); 
  
  public void mouseMoved(MouseEvent e) { }
  public void mouseDragged(MouseEvent e) { 
    this.drawing.add( new Circle(e.getX(), e.getY(), R) ); 
    this.repaint();
  }
  int count;
  public void paintComponent(Graphics g) {
    g.setColor(Color.BLUE); 
    for (int i = 0; i < this.drawing.size()-1; i++) {
      g.drawLine( this.drawing.get(i).x   ,
                  this.drawing.get(i).y   , 
                  this.drawing.get(i+1).x , 
                  this.drawing.get(i+1).y );  
    }
    // g.setColor(Color.RED); 
    // for (Circle c : this.drawing)
    //   c.draw(g);

  }
  public static void main(String[] args) {
    JFrame a = new JFrame();
    Something b = new Something(); 
    a.add(b); 
    a.setVisible(true); 
    a.setSize(500, 500); 
    b.addMouseMotionListener(b); 
  }
}

--

import javax.swing.*;
import java.awt.*; 
import java.awt.event.*;
import java.util.*; 

public class Something extends JComponent implements MouseMotionListener {
  int R = 3;
  
  ArrayList<ArrayList<Circle>> drawing = new ArrayList<ArrayList<Circle>>(); 
  ArrayList<Circle> row = new ArrayList<Circle>(); 
  
  public void mouseMoved(MouseEvent e) { 
    // store the row and create a new one 
  }
  public void mouseDragged(MouseEvent e) { 
    this.row.add( new Circle(e.getX(), e.getY(), R) ); 
    this.repaint();
  }
  int count;
  public void paintComponent(Graphics g) {
    for (ArrayList<Circle> row : this.drawing) {
      for (int i = 0; i < this.drawing.size()-1; i++) {
        g.drawLine( this.drawing.get(i).x   ,
                    this.drawing.get(i).y   , 
                    this.drawing.get(i+1).x , 
                    this.drawing.get(i+1).y );  
      }
    }
  }
  public static void main(String[] args) {
    JFrame a = new JFrame();
    Something b = new Something(); 
    a.add(b); 
    a.setVisible(true); 
    a.setSize(500, 500); 
    b.addMouseMotionListener(b); 
  }
}

--

import javax.swing.*;
import java.awt.*; 
import java.awt.event.*;
import java.util.*; 

public class Something extends JComponent implements MouseMotionListener {
  int R = 3;
  
  ArrayList<ArrayList<Circle>> drawing = new ArrayList<ArrayList<Circle>>(); 
  ArrayList<Circle> row = new ArrayList<Circle>(); 
  
  public void mouseMoved(MouseEvent e) { 
    if (this.row.size() == 0) {
      
    } else {
      this.drawing.add(row); 
      this.row = new ArrayList<Circle>(); 
    }
  }
  public void mouseDragged(MouseEvent e) { 
    this.row.add( new Circle(e.getX(), e.getY(), R) ); 
    this.repaint();
  }
  int count;
  public void paintComponent(Graphics g) {
    for (ArrayList<Circle> row : this.drawing) {
      for (int i = 0; i < this.drawing.size()-1; i++) {
        g.drawLine( this.row.get(i).x   ,
                    this.row.get(i).y   , 
                    this.row.get(i+1).x , 
                    this.row.get(i+1).y );  
      }
    }
  }
  public static void main(String[] args) {
    JFrame a = new JFrame();
    Something b = new Something(); 
    a.add(b); 
    a.setVisible(true); 
    a.setSize(500, 500); 
    b.addMouseMotionListener(b); 
  }
}

--

import java.awt.*; 

public class Circle {
  int x, y, R; // center coordinates 
  public Circle(int x, int y, int R) {
    this.x = x;
    this.y = y;
    this.R = R; 
  }
  public void draw(Graphics g) {
    g.fillOval(x - R, y - R, 2 * R, 2 * R); // center coordinates x and y
    // g.drawString("(" + x + ", " + y + ")", x, y);  
  }
}