diff --git a/ProjetJava/src/main/java/main/projetjava/ProjetJava.java b/ProjetJava/src/main/java/main/projetjava/ProjetJava.java index 0a274f3ed2df6ed733280ce578c404048697f3d4..ec4bb59254e5623672f7653516ad585c411c1d10 100644 --- a/ProjetJava/src/main/java/main/projetjava/ProjetJava.java +++ b/ProjetJava/src/main/java/main/projetjava/ProjetJava.java @@ -5,7 +5,9 @@ package main.projetjava; import dao.DaoQuestion; import db.DbConnection; -import models.Questions; +import javax.swing.SwingUtilities; +import views.MagicSlate; +import views.QuestionPanel; /** * @@ -14,19 +16,6 @@ import models.Questions; public class ProjetJava { public static void main(String[] args) { - var daoq = new DaoQuestion(); - for (Questions question : daoq.list()) { - System.out.println("question = " + question); - } - var q = daoq.read(1); - System.out.println("q = " + q); - q.setQuestion("Quel est la capital de la France ?"); - q.setAnswer("Paris"); - q.setLevel(1); - daoq.update(q); - System.out.println("q = " + daoq.read(1)); - System.out.println("Nombre de questions : " + daoq.count()); - DbConnection.closeConnection(); } } diff --git a/ProjetJava/src/main/java/views/MagicSlate.java b/ProjetJava/src/main/java/views/MagicSlate.java new file mode 100644 index 0000000000000000000000000000000000000000..b49a9373c68c7de1a6e28430df7fcfe285886ee1 --- /dev/null +++ b/ProjetJava/src/main/java/views/MagicSlate.java @@ -0,0 +1,142 @@ +package views; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Graphics; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; +import javax.swing.JButton; +import javax.swing.JColorChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +/** + * + * @author Vincent + */ +public class MagicSlate extends JPanel{ + + private int x = 0, y = 0; + private final JLabel label = new JLabel(); + private final JPanel buttons = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5)); + private JPanel dessin = new JPanel(); + private Color currentColor = Color.BLACK; + + public MagicSlate() { + + JButton red = new JButton("Rouge"); + JButton yellow = new JButton("Jaune"); + JButton blue = new JButton("Bleu"); + JButton black = new JButton("Noir"); + JButton white = new JButton("Blanc"); + JButton reset = new JButton("Effacer"); + + + //Sur dessin pour éviter le décalage. + //on récupére la position de la souris lorsqu'elle est clické + + dessin.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + x = e.getX(); + y = e.getY(); + setLabel(x, y); + } + }); + //Permet de tracer les traits + dessin.addMouseMotionListener(new MouseMotionAdapter() { + @Override + public void mouseDragged(MouseEvent e) { + Graphics g = dessin.getGraphics(); + if (g != null) { + g.setColor(currentColor); + g.drawLine(x, y, e.getX(), e.getY()); + //g.dispose(); + } + x = e.getX(); + y = e.getY(); + setLabel(x, y); + } + }); + + setLabel(x, y); + + this.setLayout(new BorderLayout()); + this.add(label, BorderLayout.SOUTH); + this.add(dessin, BorderLayout.CENTER); + this.add(buttons, BorderLayout.NORTH); + + buttons.add(red); + buttons.add(blue); + buttons.add(yellow); + buttons.add(black); + buttons.add(white); + buttons.add(reset); + + //Les override qui permettent de changer la couleur du pinceau + + red.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e){ + currentColor = Color.RED; + } + }); + + yellow.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e){ + currentColor = Color.YELLOW; + } + }); + + blue.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e){ + currentColor = Color.BLUE; + } + }); + + black.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e){ + currentColor = Color.BLACK; + } + }); + + white.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e){ + currentColor = Color.WHITE; + } + }); + + reset.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e){ + repaint(); //Permet de reset le tableau + } + }); + +// +// this.setTitle("Dessinons"); + this.setSize(500, 500); +// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); +// this.setLocationRelativeTo(null); +// this.setContentPane(container); + this.setVisible(true); +// this.setResizable(false); + + + + } + + + private void setLabel(int x, int y) { + label.setText("x=" + x + ", y=" + y); + } +} \ No newline at end of file diff --git a/ProjetJava/src/main/java/views/PrimaryWindow.java b/ProjetJava/src/main/java/views/PrimaryWindow.java index 01a2298ac3d075b58c7dcbfc0a3092909d1e7d5d..0ac2dab8b527f9163d38b23b097c91f2f8ea8f88 100644 --- a/ProjetJava/src/main/java/views/PrimaryWindow.java +++ b/ProjetJava/src/main/java/views/PrimaryWindow.java @@ -59,9 +59,7 @@ public class PrimaryWindow extends JFrame { // Création des panneaux [activités] // Ardoise - JPanel panelDessin = new JPanel(); - panelDessin.setBackground(Color.WHITE); - panelDessin.add(new JLabel("Ardoise")); + MagicSlate ardoise = new MagicSlate(); // Calcul JPanel panelCalcul = new JPanel(); @@ -72,7 +70,7 @@ public class PrimaryWindow extends JFrame { QuestionPanel panelQuestion = new QuestionPanel(); // Ajout des onglets visibles - tabbedPane.addTab("Dessin", panelDessin); + tabbedPane.addTab("Dessin", ardoise); tabbedPane.addTab("Calcul", panelCalcul); tabbedPane.addTab("Question", panelQuestion);