Painting Editor/ Drawing Pad in JAVA
/**
* MakeCodeEasy
*/
import java.awt.*;
import java.awt.event.*;
public class Painting implements MouseMotionListener,MouseListener
{
Frame f;
int x,y;
int px;
int py;
int count=0;
public Painting()
{
f=new Frame();
f.setSize(400,400);
f.setVisible(true);
f.addMouseMotionListener(this);
f.addMouseListener(this);
WindowCloser wc=new WindowCloser();
f.addWindowListener(wc);
}
public void mouseDragged(MouseEvent e1)
{
}
public void mouseMoved(MouseEvent e2)
{
if(count==0)
{
x=e2.getX();
y=e2.getY();
Graphics g=f.getGraphics();
g.setColor(Color.blue);
g.drawLine(x,y,x,y);
px=x;
py=y;
count=1;
}
else
{
x=e2.getX();
y=e2.getY();
Graphics g=f.getGraphics();
g.setColor(Color.blue);
g.drawLine(px,py,x,y);
px=x;
py=y;
}
}
public void mouseClicked(MouseEvent e3)
{
}
public void mouseEntered(MouseEvent e4)
{
}
public void mouseExited(MouseEvent e5)
{
count=0;
}
public void mousePressed(MouseEvent e6)
{
count=0;
}
public void mouseReleased(MouseEvent e7)
{
}
public static void main(String args[])
{
Painting pnt=new Painting();
}
}
Output :-
/**
* MakeCodeEasy
*/
import java.awt.*;
import java.awt.event.*;
public class Painting implements MouseMotionListener,MouseListener
{
Frame f;
int x,y;
int px;
int py;
int count=0;
public Painting()
{
f=new Frame();
f.setSize(400,400);
f.setVisible(true);
f.addMouseMotionListener(this);
f.addMouseListener(this);
WindowCloser wc=new WindowCloser();
f.addWindowListener(wc);
}
public void mouseDragged(MouseEvent e1)
{
}
public void mouseMoved(MouseEvent e2)
{
if(count==0)
{
x=e2.getX();
y=e2.getY();
Graphics g=f.getGraphics();
g.setColor(Color.blue);
g.drawLine(x,y,x,y);
px=x;
py=y;
count=1;
}
else
{
x=e2.getX();
y=e2.getY();
Graphics g=f.getGraphics();
g.setColor(Color.blue);
g.drawLine(px,py,x,y);
px=x;
py=y;
}
}
public void mouseClicked(MouseEvent e3)
{
}
public void mouseEntered(MouseEvent e4)
{
}
public void mouseExited(MouseEvent e5)
{
count=0;
}
public void mousePressed(MouseEvent e6)
{
count=0;
}
public void mouseReleased(MouseEvent e7)
{
}
public static void main(String args[])
{
Painting pnt=new Painting();
}
}
Output :-

I think I will become a great follower.Just want to say your article is striking. The clarity in your post is simply striking and i can take for granted you are an expert on this subject.
ReplyDeletebar sets with stools
thanks Bryan
DeleteThanx dude.
ReplyDelete