import java.awt.*;
import java.lang.Math;
import java.awt.event.*;
import java.applet.Applet;
public class Resize extends Applet implements MouseListener
{
                Image image;
                boolean mouseUp=false;
                Point start,end;
                public void init()
                {
                                image=getImage(getDocumentBase(),"Image.png");
                                addMouseListener(this);
                }
                public void mousePressed(MouseEvent e)
                {
                                mouseUp=false;
                                start=new Point(e.getX(),e.getY());
                }
                public void mouseReleased(MouseEvent e)
                {
                                mouseUp=true;
                                end=new Point(Math.max(e.getX(),start.x),Math.max(e.getY(),start.y));
                                start=new Point(Math.min(e.getX(),start.x),Math.min(e.getY(),start.y));
                                repaint();
                }
                public void mouseClicked(MouseEvent e)             {}
                public void mouseEntered(MouseEvent e)            {}
                public void mouseExited(MouseEvent e) {}
                public void paint(Graphics g)
                {
                                if(mouseUp)
                                {
                                                int width=end.x-start.x;
                                                int height=end.y-start.y;
                                                g.drawImage(image,start.x,start.y,width,height,this);
                                }
                }
}

 

<HTML>
                <APPLET
                                CODE=Resize.class
                                WIDTH=350
                                HEIGHT=350>
                </APPLET>
</HTML>

JAVA 45.PNG

Advertisements