1 Attachment(s)
new to forums help needed in paint program
hello guys i am new to the forums and not able to rectify an error in a drawiing program that i made.
here is the code
Code :
import java.awt.Point;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JPanel;
public class PaintPanel extends JPanel
{
private int pointCount=0;
private Point[] points=new Point[10000];
public PaintPanel()
{
addMouseMotionListener (
new MouseMotionAdapter()
{
public void mouseDragged( MouseEvent event)
{
if ( pointCount < points.length )
{
points[pointCount]=event.getPoint();
pointCount++;
repaint();
}
}
}
);
}
public void PaintComponent(Graphics g)
{
super.paintComponent(g);
for(int i=0; i<pointCount;i++)
g.fillOval(points[i].x,points[i].y,4,4 );
}
}
and
Code :
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Painter
{
public static void main(String[]args)
{
JFrame application = new JFrame("Paint 1.0 by Saif");
PaintPanel paintPanel = new PaintPanel();
application.add(paintPanel, BorderLayout.CENTER);
application.add(new JLabel("Drag da cursor to draw"),BorderLayout.SOUTH);
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.setSize(400,200);
application.setVisible(true);
}
}
here is the snapshot a drawing area should appear but only a window is appearing where i cant draw
sorry "Norm"
Attachment 1257
Re: new to forums help needed in paint program
Quote:
not able to rectify an error
Please explain what the error is.
If you are getting error messages, please copy and paste here the full text.
Re: new to forums help needed in paint program
Re: new to forums help needed in paint program
Your posted code does not have proper formatting making it hard to read.
Try debugging the code by adding println statements to it to show program execution flow so you know what methods are being called and to show the values of variables as their values are changed and used.