.
This commit is contained in:
228 files changed
+351
-12
No files matched your search
Generated
+8
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
Generated
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="20" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/algo.iml" filepath="$PROJECT_DIR$/.idea/algo.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,27 @@
|
||||
public class Couple {
|
||||
|
||||
private int q;
|
||||
private int r;
|
||||
|
||||
public Couple(int q, int r) {
|
||||
this.q = q;
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public void setQ(int q) {
|
||||
this.q = q;
|
||||
}
|
||||
|
||||
public int getQ() {
|
||||
return q;
|
||||
}
|
||||
|
||||
public void setR(int r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public int getR() {
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
public class Division {
|
||||
public static void main(String[] args) {
|
||||
Couple test = Division(5, 3);
|
||||
System.out.println(test.getQ() + ": " + test.getR());
|
||||
|
||||
}
|
||||
public static Couple Division(int a, int b){
|
||||
return new Couple(a/b, a%b);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class test {
|
||||
public String testM(){
|
||||
return "yay";
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
System.out.println(testM());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
public class Question {
|
||||
private String text;
|
||||
private String response;
|
||||
|
||||
private String user_input;
|
||||
|
||||
public Question(text, response){
|
||||
this.text = text;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public void Poser(){
|
||||
Scanner resp = new Scanner(System.in);
|
||||
System.out.println(text + ": ")
|
||||
user_input = resp.nextLine();
|
||||
}
|
||||
|
||||
public boolean Verifier(){
|
||||
return user_input == response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
public class Questionnaire {
|
||||
private Question[] questions;
|
||||
|
||||
public void add_question;
|
||||
|
||||
public void poser_tout(){
|
||||
for(Question q: questions){
|
||||
q.Poser();
|
||||
if(q.Verifier())
|
||||
System.out.println("Bravo");
|
||||
else
|
||||
System.out.println("Pas ouf");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
public class TestsQuestionnaire {
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
public class hashmap implements Map{
|
||||
|
||||
public static final TAB_SIZE = 1024;
|
||||
LinkedList[] values = new Object[TAB_SIZE];
|
||||
class HashEntry{ public Object key, values;
|
||||
public HashEntry(Object key, Object value){
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void put(Object key, Object value){
|
||||
int pos = key.hashCode() % values.lenght();
|
||||
if (values[pos] == null){
|
||||
values[pos] = value;
|
||||
return;
|
||||
}
|
||||
if(value[pos] instanceof ArrayList<HashEntry> t){
|
||||
t.add(new HashEntry(key, value));
|
||||
return;
|
||||
}
|
||||
Object temp = values[pos];
|
||||
values[pos] = new ArrayList<HashEntry>;
|
||||
value[pos].add(temp);
|
||||
value[pos].add(new HashEntry(key, value));
|
||||
}
|
||||
|
||||
public Object get(Object key){
|
||||
int pos = key.hashCode() % values.lenght();
|
||||
if(values[pos].equals(key)){
|
||||
return values[pos].value;
|
||||
}
|
||||
if(values[pos] instanceof ArrayList<HashEntry> t){
|
||||
for (v : t) {
|
||||
if (v.key.equals(key)){
|
||||
return v.value
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("test");
|
||||
|
||||
}
|
||||
}
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
Generated
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="20" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/hashmap.iml" filepath="$PROJECT_DIR$/hashmap.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,36 @@
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class HashMap {
|
||||
LinkedList<HashEntry>[] tab;
|
||||
Iterator iter;
|
||||
|
||||
class HashEntry{
|
||||
public Object key, value;
|
||||
}
|
||||
|
||||
class MyHashMapIterator implements Iterator{
|
||||
int i;
|
||||
|
||||
public MyHashMapIterator(){
|
||||
while(i<tab.length){
|
||||
if(tab[i] == null)
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if(i >= tab.length)
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object next() {
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="GENERAL_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,18 @@
|
||||
public class Cercle {
|
||||
public static final double PI = 3.14159265;
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int i = 1; i <= 50; i++) {
|
||||
System.out.println("pour un cercle de rayon : " + i + " Perimetre:" + perimetre(i)+ " aire:" + aire(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static double perimetre(double rayon){
|
||||
return 2*PI*rayon;
|
||||
}
|
||||
|
||||
public static double aire(double rayon){
|
||||
return PI*rayon*rayon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Droites {
|
||||
public static void main(String[] args) {
|
||||
droite(1, 1, 2, 2);
|
||||
if(appartient(-1,1, 0, 2, 2)){
|
||||
System.out.println("yay");
|
||||
}
|
||||
|
||||
}
|
||||
public static void droite(double x1, double y1, double x2, double y2){
|
||||
double dir_x = x2 - x1, dir_y = y2 - y1;
|
||||
double a = -dir_y, b = dir_x;
|
||||
double c = a*x1 + b*y1;
|
||||
System.out.println("equation de la droite: " + a + "x + " + b + "y = " + c);
|
||||
}
|
||||
|
||||
public static boolean appartient(double a, double b, double c, double x, double y){
|
||||
return a * x + b * y == c ;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
String prenom = "Anthony";
|
||||
int age = 21;
|
||||
double taille = 1.85;
|
||||
printHello(prenom, age, taille);
|
||||
|
||||
}
|
||||
|
||||
public static void printHello(String prenom, int age, double taille)
|
||||
{
|
||||
System.out.println("Hello World");
|
||||
System.out.println("Mon nom est " + prenom);
|
||||
System.out.println("J'ai " + age + "ans et je mesure " + taille + "m :)");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
public class Suite {
|
||||
public static void main(String[] args) {
|
||||
// suiteArithmetique(5, 5, 3);
|
||||
// suiteGeometrique(5, 5, 3);
|
||||
suiteFibonacci(15);
|
||||
|
||||
}
|
||||
|
||||
public static void suiteArithmetique(int depart, int raison, int k){
|
||||
for (int i = 0; i < k; i++) {
|
||||
System.out.println(depart + raison * i);
|
||||
}
|
||||
}
|
||||
|
||||
public static void suiteGeometrique(int depart, int raison, int k){
|
||||
for (int i = 0; i < k; i++) {
|
||||
System.out.println(depart + (int)Math.pow(raison, i));
|
||||
}
|
||||
}
|
||||
|
||||
public static void suiteFibonacci(int k){
|
||||
int el1 = 1;
|
||||
int el2 = 1;
|
||||
int temp;
|
||||
for (int i = 0; i < k-2; i++) {
|
||||
temp = el1;
|
||||
el1 = el2;
|
||||
el2 = temp + el2 ;
|
||||
}
|
||||
System.out.println(el2);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,60 @@
|
||||
public class Droite {
|
||||
public double a, b, c;
|
||||
|
||||
public String toString(){
|
||||
return a + "x + " + b + "y = " + c;
|
||||
}
|
||||
|
||||
/*
|
||||
* Represent a line in the space with the equation ax + by = c
|
||||
* @param a ax
|
||||
* @param b by
|
||||
* @param c c
|
||||
*/
|
||||
Droite(double a, double b, double c){
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the line is horizontal
|
||||
* @return true if the line is horizontal
|
||||
* @return false if the line is not horizontal
|
||||
*/
|
||||
public boolean isHorizontal(){
|
||||
if(a == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the intersection by 2 lines
|
||||
* @param other the other line you should find the intersection with
|
||||
* @return Point The Point of the intersection
|
||||
* @return Null if the lines are not intersecting
|
||||
* @return Null if the lines are the sames
|
||||
*/
|
||||
public Point intersection(Droite other){
|
||||
if(a * other.b - b * other.a == 0)
|
||||
return null;
|
||||
return new Point((other.b*c - b*other.c)/(a*other.b + b * other.a), (other.c - other.a*((other.b*c - b*other.c)/(a*other.b + b * other.a)))/other.b );
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new line with the two points given
|
||||
* @param p1 the first point
|
||||
* @param p2 the second point
|
||||
* @return Droite the line that is between the given points
|
||||
*/
|
||||
public static Droite create(Point p1, Point p2){
|
||||
System.out.println(p1 + "; " + p2);
|
||||
Point directeur = new Point(p2.getX() - p1.getX(), p2.getY() - p2.getY());
|
||||
System.out.println(directeur);
|
||||
double a = -directeur.getY();
|
||||
double b = directeur.getX();
|
||||
return new Droite(a, b, a*p1.getX() + b*p1.getY());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
public class DroiteTest {
|
||||
public static void main(String[] args) {
|
||||
Point p1 = new Point(1, 1);
|
||||
Point p2 = new Point(5, 3);
|
||||
Point p3 = new Point(0, 4);
|
||||
Point p4 = new Point(4, 6);
|
||||
|
||||
Droite d1 = new Droite(0, 1, 2);
|
||||
System.out.println(d1);
|
||||
|
||||
Droite d2 = Droite.create(p1, p2);
|
||||
Droite d3 = Droite.create(p3, p4);
|
||||
System.out.println(d2);
|
||||
System.out.println(d3);
|
||||
|
||||
if(d2.isHorizontal())
|
||||
System.out.println("d2 is horizontal");
|
||||
if(d3.isHorizontal())
|
||||
System.out.println("d3 is horizontal");
|
||||
|
||||
Point int1 = d1.intersection(d2);
|
||||
if(int1 == null)
|
||||
System.out.println("d1 et d2 sont paralleles ou confondues");
|
||||
|
||||
Point int2 = d1.intersection(d3);
|
||||
if(int2 == null)
|
||||
System.out.println("d1 et d3 sont paralleles ou confondues");
|
||||
|
||||
Point int3 = d2.intersection(d3);
|
||||
if(int3 == null)
|
||||
System.out.println("d2 et d3 sont paralleles ou confondues");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
public class Point {
|
||||
private double x, y;
|
||||
|
||||
public String toString(){
|
||||
return "("+ x+ ":" + y + ")";
|
||||
}
|
||||
|
||||
Point(){
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
Point(double x, double y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,112 @@
|
||||
package tours_hanoi;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class HanoiFrame extends JFrame implements HanoiState.Listener {
|
||||
|
||||
private final HanoiState state;
|
||||
private final int delay;
|
||||
|
||||
public static final int MARGIN_X = 10;
|
||||
public static final int MARGIN_Y = 10;
|
||||
public static final int TOWER_W = 10; // Largeur d'une tour
|
||||
public static final int DISK_H = 30; // Hauteur d'un disque
|
||||
|
||||
public static final Color DISK_COLOR = Color.BLUE;
|
||||
|
||||
private class HanoiPanel extends JPanel {
|
||||
|
||||
/** Dessine la tour d'index i
|
||||
*
|
||||
* @param g contexte graphique
|
||||
* @param i index de la tour (0 <= i < NUM_TOWERS)
|
||||
*/
|
||||
private void drawTower(Graphics g, int i) {
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
int tw = (w - (2 + HanoiState.NUM_TOWERS - 1) * MARGIN_X) / HanoiState.NUM_TOWERS; // largeur espace tour
|
||||
g.fillRect(MARGIN_X + tw / 2 + i * tw - TOWER_W / 2, MARGIN_Y, TOWER_W, h - 2 * MARGIN_Y);
|
||||
}
|
||||
|
||||
/** Dessine un disque de taille size sur la tour i en hauteur j
|
||||
*
|
||||
* @param g contexte graphique
|
||||
* @param i index de la tour (0 <= i < NUM_TOWERS)
|
||||
* @param j hauteur du disque (0 <= j)
|
||||
* @param size taille du disque (0 <= size < MAX_DISKS)
|
||||
*/
|
||||
private void drawDisk(Graphics g, int i, int j, int size) {
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
int tw = (w - (2 + HanoiState.NUM_TOWERS - 1) * MARGIN_X) / HanoiState.NUM_TOWERS; // largeur espace tour
|
||||
int x = MARGIN_X + tw / 2 + i * tw;
|
||||
int y = h - MARGIN_Y - (j + 1) * DISK_H;
|
||||
int pw = TOWER_W + (int) (1.0 * (tw - TOWER_W) * (size + 1) / HanoiState.MAX_DISKS);
|
||||
|
||||
g.setColor(DISK_COLOR);
|
||||
g.fillRect(x - pw / 2, y, pw, DISK_H);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(x - pw / 2, y, pw, DISK_H);
|
||||
}
|
||||
|
||||
/** Dessine les tours et disques sur base de l'état du jeu */
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
for (int i = 0; i < HanoiState.NUM_TOWERS; i++) {
|
||||
drawTower(g, i);
|
||||
for (int j = 0; j < state.getNumDisks(i); j++)
|
||||
drawDisk(g, i, j, state.getDiskSize(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JLabel labelCountMoves;
|
||||
|
||||
/** Crée une instance de fenêtre représentant l'état du jeu
|
||||
*
|
||||
* @param state état du jeu
|
||||
* @param delay délai en millisecondes attendu après chaque mise à jour
|
||||
*/
|
||||
public HanoiFrame(HanoiState state, int delay) {
|
||||
super("Tours de Hanoï");
|
||||
this.state = state;
|
||||
this.delay = delay;
|
||||
|
||||
state.addListener(this);
|
||||
|
||||
JPanel outerPanel = new JPanel(new BorderLayout());
|
||||
add(outerPanel);
|
||||
JPanel topPanel = new JPanel(new FlowLayout());
|
||||
labelCountMoves = new JLabel("0 déplacements");
|
||||
topPanel.add(labelCountMoves);
|
||||
outerPanel.add(new HanoiPanel(), BorderLayout.CENTER);
|
||||
outerPanel.add(topPanel, BorderLayout.NORTH);
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
setSize(screenSize);
|
||||
setVisible(true);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
/** Met à jour la représentation graphique du jeu */
|
||||
@Override
|
||||
public void stateChanged() {
|
||||
int mc = state.getMovesCount();
|
||||
labelCountMoves.setText(mc + " déplacement" + (mc > 1 ? "s" : ""));
|
||||
repaint();
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<!-- NewPage -->
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<!-- Generated by javadoc (1.8.0_144) on Tue Feb 20 13:30:33 CET 2018 -->
|
||||
<title>HanoiState</title>
|
||||
<meta name="date" content="2018-02-20">
|
||||
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
|
||||
<script type="text/javascript" src="../script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript"><!--
|
||||
try {
|
||||
if (location.href.indexOf('is-external=true') == -1) {
|
||||
parent.document.title="HanoiState";
|
||||
}
|
||||
}
|
||||
catch(err) {
|
||||
}
|
||||
//-->
|
||||
var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10};
|
||||
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
|
||||
var altColor = "altColor";
|
||||
var rowColor = "rowColor";
|
||||
var tableTab = "tableTab";
|
||||
var activeTableTab = "activeTableTab";
|
||||
</script>
|
||||
<noscript>
|
||||
<div>JavaScript is disabled on your browser.</div>
|
||||
</noscript>
|
||||
<!-- ========= START OF TOP NAVBAR ======= -->
|
||||
<div class="topNav"><a name="navbar.top">
|
||||
<!-- -->
|
||||
</a>
|
||||
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
|
||||
<a name="navbar.top.firstrow">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="navList" title="Navigation">
|
||||
<li><a href="../tours_hanoi/package-summary.html">Package</a></li>
|
||||
<li class="navBarCell1Rev">Class</li>
|
||||
<li><a href="package-tree.html">Tree</a></li>
|
||||
<li><a href="../deprecated-list.html">Deprecated</a></li>
|
||||
<li><a href="../index-all.html">Index</a></li>
|
||||
<li><a href="../help-doc.html">Help</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="subNav">
|
||||
<ul class="navList">
|
||||
<li>Prev Class</li>
|
||||
<li><a href="../tours_hanoi/HanoiState.Listener.html" title="interface in tours_hanoi"><span class="typeNameLink">Next Class</span></a></li>
|
||||
</ul>
|
||||
<ul class="navList">
|
||||
<li><a href="../index.html?tours_hanoi/HanoiState.html" target="_top">Frames</a></li>
|
||||
<li><a href="HanoiState.html" target="_top">No Frames</a></li>
|
||||
</ul>
|
||||
<ul class="navList" id="allclasses_navbar_top">
|
||||
<li><a href="../allclasses-noframe.html">All Classes</a></li>
|
||||
</ul>
|
||||
<div>
|
||||
<script type="text/javascript"><!--
|
||||
allClassesLink = document.getElementById("allclasses_navbar_top");
|
||||
if(window==top) {
|
||||
allClassesLink.style.display = "block";
|
||||
}
|
||||
else {
|
||||
allClassesLink.style.display = "none";
|
||||
}
|
||||
//-->
|
||||
</script>
|
||||
</div>
|
||||
<div>
|
||||
<ul class="subNavList">
|
||||
<li>Summary: </li>
|
||||
<li><a href="#nested.class.summary">Nested</a> | </li>
|
||||
<li><a href="#field.summary">Field</a> | </li>
|
||||
<li><a href="#constructor.summary">Constr</a> | </li>
|
||||
<li><a href="#method.summary">Method</a></li>
|
||||
</ul>
|
||||
<ul class="subNavList">
|
||||
<li>Detail: </li>
|
||||
<li><a href="#field.detail">Field</a> | </li>
|
||||
<li><a href="#constructor.detail">Constr</a> | </li>
|
||||
<li><a href="#method.detail">Method</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<a name="skip.navbar.top">
|
||||
<!-- -->
|
||||
</a></div>
|
||||
<!-- ========= END OF TOP NAVBAR ========= -->
|
||||
<!-- ======== START OF CLASS DATA ======== -->
|
||||
<div class="header">
|
||||
<div class="subTitle">tours_hanoi</div>
|
||||
<h2 title="Class HanoiState" class="title">Class HanoiState</h2>
|
||||
</div>
|
||||
<div class="contentContainer">
|
||||
<ul class="inheritance">
|
||||
<li>java.lang.Object</li>
|
||||
<li>
|
||||
<ul class="inheritance">
|
||||
<li>tours_hanoi.HanoiState</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="description">
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<hr>
|
||||
<br>
|
||||
<pre>public class <span class="typeNameLabel">HanoiState</span>
|
||||
extends java.lang.Object</pre>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="summary">
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<!-- ======== NESTED CLASS SUMMARY ======== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="nested.class.summary">
|
||||
<!-- -->
|
||||
</a>
|
||||
<h3>Nested Class Summary</h3>
|
||||
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Nested Class Summary table, listing nested classes, and an explanation">
|
||||
<caption><span>Nested Classes</span><span class="tabEnd"> </span></caption>
|
||||
<tr>
|
||||
<th class="colFirst" scope="col">Modifier and Type</th>
|
||||
<th class="colLast" scope="col">Class and Description</th>
|
||||
</tr>
|
||||
<tr class="altColor">
|
||||
<td class="colFirst"><code>static interface </code></td>
|
||||
<td class="colLast"><code><span class="memberNameLink"><a href="../tours_hanoi/HanoiState.Listener.html" title="interface in tours_hanoi">HanoiState.Listener</a></span></code>
|
||||
<div class="block">Permet d'être notifié des changements d'états
|
||||
(utilisé p.ex. par la fenêtre d'affichage)</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- =========== FIELD SUMMARY =========== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="field.summary">
|
||||
<!-- -->
|
||||
</a>
|
||||
<h3>Field Summary</h3>
|
||||
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Field Summary table, listing fields, and an explanation">
|
||||
<caption><span>Fields</span><span class="tabEnd"> </span></caption>
|
||||
<tr>
|
||||
<th class="colFirst" scope="col">Modifier and Type</th>
|
||||
<th class="colLast" scope="col">Field and Description</th>
|
||||
</tr>
|
||||
<tr class="altColor">
|
||||
<td class="colFirst"><code>static int</code></td>
|
||||
<td class="colLast"><code><span class="memberNameLink"><a href="../tours_hanoi/HanoiState.html#MAX_DISKS">MAX_DISKS</a></span></code>
|
||||
<div class="block">Nombre max. de pièces</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="rowColor">
|
||||
<td class="colFirst"><code>static int</code></td>
|
||||
<td class="colLast"><code><span class="memberNameLink"><a href="../tours_hanoi/HanoiState.html#NUM_TOWERS">NUM_TOWERS</a></span></code>
|
||||
<div class="block">Nombre de tours</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="constructor.summary">
|
||||
<!-- -->
|
||||
</a>
|
||||
<h3>Constructor Summary</h3>
|
||||
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
|
||||
<caption><span>Constructors</span><span class="tabEnd"> </span></caption>
|
||||
<tr>
|
||||
<th class="colOne" scope="col">Constructor and Description</th>
|
||||
</tr>
|
||||
<tr class="altColor">
|
||||
<td class="colOne"><code><span class="memberNameLink"><a href="../tours_hanoi/HanoiState.html#HanoiState-int-">HanoiState</a></span>(int n)</code>
|
||||
<div class="block">Construit un jeu des Tours de Hanoï à n disques</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- ========== METHOD SUMMARY =========== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="method.summary">
|
||||
<!-- -->
|
||||
</a>
|
||||
<h3>Method Summary</h3>
|
||||
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
|
||||
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd"> </span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd"> </span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd"> </span></span></caption>
|
||||
<tr>
|
||||
<th class="colFirst" scope="col">Modifier and Type</th>
|
||||
<th class="colLast" scope="col">Method and Description</th>
|
||||
</tr>
|
||||
<tr id="i0" class="altColor">
|
||||
<td class="colFirst"><code>void</code></td>
|
||||
<td class="colLast"><code><span class="memberNameLink"><a href="../tours_hanoi/HanoiState.html#addListener-tours_hanoi.HanoiState.Listener-">addListener</a></span>(<a href="../tours_hanoi/HanoiState.Listener.html" title="interface in tours_hanoi">HanoiState.Listener</a> l)</code>
|
||||
<div class="block">Enregistre un listener supplémentaire</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="i1" class="rowColor">
|
||||
<td class="colFirst"><code>int</code></td>
|
||||
<td class="colLast"><code><span class="memberNameLink"><a href="../tours_hanoi/HanoiState.html#getDiskSize-int-int-">getDiskSize</a></span>(int tower,
|
||||
int j)</code>
|
||||
<div class="block">Retourne la taille de la pièce en position j de la tour i</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="i2" class="altColor">
|
||||
<td class="colFirst"><code>int</code></td>
|
||||
<td class="colLast"><code><span class="memberNameLink"><a href="../tours_hanoi/HanoiState.html#getMovesCount--">getMovesCount</a></span>()</code>
|
||||
<div class="block">Retourne le nombre total de déplacements</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="i3" class="rowColor">
|
||||
<td class="colFirst"><code>int</code></td>
|
||||
<td class="colLast"><code><span class="memberNameLink"><a href="../tours_hanoi/HanoiState.html#getNumDisks-int-">getNumDisks</a></span>(int tower)</code>
|
||||
<div class="block">Retourne le nombre de pièces sur la tour i</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="i4" class="altColor">
|
||||
<td class="colFirst"><code>void</code></td>
|
||||
<td class="colLast"><code><span class="memberNameLink"><a href="../tours_hanoi/HanoiState.html#move-int-int-">move</a></span>(int from,
|
||||
int to)</code>
|
||||
<div class="block">Déplace une pièce du sommet d'une tour au sommet d'une autre tour.</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
|
||||
<!-- -->
|
||||
</a>
|
||||
<h3>Methods inherited from class java.lang.Object</h3>
|
||||
<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="details">
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<!-- ============ FIELD DETAIL =========== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="field.detail">
|
||||
<!-- -->
|
||||
</a>
|
||||
<h3>Field Detail</h3>
|
||||
<a name="NUM_TOWERS">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<h4>NUM_TOWERS</h4>
|
||||
<pre>public static final int NUM_TOWERS</pre>
|
||||
<div class="block">Nombre de tours</div>
|
||||
<dl>
|
||||
<dt><span class="seeLabel">See Also:</span></dt>
|
||||
<dd><a href="../constant-values.html#tours_hanoi.HanoiState.NUM_TOWERS">Constant Field Values</a></dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
<a name="MAX_DISKS">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="blockListLast">
|
||||
<li class="blockList">
|
||||
<h4>MAX_DISKS</h4>
|
||||
<pre>public static final int MAX_DISKS</pre>
|
||||
<div class="block">Nombre max. de pièces</div>
|
||||
<dl>
|
||||
<dt><span class="seeLabel">See Also:</span></dt>
|
||||
<dd><a href="../constant-values.html#tours_hanoi.HanoiState.MAX_DISKS">Constant Field Values</a></dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- ========= CONSTRUCTOR DETAIL ======== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="constructor.detail">
|
||||
<!-- -->
|
||||
</a>
|
||||
<h3>Constructor Detail</h3>
|
||||
<a name="HanoiState-int-">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="blockListLast">
|
||||
<li class="blockList">
|
||||
<h4>HanoiState</h4>
|
||||
<pre>public HanoiState(int n)</pre>
|
||||
<div class="block">Construit un jeu des Tours de Hanoï à n disques</div>
|
||||
<dl>
|
||||
<dt><span class="paramLabel">Parameters:</span></dt>
|
||||
<dd><code>n</code> - Le nombre de disques</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- ============ METHOD DETAIL ========== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="method.detail">
|
||||
<!-- -->
|
||||
</a>
|
||||
<h3>Method Detail</h3>
|
||||
<a name="move-int-int-">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<h4>move</h4>
|
||||
<pre>public void move(int from,
|
||||
int to)</pre>
|
||||
<div class="block">Déplace une pièce du sommet d'une tour au sommet d'une autre tour.
|
||||
Vérifie que les contraintes du jeu sont respectées.</div>
|
||||
<dl>
|
||||
<dt><span class="paramLabel">Parameters:</span></dt>
|
||||
<dd><code>from</code> - Indice de la tours de départ</dd>
|
||||
<dd><code>to</code> - Indice de la tour d'arrivée</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
<a name="getNumDisks-int-">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<h4>getNumDisks</h4>
|
||||
<pre>public int getNumDisks(int tower)</pre>
|
||||
<div class="block">Retourne le nombre de pièces sur la tour i</div>
|
||||
<dl>
|
||||
<dt><span class="paramLabel">Parameters:</span></dt>
|
||||
<dd><code>tower</code> - L'indice de la tour</dd>
|
||||
<dt><span class="returnLabel">Returns:</span></dt>
|
||||
<dd>Le nombre de pièces sur la tour</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
<a name="getDiskSize-int-int-">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<h4>getDiskSize</h4>
|
||||
<pre>public int getDiskSize(int tower,
|
||||
int j)</pre>
|
||||
<div class="block">Retourne la taille de la pièce en position j de la tour i</div>
|
||||
<dl>
|
||||
<dt><span class="paramLabel">Parameters:</span></dt>
|
||||
<dd><code>tower</code> - L'indice de la tour</dd>
|
||||
<dd><code>j</code> - La position de la pièce</dd>
|
||||
<dt><span class="returnLabel">Returns:</span></dt>
|
||||
<dd>La taille de la pièce en position j dans la tour</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
<a name="getMovesCount--">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<h4>getMovesCount</h4>
|
||||
<pre>public int getMovesCount()</pre>
|
||||
<div class="block">Retourne le nombre total de déplacements</div>
|
||||
<dl>
|
||||
<dt><span class="returnLabel">Returns:</span></dt>
|
||||
<dd>Le nombre total de déplacements</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ul>
|
||||
<a name="addListener-tours_hanoi.HanoiState.Listener-">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="blockListLast">
|
||||
<li class="blockList">
|
||||
<h4>addListener</h4>
|
||||
<pre>public void addListener(<a href="../tours_hanoi/HanoiState.Listener.html" title="interface in tours_hanoi">HanoiState.Listener</a> l)</pre>
|
||||
<div class="block">Enregistre un listener supplémentaire</div>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ========= END OF CLASS DATA ========= -->
|
||||
<!-- ======= START OF BOTTOM NAVBAR ====== -->
|
||||
<div class="bottomNav"><a name="navbar.bottom">
|
||||
<!-- -->
|
||||
</a>
|
||||
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
|
||||
<a name="navbar.bottom.firstrow">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="navList" title="Navigation">
|
||||
<li><a href="../tours_hanoi/package-summary.html">Package</a></li>
|
||||
<li class="navBarCell1Rev">Class</li>
|
||||
<li><a href="package-tree.html">Tree</a></li>
|
||||
<li><a href="../deprecated-list.html">Deprecated</a></li>
|
||||
<li><a href="../index-all.html">Index</a></li>
|
||||
<li><a href="../help-doc.html">Help</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="subNav">
|
||||
<ul class="navList">
|
||||
<li>Prev Class</li>
|
||||
<li><a href="../tours_hanoi/HanoiState.Listener.html" title="interface in tours_hanoi"><span class="typeNameLink">Next Class</span></a></li>
|
||||
</ul>
|
||||
<ul class="navList">
|
||||
<li><a href="../index.html?tours_hanoi/HanoiState.html" target="_top">Frames</a></li>
|
||||
<li><a href="HanoiState.html" target="_top">No Frames</a></li>
|
||||
</ul>
|
||||
<ul class="navList" id="allclasses_navbar_bottom">
|
||||
<li><a href="../allclasses-noframe.html">All Classes</a></li>
|
||||
</ul>
|
||||
<div>
|
||||
<script type="text/javascript"><!--
|
||||
allClassesLink = document.getElementById("allclasses_navbar_bottom");
|
||||
if(window==top) {
|
||||
allClassesLink.style.display = "block";
|
||||
}
|
||||
else {
|
||||
allClassesLink.style.display = "none";
|
||||
}
|
||||
//-->
|
||||
</script>
|
||||
</div>
|
||||
<div>
|
||||
<ul class="subNavList">
|
||||
<li>Summary: </li>
|
||||
<li><a href="#nested.class.summary">Nested</a> | </li>
|
||||
<li><a href="#field.summary">Field</a> | </li>
|
||||
<li><a href="#constructor.summary">Constr</a> | </li>
|
||||
<li><a href="#method.summary">Method</a></li>
|
||||
</ul>
|
||||
<ul class="subNavList">
|
||||
<li>Detail: </li>
|
||||
<li><a href="#field.detail">Field</a> | </li>
|
||||
<li><a href="#constructor.detail">Constr</a> | </li>
|
||||
<li><a href="#method.detail">Method</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<a name="skip.navbar.bottom">
|
||||
<!-- -->
|
||||
</a></div>
|
||||
<!-- ======== END OF BOTTOM NAVBAR ======= -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,127 @@
|
||||
package tours_hanoi;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class HanoiState {
|
||||
|
||||
/** Nombre de tours */
|
||||
public static final int NUM_TOWERS = 3;
|
||||
|
||||
/** Nombre max. de pièces */
|
||||
public static final int MAX_DISKS = 20;
|
||||
|
||||
/** Modèle d'une pièce (actuellement seulement sa taille (diamètre) */
|
||||
private static class Disk {
|
||||
|
||||
/** Taille de la pièce */
|
||||
public final int size;
|
||||
|
||||
/** Constructeur privé (factory) */
|
||||
private Disk(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
/** Pièces créées */
|
||||
private static final Disk[] DISKS = new Disk[MAX_DISKS];
|
||||
|
||||
/** Crée/retourne une pièce particulière */
|
||||
public static Disk getBySize(int size) {
|
||||
if (DISKS[size] == null)
|
||||
DISKS[size] = new Disk(size);
|
||||
return DISKS[size];
|
||||
}
|
||||
}
|
||||
|
||||
/** Une tour est une pile (empêche d'emblée les accès ailleurs qu'au sommet) */
|
||||
private Stack<Disk> towers[];
|
||||
|
||||
private int countMoves = 0;
|
||||
|
||||
/** Construit un jeu des Tours de Hanoï */
|
||||
@SuppressWarnings("unchecked")
|
||||
private HanoiState() {
|
||||
towers = (Stack<Disk>[]) java.lang.reflect.Array.newInstance(Stack.class, NUM_TOWERS);
|
||||
for (int i = 0; i < NUM_TOWERS; i++)
|
||||
towers[i] = new Stack<Disk>();
|
||||
}
|
||||
|
||||
/** Construit un jeu des Tours de Hanoï à n disques
|
||||
* @param n Le nombre de disques */
|
||||
public HanoiState(int n) {
|
||||
this();
|
||||
for (int i = 0; i < n; i++)
|
||||
add(0, Disk.getBySize(n - 1 - i));
|
||||
}
|
||||
|
||||
/** Ajoute une pièce au sommet d'une tour */
|
||||
private void add(int tower, Disk p) {
|
||||
towers[tower].push(p);
|
||||
}
|
||||
|
||||
/** Déplace une pièce du sommet d'une tour au sommet d'une autre tour.
|
||||
* Vérifie que les contraintes du jeu sont respectées.
|
||||
* @param from Indice de la tours de départ
|
||||
* @param to Indice de la tour d'arrivée*/
|
||||
public void move(int from, int to) {
|
||||
if (towers[from].empty())
|
||||
throw new RuntimeException("Pile source vide");
|
||||
|
||||
if (!towers[to].empty() &&
|
||||
(towers[to].peek().size < towers[from].peek().size))
|
||||
throw new RuntimeException("Déplacement sur une pièce plus grande");
|
||||
|
||||
towers[to].push(towers[from].pop());
|
||||
|
||||
countMoves++;
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/** Retourne le nombre de pièces sur la tour i
|
||||
* @param tower L'indice de la tour
|
||||
* @return Le nombre de pièces sur la tour*/
|
||||
public int getNumDisks(int tower) {
|
||||
return towers[tower].size();
|
||||
}
|
||||
|
||||
/** Retourne la taille de la pièce en position j de la tour i
|
||||
* @param tower L'indice de la tour
|
||||
* @param j La position de la pièce
|
||||
* @return La taille de la pièce en position j dans la tour*/
|
||||
public int getDiskSize(int tower, int j) {
|
||||
return towers[tower].get(j).size;
|
||||
}
|
||||
|
||||
/** Retourne le nombre total de déplacements
|
||||
* @return Le nombre total de déplacements*/
|
||||
public int getMovesCount() {
|
||||
return countMoves;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Permet d'être notifié des changements d'états
|
||||
* (utilisé p.ex. par la fenêtre d'affichage) */
|
||||
public static interface Listener {
|
||||
|
||||
public void stateChanged();
|
||||
|
||||
}
|
||||
|
||||
/** Liste des listeners */
|
||||
private List<Listener> listeners = new ArrayList<Listener>();
|
||||
|
||||
/** Notifie l'ensemble des listeners du changement d'état */
|
||||
private void notifyListeners() {
|
||||
for (Listener l : listeners)
|
||||
l.stateChanged();
|
||||
}
|
||||
|
||||
/** Enregistre un listener supplémentaire */
|
||||
public void addListener(Listener l) {
|
||||
listeners.add(l);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package tours_hanoi;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class Tester {
|
||||
|
||||
/** Nombre de pièces à mettre en jeu
|
||||
* (attention, le nombre de déplacements est de l'ordre de 2^N) */
|
||||
public static final int NUM_DISKS = 6;
|
||||
|
||||
/** Délai entre l'affichage de deux mouvements (en millisecondes) */
|
||||
public static final int DELAY = 1000;
|
||||
|
||||
/** Si cette constante vaut true, les mouvements des pièces sont affichés */
|
||||
public static final boolean SHOW_MOVES = true;
|
||||
|
||||
/** Reference vers fenêtre d'affichage optionnelle */
|
||||
private static HanoiFrame f;
|
||||
|
||||
/** Programme principal */
|
||||
public static void main(String [] args) {
|
||||
HanoiState state = new HanoiState(NUM_DISKS);
|
||||
|
||||
if (SHOW_MOVES) {
|
||||
f = new HanoiFrame(state, DELAY);
|
||||
}
|
||||
solve(state, NUM_DISKS, 0, 2, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Déplace n pièces de la tour d'index tSrc vers la tour d'index tDst.
|
||||
*
|
||||
* @param state référence vers l'état des tours/pièces
|
||||
* @param n nombre de pièces à déplacer
|
||||
* @param tSrc index tour source
|
||||
* @param tDst index tour destination
|
||||
* @param tInt index tour intermédiaire
|
||||
*/
|
||||
private static void solve(HanoiState state, int n, int tSrc, int tDst, int tInt) {
|
||||
state.move(tSrc, tDst);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,574 @@
|
||||
/* Javadoc style sheet */
|
||||
/*
|
||||
Overall document style
|
||||
*/
|
||||
|
||||
@import url('resources/fonts/dejavu.css');
|
||||
|
||||
body {
|
||||
background-color:#ffffff;
|
||||
color:#353833;
|
||||
font-family:'DejaVu Sans', Arial, Helvetica, sans-serif;
|
||||
font-size:14px;
|
||||
margin:0;
|
||||
}
|
||||
a:link, a:visited {
|
||||
text-decoration:none;
|
||||
color:#4A6782;
|
||||
}
|
||||
a:hover, a:focus {
|
||||
text-decoration:none;
|
||||
color:#bb7a2a;
|
||||
}
|
||||
a:active {
|
||||
text-decoration:none;
|
||||
color:#4A6782;
|
||||
}
|
||||
a[name] {
|
||||
color:#353833;
|
||||
}
|
||||
a[name]:hover {
|
||||
text-decoration:none;
|
||||
color:#353833;
|
||||
}
|
||||
pre {
|
||||
font-family:'DejaVu Sans Mono', monospace;
|
||||
font-size:14px;
|
||||
}
|
||||
h1 {
|
||||
font-size:20px;
|
||||
}
|
||||
h2 {
|
||||
font-size:18px;
|
||||
}
|
||||
h3 {
|
||||
font-size:16px;
|
||||
font-style:italic;
|
||||
}
|
||||
h4 {
|
||||
font-size:13px;
|
||||
}
|
||||
h5 {
|
||||
font-size:12px;
|
||||
}
|
||||
h6 {
|
||||
font-size:11px;
|
||||
}
|
||||
ul {
|
||||
list-style-type:disc;
|
||||
}
|
||||
code, tt {
|
||||
font-family:'DejaVu Sans Mono', monospace;
|
||||
font-size:14px;
|
||||
padding-top:4px;
|
||||
margin-top:8px;
|
||||
line-height:1.4em;
|
||||
}
|
||||
dt code {
|
||||
font-family:'DejaVu Sans Mono', monospace;
|
||||
font-size:14px;
|
||||
padding-top:4px;
|
||||
}
|
||||
table tr td dt code {
|
||||
font-family:'DejaVu Sans Mono', monospace;
|
||||
font-size:14px;
|
||||
vertical-align:top;
|
||||
padding-top:4px;
|
||||
}
|
||||
sup {
|
||||
font-size:8px;
|
||||
}
|
||||
/*
|
||||
Document title and Copyright styles
|
||||
*/
|
||||
.clear {
|
||||
clear:both;
|
||||
height:0px;
|
||||
overflow:hidden;
|
||||
}
|
||||
.aboutLanguage {
|
||||
float:right;
|
||||
padding:0px 21px;
|
||||
font-size:11px;
|
||||
z-index:200;
|
||||
margin-top:-9px;
|
||||
}
|
||||
.legalCopy {
|
||||
margin-left:.5em;
|
||||
}
|
||||
.bar a, .bar a:link, .bar a:visited, .bar a:active {
|
||||
color:#FFFFFF;
|
||||
text-decoration:none;
|
||||
}
|
||||
.bar a:hover, .bar a:focus {
|
||||
color:#bb7a2a;
|
||||
}
|
||||
.tab {
|
||||
background-color:#0066FF;
|
||||
color:#ffffff;
|
||||
padding:8px;
|
||||
width:5em;
|
||||
font-weight:bold;
|
||||
}
|
||||
/*
|
||||
Navigation bar styles
|
||||
*/
|
||||
.bar {
|
||||
background-color:#4D7A97;
|
||||
color:#FFFFFF;
|
||||
padding:.8em .5em .4em .8em;
|
||||
height:auto;/*height:1.8em;*/
|
||||
font-size:11px;
|
||||
margin:0;
|
||||
}
|
||||
.topNav {
|
||||
background-color:#4D7A97;
|
||||
color:#FFFFFF;
|
||||
float:left;
|
||||
padding:0;
|
||||
width:100%;
|
||||
clear:right;
|
||||
height:2.8em;
|
||||
padding-top:10px;
|
||||
overflow:hidden;
|
||||
font-size:12px;
|
||||
}
|
||||
.bottomNav {
|
||||
margin-top:10px;
|
||||
background-color:#4D7A97;
|
||||
color:#FFFFFF;
|
||||
float:left;
|
||||
padding:0;
|
||||
width:100%;
|
||||
clear:right;
|
||||
height:2.8em;
|
||||
padding-top:10px;
|
||||
overflow:hidden;
|
||||
font-size:12px;
|
||||
}
|
||||
.subNav {
|
||||
background-color:#dee3e9;
|
||||
float:left;
|
||||
width:100%;
|
||||
overflow:hidden;
|
||||
font-size:12px;
|
||||
}
|
||||
.subNav div {
|
||||
clear:left;
|
||||
float:left;
|
||||
padding:0 0 5px 6px;
|
||||
text-transform:uppercase;
|
||||
}
|
||||
ul.navList, ul.subNavList {
|
||||
float:left;
|
||||
margin:0 25px 0 0;
|
||||
padding:0;
|
||||
}
|
||||
ul.navList li{
|
||||
list-style:none;
|
||||
float:left;
|
||||
padding: 5px 6px;
|
||||
text-transform:uppercase;
|
||||
}
|
||||
ul.subNavList li{
|
||||
list-style:none;
|
||||
float:left;
|
||||
}
|
||||
.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited {
|
||||
color:#FFFFFF;
|
||||
text-decoration:none;
|
||||
text-transform:uppercase;
|
||||
}
|
||||
.topNav a:hover, .bottomNav a:hover {
|
||||
text-decoration:none;
|
||||
color:#bb7a2a;
|
||||
text-transform:uppercase;
|
||||
}
|
||||
.navBarCell1Rev {
|
||||
background-color:#F8981D;
|
||||
color:#253441;
|
||||
margin: auto 5px;
|
||||
}
|
||||
.skipNav {
|
||||
position:absolute;
|
||||
top:auto;
|
||||
left:-9999px;
|
||||
overflow:hidden;
|
||||
}
|
||||
/*
|
||||
Page header and footer styles
|
||||
*/
|
||||
.header, .footer {
|
||||
clear:both;
|
||||
margin:0 20px;
|
||||
padding:5px 0 0 0;
|
||||
}
|
||||
.indexHeader {
|
||||
margin:10px;
|
||||
position:relative;
|
||||
}
|
||||
.indexHeader span{
|
||||
margin-right:15px;
|
||||
}
|
||||
.indexHeader h1 {
|
||||
font-size:13px;
|
||||
}
|
||||
.title {
|
||||
color:#2c4557;
|
||||
margin:10px 0;
|
||||
}
|
||||
.subTitle {
|
||||
margin:5px 0 0 0;
|
||||
}
|
||||
.header ul {
|
||||
margin:0 0 15px 0;
|
||||
padding:0;
|
||||
}
|
||||
.footer ul {
|
||||
margin:20px 0 5px 0;
|
||||
}
|
||||
.header ul li, .footer ul li {
|
||||
list-style:none;
|
||||
font-size:13px;
|
||||
}
|
||||
/*
|
||||
Heading styles
|
||||
*/
|
||||
div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 {
|
||||
background-color:#dee3e9;
|
||||
border:1px solid #d0d9e0;
|
||||
margin:0 0 6px -8px;
|
||||
padding:7px 5px;
|
||||
}
|
||||
ul.blockList ul.blockList ul.blockList li.blockList h3 {
|
||||
background-color:#dee3e9;
|
||||
border:1px solid #d0d9e0;
|
||||
margin:0 0 6px -8px;
|
||||
padding:7px 5px;
|
||||
}
|
||||
ul.blockList ul.blockList li.blockList h3 {
|
||||
padding:0;
|
||||
margin:15px 0;
|
||||
}
|
||||
ul.blockList li.blockList h2 {
|
||||
padding:0px 0 20px 0;
|
||||
}
|
||||
/*
|
||||
Page layout container styles
|
||||
*/
|
||||
.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer {
|
||||
clear:both;
|
||||
padding:10px 20px;
|
||||
position:relative;
|
||||
}
|
||||
.indexContainer {
|
||||
margin:10px;
|
||||
position:relative;
|
||||
font-size:12px;
|
||||
}
|
||||
.indexContainer h2 {
|
||||
font-size:13px;
|
||||
padding:0 0 3px 0;
|
||||
}
|
||||
.indexContainer ul {
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
.indexContainer ul li {
|
||||
list-style:none;
|
||||
padding-top:2px;
|
||||
}
|
||||
.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt {
|
||||
font-size:12px;
|
||||
font-weight:bold;
|
||||
margin:10px 0 0 0;
|
||||
color:#4E4E4E;
|
||||
}
|
||||
.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd {
|
||||
margin:5px 0 10px 0px;
|
||||
font-size:14px;
|
||||
font-family:'DejaVu Sans Mono',monospace;
|
||||
}
|
||||
.serializedFormContainer dl.nameValue dt {
|
||||
margin-left:1px;
|
||||
font-size:1.1em;
|
||||
display:inline;
|
||||
font-weight:bold;
|
||||
}
|
||||
.serializedFormContainer dl.nameValue dd {
|
||||
margin:0 0 0 1px;
|
||||
font-size:1.1em;
|
||||
display:inline;
|
||||
}
|
||||
/*
|
||||
List styles
|
||||
*/
|
||||
ul.horizontal li {
|
||||
display:inline;
|
||||
font-size:0.9em;
|
||||
}
|
||||
ul.inheritance {
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
ul.inheritance li {
|
||||
display:inline;
|
||||
list-style:none;
|
||||
}
|
||||
ul.inheritance li ul.inheritance {
|
||||
margin-left:15px;
|
||||
padding-left:15px;
|
||||
padding-top:1px;
|
||||
}
|
||||
ul.blockList, ul.blockListLast {
|
||||
margin:10px 0 10px 0;
|
||||
padding:0;
|
||||
}
|
||||
ul.blockList li.blockList, ul.blockListLast li.blockList {
|
||||
list-style:none;
|
||||
margin-bottom:15px;
|
||||
line-height:1.4;
|
||||
}
|
||||
ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList {
|
||||
padding:0px 20px 5px 10px;
|
||||
border:1px solid #ededed;
|
||||
background-color:#f8f8f8;
|
||||
}
|
||||
ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList {
|
||||
padding:0 0 5px 8px;
|
||||
background-color:#ffffff;
|
||||
border:none;
|
||||
}
|
||||
ul.blockList ul.blockList ul.blockList ul.blockList li.blockList {
|
||||
margin-left:0;
|
||||
padding-left:0;
|
||||
padding-bottom:15px;
|
||||
border:none;
|
||||
}
|
||||
ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast {
|
||||
list-style:none;
|
||||
border-bottom:none;
|
||||
padding-bottom:0;
|
||||
}
|
||||
table tr td dl, table tr td dl dt, table tr td dl dd {
|
||||
margin-top:0;
|
||||
margin-bottom:1px;
|
||||
}
|
||||
/*
|
||||
Table styles
|
||||
*/
|
||||
.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary {
|
||||
width:100%;
|
||||
border-left:1px solid #EEE;
|
||||
border-right:1px solid #EEE;
|
||||
border-bottom:1px solid #EEE;
|
||||
}
|
||||
.overviewSummary, .memberSummary {
|
||||
padding:0px;
|
||||
}
|
||||
.overviewSummary caption, .memberSummary caption, .typeSummary caption,
|
||||
.useSummary caption, .constantsSummary caption, .deprecatedSummary caption {
|
||||
position:relative;
|
||||
text-align:left;
|
||||
background-repeat:no-repeat;
|
||||
color:#253441;
|
||||
font-weight:bold;
|
||||
clear:none;
|
||||
overflow:hidden;
|
||||
padding:0px;
|
||||
padding-top:10px;
|
||||
padding-left:1px;
|
||||
margin:0px;
|
||||
white-space:pre;
|
||||
}
|
||||
.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link,
|
||||
.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link,
|
||||
.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover,
|
||||
.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover,
|
||||
.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active,
|
||||
.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active,
|
||||
.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited,
|
||||
.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited {
|
||||
color:#FFFFFF;
|
||||
}
|
||||
.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span,
|
||||
.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span {
|
||||
white-space:nowrap;
|
||||
padding-top:5px;
|
||||
padding-left:12px;
|
||||
padding-right:12px;
|
||||
padding-bottom:7px;
|
||||
display:inline-block;
|
||||
float:left;
|
||||
background-color:#F8981D;
|
||||
border: none;
|
||||
height:16px;
|
||||
}
|
||||
.memberSummary caption span.activeTableTab span {
|
||||
white-space:nowrap;
|
||||
padding-top:5px;
|
||||
padding-left:12px;
|
||||
padding-right:12px;
|
||||
margin-right:3px;
|
||||
display:inline-block;
|
||||
float:left;
|
||||
background-color:#F8981D;
|
||||
height:16px;
|
||||
}
|
||||
.memberSummary caption span.tableTab span {
|
||||
white-space:nowrap;
|
||||
padding-top:5px;
|
||||
padding-left:12px;
|
||||
padding-right:12px;
|
||||
margin-right:3px;
|
||||
display:inline-block;
|
||||
float:left;
|
||||
background-color:#4D7A97;
|
||||
height:16px;
|
||||
}
|
||||
.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab {
|
||||
padding-top:0px;
|
||||
padding-left:0px;
|
||||
padding-right:0px;
|
||||
background-image:none;
|
||||
float:none;
|
||||
display:inline;
|
||||
}
|
||||
.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd,
|
||||
.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd {
|
||||
display:none;
|
||||
width:5px;
|
||||
position:relative;
|
||||
float:left;
|
||||
background-color:#F8981D;
|
||||
}
|
||||
.memberSummary .activeTableTab .tabEnd {
|
||||
display:none;
|
||||
width:5px;
|
||||
margin-right:3px;
|
||||
position:relative;
|
||||
float:left;
|
||||
background-color:#F8981D;
|
||||
}
|
||||
.memberSummary .tableTab .tabEnd {
|
||||
display:none;
|
||||
width:5px;
|
||||
margin-right:3px;
|
||||
position:relative;
|
||||
background-color:#4D7A97;
|
||||
float:left;
|
||||
|
||||
}
|
||||
.overviewSummary td, .memberSummary td, .typeSummary td,
|
||||
.useSummary td, .constantsSummary td, .deprecatedSummary td {
|
||||
text-align:left;
|
||||
padding:0px 0px 12px 10px;
|
||||
}
|
||||
th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th,
|
||||
td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{
|
||||
vertical-align:top;
|
||||
padding-right:0px;
|
||||
padding-top:8px;
|
||||
padding-bottom:3px;
|
||||
}
|
||||
th.colFirst, th.colLast, th.colOne, .constantsSummary th {
|
||||
background:#dee3e9;
|
||||
text-align:left;
|
||||
padding:8px 3px 3px 7px;
|
||||
}
|
||||
td.colFirst, th.colFirst {
|
||||
white-space:nowrap;
|
||||
font-size:13px;
|
||||
}
|
||||
td.colLast, th.colLast {
|
||||
font-size:13px;
|
||||
}
|
||||
td.colOne, th.colOne {
|
||||
font-size:13px;
|
||||
}
|
||||
.overviewSummary td.colFirst, .overviewSummary th.colFirst,
|
||||
.useSummary td.colFirst, .useSummary th.colFirst,
|
||||
.overviewSummary td.colOne, .overviewSummary th.colOne,
|
||||
.memberSummary td.colFirst, .memberSummary th.colFirst,
|
||||
.memberSummary td.colOne, .memberSummary th.colOne,
|
||||
.typeSummary td.colFirst{
|
||||
width:25%;
|
||||
vertical-align:top;
|
||||
}
|
||||
td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover {
|
||||
font-weight:bold;
|
||||
}
|
||||
.tableSubHeadingColor {
|
||||
background-color:#EEEEFF;
|
||||
}
|
||||
.altColor {
|
||||
background-color:#FFFFFF;
|
||||
}
|
||||
.rowColor {
|
||||
background-color:#EEEEEF;
|
||||
}
|
||||
/*
|
||||
Content styles
|
||||
*/
|
||||
.description pre {
|
||||
margin-top:0;
|
||||
}
|
||||
.deprecatedContent {
|
||||
margin:0;
|
||||
padding:10px 0;
|
||||
}
|
||||
.docSummary {
|
||||
padding:0;
|
||||
}
|
||||
|
||||
ul.blockList ul.blockList ul.blockList li.blockList h3 {
|
||||
font-style:normal;
|
||||
}
|
||||
|
||||
div.block {
|
||||
font-size:14px;
|
||||
font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif;
|
||||
}
|
||||
|
||||
td.colLast div {
|
||||
padding-top:0px;
|
||||
}
|
||||
|
||||
|
||||
td.colLast a {
|
||||
padding-bottom:3px;
|
||||
}
|
||||
/*
|
||||
Formatting effect styles
|
||||
*/
|
||||
.sourceLineNo {
|
||||
color:green;
|
||||
padding:0 30px 0 0;
|
||||
}
|
||||
h1.hidden {
|
||||
visibility:hidden;
|
||||
overflow:hidden;
|
||||
font-size:10px;
|
||||
}
|
||||
.block {
|
||||
display:block;
|
||||
margin:3px 10px 2px 0px;
|
||||
color:#474747;
|
||||
}
|
||||
.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink,
|
||||
.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel,
|
||||
.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink {
|
||||
font-weight:bold;
|
||||
}
|
||||
.deprecationComment, .emphasizedPhrase, .interfaceName {
|
||||
font-style:italic;
|
||||
}
|
||||
|
||||
div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase,
|
||||
div.block div.block span.interfaceName {
|
||||
font-style:normal;
|
||||
}
|
||||
|
||||
div.contentContainer ul.blockList li.blockList h2{
|
||||
padding-bottom:0px;
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/recursif.iml" filepath="$PROJECT_DIR$/recursif.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="GENERAL_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,77 @@
|
||||
import java.lang.Math;
|
||||
|
||||
public class ExoArray {
|
||||
public static void main(String[] args) {
|
||||
int[] powers = new int[20], odds = new int[20], alterns = new int[20];
|
||||
for (int i = 0; i < 20; i++) {
|
||||
powers[i] = (int) Math.pow(2, i+1);
|
||||
odds[i] = i * 2 + 1;
|
||||
alterns[i] = (int)Math.pow(-1, i) * i;
|
||||
}
|
||||
display(powers);
|
||||
System.out.println(ordered(powers));
|
||||
display(odds);
|
||||
System.out.println(ordered(odds));
|
||||
display(alterns);
|
||||
System.out.println(ordered(alterns));
|
||||
System.out.printf("%d, %d, %d\n", sum(powers), sum(odds), sum(alterns));
|
||||
System.out.printf("%.2f, %.2f, %.2f\n", average(powers), average(odds), average(alterns));
|
||||
}
|
||||
|
||||
public static void display(int[] in){
|
||||
String dis = "";
|
||||
for(int i: in){
|
||||
dis = dis + i + " ";
|
||||
}
|
||||
System.out.println(dis);
|
||||
}
|
||||
|
||||
public static int sum(int[] in){
|
||||
int sum = 0;
|
||||
for(int i: in){
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static float average(int[] in){
|
||||
return sum(in)/in.length;
|
||||
}
|
||||
|
||||
public static int[] zipSum(int[] in1, int[] in2){
|
||||
if (in1.length != in2.length) // Fail Check
|
||||
return null;
|
||||
|
||||
int[] ret = new int[in1.length];
|
||||
for (int i = 0; i < in1.length; i++) {
|
||||
ret[i] = in1[i] + in2[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static float[] zipAverage(int[] in1, int[] in2){
|
||||
if (in1.length != in2.length) // Fail Check
|
||||
return null;
|
||||
|
||||
float[] ret = new float[in1.length];
|
||||
for (int i = 0; i < in1.length; i++) {
|
||||
ret[i] = in1[i] + in2[i] / 2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static boolean ordered(int[] in){
|
||||
for (int i = 1; i < in.length; i++) {
|
||||
if(in[i] < in[i-1])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static int max(int[] in){
|
||||
int max = 0;
|
||||
for (int i : in) {
|
||||
max = max < i ? i : max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
public class ExoCmd {
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 2){
|
||||
System.out.println("Vous devez entrez au moins 2 arguments (entiers)!");
|
||||
return;
|
||||
}
|
||||
int[] args_int = new int[args.length];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
args_int[i] = Integer.parseInt(args[i]);
|
||||
}
|
||||
System.out.println("Voici les nombres que vous avez entrer:");
|
||||
ExoArray.display(args_int);
|
||||
System.out.printf("Sum: %d; Moyenne: %.2f", ExoArray.sum(args_int), ExoArray.average(args_int));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
#Wed Apr 19 14:36:46 CEST 2023
|
||||
gradle.version=7.4.1
|
||||
Binary file not shown.
Whitespace-only changes.
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ExempleFX</name>
|
||||
<comment>Project ExempleFX created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,13 @@
|
||||
arguments=
|
||||
auto.sync=false
|
||||
build.scans.enabled=false
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=
|
||||
eclipse.preferences.version=1
|
||||
gradle.user.home=
|
||||
java.home=/usr/lib/jvm/java-19-openjdk
|
||||
jvm.arguments=
|
||||
offline.mode=false
|
||||
override.workspace.settings=true
|
||||
show.console.view=true
|
||||
show.executions.view=true
|
||||
@@ -0,0 +1,25 @@
|
||||
plugins {
|
||||
id 'application'
|
||||
id 'org.openjfx.javafxplugin' version '0.0.9'
|
||||
}
|
||||
|
||||
compileJava.options.encoding = "UTF-8"
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
}
|
||||
|
||||
application {
|
||||
// C'est le nom de la classe principale (contenant la méthode main). On
|
||||
// doit donner les packages s'il y en a. Ici, Main est dans le package
|
||||
// exemplefx.
|
||||
mainClass = 'exemplefx.Main'
|
||||
}
|
||||
|
||||
javafx {
|
||||
version = "11"
|
||||
modules = [ 'javafx.controls' ]
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,260 @@
|
||||
package exemplefx;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
// La classe principale pour javafx doit hériter de Application.
|
||||
//
|
||||
// L'objectif de ce programme est d'afficher une forme (cercle ou carré) que
|
||||
// l'on pourra déplacer via des boutons. Commencez par exécuter le code pour
|
||||
// voir ce que ça fait.
|
||||
//
|
||||
// Pour ce faire, ouvrez un terminal dans le dossier contenant le fichier
|
||||
// build.gradle et entrez la commande "gradle run" (sans les guillemets)
|
||||
//
|
||||
// Si vous n'avez pas installé gradle, remplacez gradle dans la commande par
|
||||
// .\gradlew.bat si vous êtes sous windows et ./gradlew si vous êtes sous mac
|
||||
// ou linux.
|
||||
public class Main extends Application {
|
||||
|
||||
private CheckBox drawSquare;
|
||||
private CheckBox blink;
|
||||
private Button up;
|
||||
private Button down;
|
||||
private MonCanvas canvas;
|
||||
private TextField size;
|
||||
private TextField increment;
|
||||
private Timer blinkTimer;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Méthode statique de Application pour lancer le programme
|
||||
launch(args);
|
||||
}
|
||||
|
||||
// Méthode appelée quand on initialise la fenêtre. C'est à partir de là
|
||||
// qu'on va ajouter les boutons et autres.
|
||||
// Stage représente la fenêtre.
|
||||
public void start(Stage stage) {
|
||||
// Il s'agit d'un layout. Un layout est un objet auquel on va ajouter
|
||||
// des éléments (boutons, texte, ...) et qui va gérer comment les
|
||||
// placer sur la fenêtre.
|
||||
// Le BorderPane découpe la zone en cinq : haut, bas, gauche, droite et
|
||||
// centre. Il permet de placer des éléments sur les bords tout en
|
||||
// gardant un maximum de place pour le centre où on peut mettre le
|
||||
// principal. Par exemple, dans un éditeur de texte, on peut avoir les
|
||||
// boutons au dessus et le texte prend la place restante au centre.
|
||||
BorderPane root = new BorderPane();
|
||||
|
||||
// On crée deux boutons
|
||||
up = new Button("Haut");
|
||||
down = new Button("Bas");
|
||||
|
||||
// Une VBox est un autre exemple de layout. Elle va placer les éléments
|
||||
// de haut en bas dans l'ordre où on les ajoute. Pour un placement de
|
||||
// gauche à droite, on utilise une HBox.
|
||||
VBox buttons = new VBox();
|
||||
// On ajoute le bouton up en l'ajoutant aux "enfants" de la VBox. Les
|
||||
// enfants d'un élément sont ceux qui se trouvent à l'intérieur.
|
||||
buttons.getChildren().add(up);
|
||||
buttons.getChildren().add(down);
|
||||
// On peut aussi demander à la VBox de centrer ses composants.
|
||||
buttons.setAlignment(Pos.CENTER);
|
||||
|
||||
// Ici, on place la VBox dans la partie gauche du BorderPane. Cela veut
|
||||
// dire que le BorderPane va juste placer tous les éléments de la VBox
|
||||
// dans la partie gauche de la fenêtre mais c'est la VBox qui va
|
||||
// choisir comment les placer dans cette partie gauche. Ici, de haut en
|
||||
// bas car c'est le principe d'une VBox.
|
||||
root.setLeft(buttons);
|
||||
|
||||
// On crée une check box avec le texte donné.
|
||||
drawSquare = new CheckBox("Dessiner un carré");
|
||||
blink = new CheckBox("Clignoter");
|
||||
|
||||
HBox checks = new HBox(drawSquare, blink);
|
||||
checks.setAlignment(Pos.CENTER);
|
||||
// On place la check box en haut du BorderPane et donc en haut de la
|
||||
// fenêtre comme le BorderPane sera le contenu principal de la fenêtre.
|
||||
root.setTop(checks);
|
||||
|
||||
// Un GridPane est un layout qui place ses éléments sous forme de
|
||||
// grille. On peut y ajouter chaque élément dans une certaine ligne et
|
||||
// une certaine colonne.
|
||||
GridPane texts = new GridPane();
|
||||
// On crée un Label qui correspond à un simple texte. Ce Label sera
|
||||
// placé dans la ligne 0 et la colonne 0 du GridPane. C'est à dire,
|
||||
// dans la case en haut à gauche.
|
||||
texts.add(new Label("Taille de la forme (rayon) :"), 0, 0);
|
||||
// Un TextField permet d'entrer du texte.
|
||||
size = new TextField();
|
||||
// On place le TextField pour la taille de la forme dans la première
|
||||
// ligne et dans la deuxième colonne du GridPane.
|
||||
texts.add(size, 1, 0);
|
||||
texts.add(new Label("Distance du déplacement :"), 0, 1);
|
||||
increment = new TextField();
|
||||
texts.add(increment, 1, 1);
|
||||
texts.setAlignment(Pos.CENTER);
|
||||
|
||||
root.setBottom(texts);
|
||||
|
||||
// On crée un canvas personnalisé (voir MonCanvas.java)
|
||||
canvas = new MonCanvas(800, 600);
|
||||
// Le canvas pourra utiliser toute la place restante au centre. Mais
|
||||
// comme les canvas de JavaFX ont une taille fixe, il ne changera pas
|
||||
// de taille si on change la taille de la fenêtre. Pour cela, il
|
||||
// faudrait modifier notre canvas.
|
||||
root.setCenter(canvas);
|
||||
|
||||
// La scène représente ce qui sera affiché dans la fenêtre.
|
||||
// Une scène à besoin d'un layout. C'est pour ça qu'on lui donne root
|
||||
// qui sera le layout principal.
|
||||
Scene scene = new Scene(root);
|
||||
|
||||
// On configure la scène à afficher.
|
||||
stage.setScene(scene);
|
||||
|
||||
// Cette méthode définie plus bas va configurer tous les éléments qui
|
||||
// doivent réagir à certains évènements. Par exemple, que faire quand
|
||||
// on clique sur un bouton.
|
||||
this.confHandlers(stage);
|
||||
|
||||
// On configure le titre de la fenêtre
|
||||
stage.setTitle("Ma fenêtre");
|
||||
|
||||
// En général, c'est la dernière instruction de start. On dit à javafx
|
||||
// d'afficher la fenêtre (sinon elle ne sera pas visible).
|
||||
stage.show();
|
||||
}
|
||||
|
||||
private void confHandlers(Stage stage) {
|
||||
// Dans une interface graphique, on utilise de la programmation
|
||||
// évènementielle. C'est à dire qu'on va exécuter certaines fonctions
|
||||
// quand un évènement particulier se produit. Par exemple, cliquer sur
|
||||
// un bouton. Le code à exécuter est donné par un objet appelé le
|
||||
// "handler". Une sous-classe de EventHandler pour JavaFX.
|
||||
// Ci-dessous, on crée une classe anonyme qui sera sous-classe de
|
||||
// EventHandler pour les KeyEvent (pour le clavier). Sa méthode handle
|
||||
// va faire monter ou descendre la forme du canvas selon la touche
|
||||
// enfoncée. La syntaxe <KeyEvent> veut juste dire qu'on ne gère que
|
||||
// les KeyEvent. Donc que les touches du clavier et pas, par exemple,
|
||||
// la souris.
|
||||
EventHandler keyhandler = new EventHandler<KeyEvent>() {
|
||||
public void handle(KeyEvent evt) {
|
||||
// Le code est celui de la touche utilisée. Ceux-ci sont
|
||||
// contenus dans la classe KeyCode. KeyCode.UP est le code pour
|
||||
// la flèche du haut.
|
||||
KeyCode code = evt.getCode();
|
||||
if (code == KeyCode.UP) {
|
||||
// Si on a appuyé sur la flèche du haut, on fait monter la
|
||||
// forme dans le canvas.
|
||||
canvas.up();
|
||||
} else if (code == KeyCode.DOWN) {
|
||||
canvas.down();
|
||||
}
|
||||
}
|
||||
};
|
||||
// On ajoute le handler à la fenêtre. On précise bien qu'on ne
|
||||
// s'intéresse que aux évènements KEY_PRESSED qui correspondent à une
|
||||
// touche qui a été enfoncée. Par opposition, KEY_RELEASED correspond à
|
||||
// une touche qui a été relachée.
|
||||
stage.addEventFilter(KeyEvent.KEY_PRESSED, keyhandler);
|
||||
|
||||
// Les handlers peuvent aussi être donnés via une expression lambda. La
|
||||
// fonction doit prendre un évèment en paramètre. Comme ici, up est un
|
||||
// bouton, les détails de l'évènement ne nous intéresse pas car il
|
||||
// s'agit juste d'un clic sur le bouton.
|
||||
//this.up.setOnAction(evt -> this.canvas.up());
|
||||
this.up.setOnAction(evt -> this.canvas.up());
|
||||
this.down.setOnAction(evt -> this.canvas.down());
|
||||
|
||||
// On remarque ici qu'on prend une propriété (selectedProperty). Il
|
||||
// s'agit d'un attribut particulier sur lequel on peut ajouter des
|
||||
// handlers pour gérer les cas où la valeur change. Ici, la propriété
|
||||
// "selected" indique si la checkbox est cochée ou pas.
|
||||
// On ajoute un listener qui est une forme de handler qui gère les cas
|
||||
// où des valeurs changent. On reçoit trois paramètres : l'objet
|
||||
// lui-même (la checkbox), la valeur avant le changement et la valeur
|
||||
// après. Avant et après sont des booléens ici (voir documentation de
|
||||
// CheckBox).
|
||||
this.drawSquare.selectedProperty().addListener(
|
||||
(box, avant, apres) -> {
|
||||
// On n'a pas besoin de la valeur précédente. Juste de la
|
||||
// nouvelle valeur indiquant si la case est cochée (true)
|
||||
// ou pas (false).
|
||||
this.canvas.setDrawSquare(apres);
|
||||
}
|
||||
);
|
||||
// Comme ci-dessus, on ajoute un handler pour mettre à jour la taille
|
||||
// de la forme quand on change la valeur dans le TextField. Sans
|
||||
// surprise, avant et apres sont des String.
|
||||
this.size.textProperty().addListener(
|
||||
(field, avant, apres) -> {
|
||||
try {
|
||||
this.canvas.setSize(Double.parseDouble(apres));
|
||||
} catch (NumberFormatException e) {
|
||||
// Ici, on ignore le problème.
|
||||
// On pourrait afficher un message d'erreur dans une
|
||||
// vraie application ou utiliser une pop-up.
|
||||
}
|
||||
}
|
||||
);
|
||||
this.increment.textProperty().addListener(
|
||||
(observable, avant, apres) -> {
|
||||
try {
|
||||
this.canvas.setIncrement(Double.parseDouble(apres));
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Pour activer ou désactiver le clignotement, on utilise un Timer. La
|
||||
// checkbox blink va donc soit activer le timer toutes les 2 secondes,
|
||||
// soit le désactiver selon qu'elle soit cochée ou pas.
|
||||
this.blinkTimer = new Timer();
|
||||
this.blink.selectedProperty().addListener(
|
||||
(observable, avant, apres) -> {
|
||||
if (!apres) {
|
||||
// Si on vient de décocher blink, on arrête le timer et
|
||||
// on en crée un nouveau qui ne sera pas lancé.
|
||||
blinkTimer.cancel();
|
||||
blinkTimer = new Timer();
|
||||
} else {
|
||||
// Si on vient de cocher blink, on lance le timer après
|
||||
// 2 secondes (2000 ms) et à intervalles de 2 secondes.
|
||||
blinkTimer.scheduleAtFixedRate(new BlinkingTask(canvas), 0, 2000);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Dernier handler, si on ferme la fenêtre, on arrête le timer.
|
||||
stage.setOnCloseRequest(evt -> this.blinkTimer.cancel());
|
||||
}
|
||||
|
||||
private class BlinkingTask extends TimerTask {
|
||||
private MonCanvas canvas;
|
||||
|
||||
public BlinkingTask(MonCanvas c) {
|
||||
this.canvas = c;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.canvas.toggleRed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package exemplefx;
|
||||
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
// Un canvas est un élément d'interface graphique qui permet de dessiner. Nous
|
||||
// créons ici notre propre canvas pour lui ajouter des fonctionnalités
|
||||
// spécifiques. On voudra pouvoir dessiner une forme spécifique à des un
|
||||
// endroit spécifique. Cette forme sera centrée en x mais pourra monter ou
|
||||
// descendre.
|
||||
public class MonCanvas extends Canvas {
|
||||
|
||||
// Coordonnée y de la forme.
|
||||
private double y;
|
||||
// Si drawSquare est vrai, on dessine un carré. Sinon, on dessine un
|
||||
// cercle.
|
||||
private boolean drawSquare;
|
||||
// De combien de pixels ont va déplacer la forme dans les méthodes up et
|
||||
// down.
|
||||
private double increment;
|
||||
// Rayon de la forme.
|
||||
private double size;
|
||||
// Si vrai, on dessine la forme en rouge. Sinon, en bleu.
|
||||
private boolean red;
|
||||
|
||||
public MonCanvas(double width, double height) {
|
||||
super(width, height);
|
||||
// La fonction reset permet de tout remettre à zéro. Mais elle sert
|
||||
// aussi à initialiser. On pourrait imaginer ajouter un bouton reset
|
||||
// dans l'interface. Voyez-vous comment ?
|
||||
reset();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.y = getHeight() / 2;
|
||||
this.drawSquare = false;
|
||||
this.increment = 10;
|
||||
this.size = 100;
|
||||
this.red = false;
|
||||
// Quand on a tout initialisé, on dessine.
|
||||
draw();
|
||||
}
|
||||
|
||||
public void setIncrement(double inc) {
|
||||
this.increment = inc;
|
||||
}
|
||||
|
||||
public void setDrawSquare(boolean drawsq) {
|
||||
this.drawSquare = drawsq;
|
||||
// A chaque fois qu'on change un paramètre, on va redessiner la forme
|
||||
// avec ces changements. On voit ici un exemple où les méthodes set
|
||||
// sont importantes. Ce comportement de redessiner automatiquement ne
|
||||
// serait pas possible si drawSquare était publique.
|
||||
draw();
|
||||
}
|
||||
|
||||
public void setSize(double s) {
|
||||
this.size = s;
|
||||
draw();
|
||||
}
|
||||
|
||||
public void toggleRed() {
|
||||
this.red = !red;
|
||||
draw();
|
||||
}
|
||||
|
||||
public void up() {
|
||||
// Dans un canvas, l'axe y est inversé. Le point (0,0) est en haut à
|
||||
// gauche va vers le bas. Le point en bas à droite sera donc (width,
|
||||
// height) avec width et height la largeur et la hauteur du canvas
|
||||
// respectivement. Pour dessiner la forme plus haut, on va donc
|
||||
// diminuer la valeur y.
|
||||
this.y -= this.increment;
|
||||
draw();
|
||||
}
|
||||
|
||||
public void down() {
|
||||
this.y += this.increment;
|
||||
draw();
|
||||
}
|
||||
|
||||
// Cette méthode va dessiner la forme avec tous les paramètres.
|
||||
private void draw() {
|
||||
// On ne peut pas utiliser directement les attributs width et height de
|
||||
// Canvas car elles sont privées et donc pas accessibles dans notre
|
||||
// sous-classe. On doit donc utiliser getWidth et getHeight.
|
||||
double width = this.getWidth();
|
||||
double height = this.getHeight();
|
||||
// xc est la coordonnée x correspondant au centre du canvas.
|
||||
double xc = width / 2;
|
||||
// Un GraphicsContext est un objet qui permet de dessiner sur un
|
||||
// Canvas. Il possède beaucoup de méthodes spécifiques comme strokeLine
|
||||
// pour dessiner une ligne.
|
||||
GraphicsContext gc = this.getGraphicsContext2D();
|
||||
// La méthode clearRect fonctionne comme une gomme. Il efface tous les
|
||||
// dessins se trouvant à l'intérieur. Sans cela, les dessins
|
||||
// précédents restent affichés. Essayez de commenter cette ligne pour
|
||||
// voir ce que ça donne.
|
||||
gc.clearRect(0, 0, width, height);
|
||||
// On va dessiner un rectangle pour bien voir les limites du canvas.
|
||||
// Vous verrez que sa taille reste constante.
|
||||
gc.strokeRect(1, 1, width-2, height-2);
|
||||
// Selon la valeur de red, on choisis la couleur à utiliser. La méthode
|
||||
// setFill configure la couleur pour le remplissage (l'intérieur des
|
||||
// formes). Pour choisir la couleur des lignes, on utilise setStroke.
|
||||
if (red) {
|
||||
gc.setFill(Color.RED);
|
||||
} else {
|
||||
gc.setFill(Color.BLUE);
|
||||
}
|
||||
// Si vrai, on dessine un carré. Pour cela, la méthode fillRect dessine
|
||||
// un carré et le colore avec la couleur configurée ci-dessus. Sinon,
|
||||
// on dessine un cercle avec fillOval.
|
||||
if (this.drawSquare) {
|
||||
gc.fillRect(xc-size, y-size, 2*size, 2*size);
|
||||
} else {
|
||||
gc.fillOval(xc-size, y-size, 2*size, 2*size);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# Linux start script should use lf
|
||||
/gradlew text eol=lf
|
||||
|
||||
# These are Windows script files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Ignore Gradle project-specific cache directory
|
||||
.gradle
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
Generated
+1
@@ -0,0 +1 @@
|
||||
Spirale
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="19" />
|
||||
</component>
|
||||
</project>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+5
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" project-jdk-name="19" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Spirale</name>
|
||||
<comment>Project Spirale created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,13 @@
|
||||
arguments=
|
||||
auto.sync=false
|
||||
build.scans.enabled=false
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=app
|
||||
eclipse.preferences.version=1
|
||||
gradle.user.home=
|
||||
java.home=/usr/lib/jvm/java-19-openjdk
|
||||
jvm.arguments=
|
||||
offline.mode=false
|
||||
override.workspace.settings=true
|
||||
show.console.view=true
|
||||
show.executions.view=true
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/test" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="test"/>
|
||||
<attribute name="gradle_used_by_scope" value="test"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/test" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="test"/>
|
||||
<attribute name="gradle_used_by_scope" value="test"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-19/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>app</name>
|
||||
<comment>Project app created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,13 @@
|
||||
arguments=
|
||||
auto.sync=false
|
||||
build.scans.enabled=false
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=
|
||||
eclipse.preferences.version=1
|
||||
gradle.user.home=
|
||||
java.home=
|
||||
jvm.arguments=
|
||||
offline.mode=false
|
||||
override.workspace.settings=false
|
||||
show.console.view=false
|
||||
show.executions.view=false
|
||||
@@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=19
|
||||
org.eclipse.jdt.core.compiler.compliance=19
|
||||
org.eclipse.jdt.core.compiler.source=19
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* This generated file contains a sample Java application project to get you started.
|
||||
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
|
||||
* User Manual available at https://docs.gradle.org/8.0.2/userguide/building_java_projects.html
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
id 'application'
|
||||
id 'org.openjfx.javafxplugin' version '0.0.13'
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Use JUnit Jupiter for testing.
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1'
|
||||
|
||||
// This dependency is used by the application.
|
||||
implementation 'com.google.guava:guava:31.1-jre'
|
||||
}
|
||||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass = 'spirale.App'
|
||||
}
|
||||
|
||||
javafx {
|
||||
version = "20"
|
||||
modules = [ 'javafx.controls' ]
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
// Use JUnit Platform for unit tests.
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package spirale;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.paint.*;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.canvas.*;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public class App extends Application {
|
||||
|
||||
private BorderPane root;
|
||||
private Button next;
|
||||
private HBox top;
|
||||
private Generator gen;
|
||||
private Canvas can;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage){
|
||||
final int[] last_pos_x = {400};
|
||||
final int[] last_pos_y = { 400 };
|
||||
final int[] last_pos_state = { 0 };
|
||||
gen = new Fibonacci();
|
||||
can = new Canvas(800,800);
|
||||
GraphicsContext con = can.getGraphicsContext2D();
|
||||
con.setFill(Color.BLUE);
|
||||
|
||||
root = new BorderPane();
|
||||
|
||||
top = new HBox();
|
||||
next = new Button("Next");
|
||||
next.setOnAction((x) -> {
|
||||
int curr = gen.next();
|
||||
System.out.println(curr);
|
||||
int next_pos_x = last_pos_x[0], next_pos_y = last_pos_y[0];
|
||||
switch (last_pos_state[0]) {
|
||||
case 0:
|
||||
next_pos_x = last_pos_x[0];
|
||||
next_pos_y = last_pos_y[0] + curr;
|
||||
break;
|
||||
case 1:
|
||||
next_pos_x = last_pos_x[0] + curr;
|
||||
next_pos_y = last_pos_y[0];
|
||||
break;
|
||||
case 2:
|
||||
next_pos_x = last_pos_x[0];
|
||||
next_pos_y = last_pos_y[0] - curr;
|
||||
break;
|
||||
case 3:
|
||||
next_pos_x = last_pos_x[0] - curr;
|
||||
next_pos_y = last_pos_y[0];
|
||||
break;
|
||||
}
|
||||
last_pos_state[0]++;
|
||||
last_pos_state[0] = last_pos_state[0] % 4;
|
||||
con.strokeLine(last_pos_x[0], last_pos_y[0], next_pos_x, next_pos_y);
|
||||
last_pos_x[0] = next_pos_x;
|
||||
last_pos_y[0] = next_pos_y;
|
||||
});
|
||||
top.getChildren().add(next);
|
||||
top.setAlignment(Pos.CENTER);
|
||||
|
||||
root.setTop(top);
|
||||
root.setCenter(can);
|
||||
|
||||
Scene scene = new Scene(root);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setTitle("Mon paneau");
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package spirale;
|
||||
|
||||
public class Fibonacci implements Generator{
|
||||
private int last1 = 0, last2 = 0;
|
||||
|
||||
public int next(){
|
||||
int tmp = last1 + last2;
|
||||
if(tmp == 0){
|
||||
tmp = 1;
|
||||
}
|
||||
last2 = last1;
|
||||
last1 = tmp;
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package spirale;
|
||||
|
||||
public interface Generator {
|
||||
int next();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package spirale;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class AppTest {
|
||||
@Test void appHasAGreeting() {
|
||||
App classUnderTest = new App();
|
||||
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loaded 100 of 228 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user