Results 1 to 2 of 2
Thread: Help with paint program
- 02-03-2011, 07:43 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 1
- Rep Power
- 0
Help with paint program
Hi
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()
{
setBackground(Color.white);
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged (MouseEvent evento)
{
if (cuentapuntos < puntos.length)
{
puntos[cuentapuntos] = evento.getPoint();
cuentapuntos++;
repaint();
}
}
}
);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
for(int i = 0; i < cuentapuntos; i++)
g.fillOval(puntos[i].x, puntos[i].y, 10, 10);
}
}
- 02-04-2011, 06:26 AM #2
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)
db
Similar Threads
-
Java Paint Program problem (JPanel)
By KilKidd in forum Advanced JavaReplies: 6Last Post: 11-20-2010, 04:31 AM -
Paint Program Help
By ngiannini in forum AWT / SwingReplies: 12Last Post: 05-10-2010, 04:24 PM -
how to add more than one paint method
By gautham in forum Java 2DReplies: 2Last Post: 04-06-2010, 07:07 AM -
Simple Paint program question
By StressaJune in forum New To JavaReplies: 1Last Post: 03-30-2009, 08:46 PM -
just started paint program. am i going the right direction?
By diggitydoggz in forum New To JavaReplies: 3Last Post: 12-31-2008, 05:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks