Premier depot
This commit is contained in:
commit
a426f09c79
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
@ -0,0 +1 @@
|
|||
/bin/
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ExempleTutoSimulation</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue