ArdoiseMagique.java 1.56 KB
package tp2.ArdoiseMagique;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ArdoiseMagique extends JFrame {

    public ArdoiseMagique() {
        super();
        this.setLocationRelativeTo(null);

        Ardoise ard = new Ardoise();
        ard.addMouseMotionListener(new MouseMotionAdapter() {
            @Override
            public void mouseDragged(MouseEvent e) {
                super.mouseDragged(e);
                Ardoise a = (Ardoise) e.getSource();
                if (SwingUtilities.isLeftMouseButton(e)) {
                    a.setPixel(
                        e.getX(),
                        e.getY(),
                        Ardoise.BLACK
                    );
                } else if (SwingUtilities.isRightMouseButton(e)) {
                    a.wipe();
                }
            }
        });

        ard.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                Ardoise src = (Ardoise) e.getSource();
                if (SwingUtilities.isLeftMouseButton(e)) {
                    src.resetOld();
                } else if (SwingUtilities.isRightMouseButton(e)){
                    src.wipe();
                }
            }
        });
        ard.setPreferredSize(new Dimension(1000,600));
        this.add(ard);

        this.setResizable(false);
        this.pack();

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    public static void main(String[] args) {
        new ArdoiseMagique();
    }

}