MSPaint


import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.geom.Line2D;
import java.awt.Graphics2D;
import java.awt.Graphics;

class MSPaint extends JFrame implements MouseListener{
int x1,y1,x2,y2;
MSPaint(){

this.addMouseListener(this);
this.setLayout(new BorderLayout());
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void mouseClicked(MouseEvent me) {
}

public void mouseEntered(MouseEvent me) {

}

public void mouseExited(MouseEvent me) {
}
public void mousePressed(MouseEvent me) {
x1 = me.getX();
y1 = me.getY();
// System.out.println(x1+” , “+y1);
}
public void mouseReleased(MouseEvent me) {
x2 = me.getX();
y2 = me.getY();
repaint();
}
public void paint(Graphics g) {
super.paint(g);
g.drawLine(x1,y1,x2,y2);
}
public static void main(String args[]){
MSPaint p=new MSPaint();

}
}