1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
   | public class Paneau extends JPanel implements MouseListener,MouseMotionListener
{   
    Fenetre jf;
    int x1; int y1;
    int x2;int y2;
    public Paneau(Fenetre jf)
    {
        this.jf=jf;
        setBackground(Color.WHITE);
        this.addMouseListener(this);
        this.addMouseMotionListener(this);
    }
    public void mouseClicked(MouseEvent m){}
    public void mousePressed(MouseEvent m)
    {x1=m.getX(); y1=m.getY();}
    public void mouseReleased(MouseEvent m)
    {}
    public void mouseEntered(MouseEvent m){}
    public void mouseExited(MouseEvent m){}
 
    public void mouseDragged(MouseEvent m)
    {x2=m.getX();y2=m.getY(); repaint();}
    public void mouseMoved(MouseEvent m){}
 
    public void paintComponent(Graphics g)
    {
 
        super.paintComponent(g);
        boolean etat1=jf.etatlign();
        boolean etat2=jf.etatrect();
        boolean etat3=jf.etatcerc();
        if(etat1)
        {
            g.drawLine(x1 , y1, x2, y2);          
        }
        if(etat2)
        {
            g.drawRect(x1, y1, x2-x1, y2-y1);
        }
        if(etat3)
        {
            g.drawOval(x1, y1, x2-x1, y2-y1);
        }
    } | 
Partager