/**Graphics In Java Example **/
import java.awt.*;
import java.awt.event.*;
class line extends Frame implements MouseListener,ActionListener
{
int x1,x2,y1,y2;
Button b;
public line()
{
addMouseListener(this);
b=new Button("EXIT");
setLayout(new FlowLayout());
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
public void mousePressed(MouseEvent me)
{
x1=me.getX();
y1=me.getY();
}
public void mouseReleased(MouseEvent me)
{
x2=me.getX();
y2=me.getY();
Graphics g=getGraphics();
g.drawLine(x1,y1,x2,y2);
}
public void mouseClicked(MouseEvent me)
{
}
public void mouseEntered(MouseEvent me)
{
}
public void mouseExited(MouseEvent me)
{
}
public static void main(String args[])throws Exception
{
line l=new line();
l.setSize(600,600);
l.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
class line extends Frame implements MouseListener,ActionListener
{
int x1,x2,y1,y2;
Button b;
public line()
{
addMouseListener(this);
b=new Button("EXIT");
setLayout(new FlowLayout());
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
public void mousePressed(MouseEvent me)
{
x1=me.getX();
y1=me.getY();
}
public void mouseReleased(MouseEvent me)
{
x2=me.getX();
y2=me.getY();
Graphics g=getGraphics();
g.drawLine(x1,y1,x2,y2);
}
public void mouseClicked(MouseEvent me)
{
}
public void mouseEntered(MouseEvent me)
{
}
public void mouseExited(MouseEvent me)
{
}
public static void main(String args[])throws Exception
{
line l=new line();
l.setSize(600,600);
l.setVisible(true);
}
}
No comments:
Post a Comment