Results 1 to 2 of 2
  1. #1
    michcan is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default Help with paint program

    I have a problem with my code... if i move the mouse quickly when drawing it just paint a lot of dots insted of painting like the brush in ms paint program..

    Help please!!! (sorry about my english)

    here is my code:

    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
    import javax.swing.JPanel;

    public class Dibujo extends JPanel
    private int cuentapuntos = 0;

    private Point puntos[]= new Point[10000];

    public Dibujo()

    addMouseMotionListener(new MouseMotionAdapter() {

    public void mouseDragged (MouseEvent evento)
    if (cuentapuntos < puntos.length)
    puntos[cuentapuntos] = evento.getPoint();


    public void paintComponent(Graphics g)

    for(int i = 0; i < cuentapuntos; i++)
    g.fillOval(puntos[i].x, puntos[i].y, 10, 10);


  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    Please use code tags when posting code.

    What you're seeing is what your paintComponent(...) override draws. if you want the points to be connected, draw a series of lines connecting each consecutive pair of points instead of a [10,10] oval around each point.

    You may also want to learn about Graphics2D#setStroke(...)
    Stroking and Filling Graphics Primitives (The Java™ Tutorials > 2D Graphics > Working with Geometry)


Similar Threads

  1. Java Paint Program problem (JPanel)
    By KilKidd in forum Advanced Java
    Replies: 6
    Last Post: 11-20-2010, 05:31 AM
  2. Paint Program Help
    By ngiannini in forum AWT / Swing
    Replies: 12
    Last Post: 05-10-2010, 05:24 PM
  3. how to add more than one paint method
    By gautham in forum Java 2D
    Replies: 2
    Last Post: 04-06-2010, 08:07 AM
  4. Simple Paint program question
    By StressaJune in forum New To Java
    Replies: 1
    Last Post: 03-30-2009, 09:46 PM
  5. Replies: 3
    Last Post: 12-31-2008, 06:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts