Blame view

src/tp2/ArdoiseMagique/Main2.java 1.62 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
57
  package tp2.ArdoiseMagique;
  
  import javax.swing.*;
  import java.awt.*;
  import java.awt.event.MouseAdapter;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseMotionAdapter;
  
  public class Main2 extends JFrame {
  
      public Main2 () {
          super();
          this.setLocationRelativeTo(null);
  
          ArdoiseMagique ard = new ArdoiseMagique();
          ard.addMouseMotionListener(new MouseMotionAdapter() {
              @Override
              public void mouseDragged(MouseEvent e) {
                  super.mouseDragged(e);
                  ArdoiseMagique a = (ArdoiseMagique) e.getSource();
                  if (SwingUtilities.isLeftMouseButton(e)) {
                      a.addPoint(
                          e.getX(),
                          e.getY()
                      );
                  } else if (SwingUtilities.isRightMouseButton(e)) {
                      a.clear();
                  }
              }
          });
  
          ard.addMouseListener(new MouseAdapter() {
              @Override
              public void mouseReleased(MouseEvent e) {
                  ArdoiseMagique src = (ArdoiseMagique) e.getSource();
                  if (SwingUtilities.isLeftMouseButton(e)) {
                      src.newCurve();
                  } else if (SwingUtilities.isRightMouseButton(e)){
                      src.clear();
                  }
              }
          });
          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 Main2();
      }
  }