import java.util.*;
import java.awt.*;
import java.awt.event.*;
class Drawframe
extends Frame
{
int mx1=0, my1=0, mx2=20, my2=50;
Vector px= new Vector();
Vector py= new Vector();
int pointn=0;
int pcount=0;
Integer intg;
public Drawframe()
{
px.insertElementAt(new Integer(mx1), pointn);
py.insertElementAt(new Integer(my1), pointn);
++pointn;
px.insertElementAt(new Integer(mx2), pointn);
py.insertElementAt(new Integer(my2), pointn);
addMouseListener(new Madapter(this));
addWindowListener(new Wadapter(this));
}
public void paint(Graphics gp)
{
gp.drawString("pen tool demo",20,40);
pcount=px. size();
for (int i=0;i<pcount-1;i++)
{
int tx1= ((Integer)px.elementAt(i)).intValue();
int tx2= ((Integer)px.elementAt(i+1)).intValue();
int ty1= ((Integer)py.elementAt(i)).intValue();
int ty2= ((Integer)py.elementAt(i+1)).intValue();
gp.drawLine(tx1,ty1,tx2,ty2);
}
}
}
class Wadapter
extends WindowAdapter
{
Drawframe df;
Wadapter(Drawframe dfram)
{
df=dfram;
}
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
}
class Madapter
extends MouseAdapter
{
Drawframe df;
Madapter(Drawframe dfram)
{
df=dfram;
}
public void mousePressed(MouseEvent me)
{
int x1=me.getX();
int y1=me.getY();
df.pointn++;
(df.px).insertElementAt(new Integer(x1), df.pointn);
(df.py).insertElementAt(new Integer(y1), df.pointn);
}
public void mouseDragged(MouseEvent me)
{
int x2=me.getX();
int y2=me.getY();
df.pointn++;
(df.px).insertElementAt(new Integer(x2), df.pointn);
(df.py).insertElementAt(new Integer(y2), df.pointn);
df.repaint();
}
}
class prob171
{
public static void main(String args[])
{
Drawframe frm= new Drawframe();
frm.setSize(300,250);
frm.setTitle("pen Tool Demonstration");
frm.setVisible(true);
}
}
No comments:
Post a Comment