import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class p1 extends JFrame implements ActionListener,MouseMotionListener
{
JFrame f;
JButton b1,b2,b3,b4,b5,b6,b7;
//JLine l;
public p1()
{
f=new JFrame("Paint");
b1=new JButton("Line");
b2=new JButton("Squre");
b3=new JButton("ovel");
b4=new JButton("Squre pencil");
b5=new JButton("ovel pencil");
b6=new JButton("clear");
b7=new JButton("exit");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(b6);
f.add(b7);
f.setLayout(new FlowLayout());
f.setSize(600,500);
f.setVisible(true);
}
void set1()
{
void MouseDragged(MouseEvent me)
{
int x,y;
x=me.getX();
y=me.getY();
Graphics g=getGraphics();
// g.setColor(COLOR.BLACK);
g.drawLine(x,y,10,10);
}
}
/* public void MouseDragged2(MouseEvent me)
{
int x,y;
x=me.getX();
y=me.getY();
Graphics g=getGraphics();
//g.setcolor(COLOR.BLACK);
g.drawRect(x,y,10,10);
}
public void MouseDragged3(MouseEvent me)
{
int x,y;
x=me.getX();
y=me.getY();
Graphics g=getGraphics();
// g.setcolor(COLOR.BLACK);
g.drawOval(x,y,10,10);
}
public void MouseDragged4(MouseEvent me)
{
int x,y;
x=me.getX();
y=me.getY();
Random r=new Random();
Float r1=r.nextFloat();
Float g1=r.nextFloat();
Float b1=r.nextFloat();
Color c=new Color(r1,g1,b1);
Graphics g=getGraphics();
g.setColor(c);
g.drawLine(x,y,10,10);
}
public void MouseDragged5(MouseEvent me)
{
int x,y;
x=me.getX();
y=me.getY();
Random r=new Random();
Float r1=r.nextFloat();
Float g1=r.nextFloat();
Float b1=r.nextFloat();
Color c=new Color(r1,g1,b1);
Graphics g=getGraphics();
g.setColor(c);
g.drawLine(x,y,10,10);
}
public void MouseDragged6(MouseEvent me)
{
getContentPane().setBackground(Color.WHITE);
}
*/
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
set1();
}
else if(ae.getSource()==b2)
{
//MouseDragged2();
}
else if(ae.getSource()==b3)
{
//MouseDragged3();
}
else if(ae.getSource()==b4)
{
//MouseDragged4();
}
else if(ae.getSource()==b5)
{
//MouseDragged5();
}
else if(ae.getSource()==b6)
{
//MouseDragged6();
}
else
{
System.exit(0);
}
}
public void MouseMoved(MouseEvent me1)
{
}
public static void main(String args[])
{
new p1();
}
}
No comments:
Post a Comment