Blame view

src/tp2/ArdoiseMagique/Main.java 1.53 KB
5d736557   shaggy42089   tp2 done
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
45
46
47
48
49
50
51
52
53
54
55
56
  package tp2.ArdoiseMagique;
  
  import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  
  public class Main extends JFrame {
  
      public Main() {
          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 Main();
      }
  
  }