From a426f09c791889252fda9ce2abc733f0cba77709 Mon Sep 17 00:00:00 2001 From: "antoine.gagneux" Date: Fri, 3 Apr 2020 17:47:06 +0200 Subject: [PATCH] Premier depot --- .classpath | 6 ++ .gitignore | 1 + .project | 17 ++++ .settings/org.eclipse.jdt.core.prefs | 11 +++ src/ClassePrincipale.java | 12 +++ src/calcul/Simulateur.java | 48 +++++++++++ src/graphique/JPanelDessin.java | 49 ++++++++++++ src/graphique/MaJFrame.java | 114 +++++++++++++++++++++++++++ 8 files changed, 258 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 src/ClassePrincipale.java create mode 100644 src/calcul/Simulateur.java create mode 100644 src/graphique/JPanelDessin.java create mode 100644 src/graphique/MaJFrame.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e461bea --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..fd506b0 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + ExempleTutoSimulation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bb35fa0 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/ClassePrincipale.java b/src/ClassePrincipale.java new file mode 100644 index 0000000..de29f3f --- /dev/null +++ b/src/ClassePrincipale.java @@ -0,0 +1,12 @@ +import graphique.MaJFrame; + +public class ClassePrincipale { + + public static void main(String[] args) { + // TODO Auto-generated method stub + MaJFrame mjf = new MaJFrame(); + mjf.setVisible(true); + + } + +} diff --git a/src/calcul/Simulateur.java b/src/calcul/Simulateur.java new file mode 100644 index 0000000..a316f25 --- /dev/null +++ b/src/calcul/Simulateur.java @@ -0,0 +1,48 @@ +package calcul; + +import graphique.MaJFrame; + +public class Simulateur extends Thread { + + private int valeur; + private MaJFrame mjf; + private boolean pause; + + public Simulateur(int valeur,MaJFrame mjf) { + this.valeur = valeur; + this.mjf = mjf; + pause = false; + } + + public int getValeur() { + return valeur; + } + + public void run() { + while(true) { + if (!pause) { + faireUneEtape(); + } + + //pause + try { + Thread.sleep(200); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + //refresh + mjf.repaint(); + } + } + + private void faireUneEtape() { + valeur =valeur -1; + } + + public void mettreEnPause() { + pause = !pause; + } + + +} diff --git a/src/graphique/JPanelDessin.java b/src/graphique/JPanelDessin.java new file mode 100644 index 0000000..fb21444 --- /dev/null +++ b/src/graphique/JPanelDessin.java @@ -0,0 +1,49 @@ +package graphique; + +import java.awt.*; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.swing.*; + +import calcul.Simulateur; + +public class JPanelDessin extends JPanel { + + private static final long serialVersionUID = -4704888296894874299L; + private Simulateur sim; + + public JPanelDessin() { + sim=null; + } + + public void setSim(Simulateur sim) { + this.sim = sim; + } + + /** + * redéfinition de la methode paintComponent + * @param g + */ + public void paintComponent(Graphics g) { + super.paintComponent(g); + + // Couleur du fond = blanc + this.setBackground(Color.white); + + // Affiche un cercle noir au centre + g.setColor(Color.black); + g.drawOval( this.getWidth() / 2, this.getHeight() / 2, 10, 10);// + + if(sim!=null) { + int val = sim.getValeur(); + g.drawLine(10, this.getHeight() / 2, + ((this.getWidth()-20)*val)/100, this.getHeight() / 2); + + } + + + + } +} diff --git a/src/graphique/MaJFrame.java b/src/graphique/MaJFrame.java new file mode 100644 index 0000000..d4be601 --- /dev/null +++ b/src/graphique/MaJFrame.java @@ -0,0 +1,114 @@ +package graphique; + +import java.awt.BorderLayout; +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; + +import calcul.Simulateur; + +import javax.swing.JLabel; +import java.awt.GridLayout; +import javax.swing.JButton; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class MaJFrame extends JFrame { + + private JPanel contentPane; + private JLabel lblNewLabel_2; + private JPanelDessin panel_1; + private Simulateur sim; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + MaJFrame frame = new MaJFrame(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the frame. + */ + public MaJFrame() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 450, 300); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + contentPane.setLayout(new BorderLayout(0, 0)); + setContentPane(contentPane); + + JPanel panel = new JPanel(); + contentPane.add(panel, BorderLayout.NORTH); + + JLabel lblNewLabel = new JLabel("Mon SUPER Projet"); + panel.add(lblNewLabel); + + panel_1 = new JPanelDessin(); + contentPane.add(panel_1, BorderLayout.CENTER); + + JPanel panel_2 = new JPanel(); + contentPane.add(panel_2, BorderLayout.WEST); + panel_2.setLayout(new GridLayout(5, 1, 0, 0)); + + JPanel panel_3 = new JPanel(); + panel_2.add(panel_3); + + JLabel lblNewLabel_1 = new JLabel("Hello"); + panel_3.add(lblNewLabel_1); + + JPanel panel_4 = new JPanel(); + panel_2.add(panel_4); + + JButton btnNewButton = new JButton("Start"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + clicStart(); + } + }); + panel_4.add(btnNewButton); + + JPanel panel_5 = new JPanel(); + panel_2.add(panel_5); + + JButton btnNewButton_1 = new JButton("Pause"); + btnNewButton_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + clicPause(); + } + }); + panel_5.add(btnNewButton_1); + + JPanel panel_6 = new JPanel(); + panel_2.add(panel_6); + + lblNewLabel_2 = new JLabel("Etape : 0"); + panel_6.add(lblNewLabel_2); + + JPanel panel_7 = new JPanel(); + panel_2.add(panel_7); + } + + protected void clicPause() { + sim.mettreEnPause(); + } + + protected void clicStart() { + sim = new Simulateur(100,this); + panel_1.setSim(sim); + sim.start(); + } + + +}