Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider d304771e rédigé par jacquin-c's avatar jacquin-c
Parcourir les fichiers

first commit

parent
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 688 ajouts et 0 suppression
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.6.10"
id("org.openjfx.javafxplugin") version "0.0.13"
application
}
group = "jacquin-c"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
implementation("org.controlsfx:controlsfx:11.1.2")
}
javafx {
version = "19"
modules("javafx.controls", "javafx.fxml")
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
/*application {
mainClass.set("ihm/td1/TP1_1Kt")
}
*/
kotlin.code.style=official
Fichier ajouté
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#!/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 \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# 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" "$@"
@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% equ 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% equ 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!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
image/calculatrice.png

13,7 ko

image/exo2.png

8,36 ko

@startuml
hide circle
skinparam monochrome true
skinparam classAttributeIconSize 0
skinparam backgroundcolor transparent
'skinparam groupInheritance 2
class Modele {
+ operande1: Int
+ operande2: Int
+ operateur: String
+ <<create>> Model()
+ additionner(): Int
+ soustraire(): Int
+ multiplier(): Int
+ diviser(): Double
}
@enduml
image/td4.png

6,4 ko

# TD4: premiers exercices MVC
## Exercice 1
Nous allons développer une calculatrice en suivant l'architecture MVC (Modéle - Vue - Contrôleur).
Cette calculatrice ne permet que de réaliser les opérations **binaires** *+*, *-*, * , */*.
Au départ, nous ne gérerons pas les erreurs éventuelles qui pourront se présenter. Elles seront prises en compte dans un second temps.
Le répertoire de travail est *calculatriceMVC*
La vue vous est fournie dans le répertoire *vue* => classe *Vue*
<p align="center">
<img src="image/calculatrice.png" />
</p>
### 1) affichage de la vue sans interaction avec l'utilisateur
- compléter le code de la classe *Calculatrice* qui peut être considérée comme le contrôleur principal de l'application pour simplement afficher la vue.
### 2) développement du modèle de l'application
- implémenter le classe UML ci-dessous dans le répertoire *modele*
<p align="center">
<img src="image/td4.png" />
</p>
- créer une instance du modèle dans le contrôleur principal
### 3) mise en place de la fonctionnalité "saisie d'un nombre dans le *textField*"
- développer le contrôleur *ControleurBoutonChiffre* qui permet d'ajouter à la suite dans le *textField* la valeur du label du bouton sur lequel l'utilisateur a cliqué
(si on appuie sur *1*, on aura la valeur *1* affichée dans le *textField*, puis si on appuie maintenant sur *3*, on aura *13* affiché dans le textField ...)
- développer la méthode *fixeControleurBoutonChiffre()* qui permet d'associer le contrôleur développé précédemment aux boutons de la vue qui concernent les chiffres.
- dans le contrôleur principal, faire l'association entre le contrôleur *ControleurBoutonChiffre* et les boutons concernés.
- tester
### 4) appui sur un bouton de type opérateur
Lorsqu'on appuie sur un bouton de type opérateur:
- la chaine représentant l'opérateur et le nombre dans le *textField* sont stockés dans le modèle
- l'opérateur s'affiche après le premier nombre dans le *textField* (par exemple "345 +")
Développer le contrôleur *ControleurOperation*, la méthode *fixeControleurBoutonOperation(...)* et faire l'association contrôleur-vue dans le contrôleur principal
### 5) appui sur la touche "="
Le résultat est calculé et s'affiche comme suit: "12 + 13 = 25"
(mettre à jour le modèle et réaliser l'affichage dans le *textField*
### 6) appui sur la touche "C"
L'appui sur cette touche permet de remettre dans leur état initial le modèle et la vue.
### 7) gestion des erreurs
Maintenant que vous avez une calculatrice fonctionnelle, gérer les différentes erreurs qui peuvent se produire lors de l'appui sur les différents boutons.
Tout ceci se passe dans les contrôleurs.
## II) EXERCICE 2
Le but de cet exercice est de développer une application de type calendrier qui sera initialisée au départ à la date du jour
=> répertoire *calendrierMVC*
Lorsqu'un utilisateur choisira un mois dans la comboBox, la date sera modifiée.
Lorsque l'utilisateur appuiera sur la touche *LEFT* de son clavier, le calendrier reculera d'un jour et sur la touche *RIGHT* le calendrier avancera d'un jour.
<p align="center">
<img src="image/exo2.png" />
</p>
### 1) le modèle (classe *Calendrier* dans modele)
Regardez la classe *Calendrier* fournie qui sera utilisée. Elle encapsule
la classe *Calendar* qui est une classe *java* qui représente un calendrier.
Les méthodes de la classe Calendrier permettent par exemple:
- de récupérer des informations concernant la date actuelle du calendrier (le numéro du jour dans le mois, le numéro du mois ...)
- d'ajouter un mois ou un jour à la date actuelle du calendrier
Pour information les méthodes de cette classe utilisent celles de la classe *Calendar* dont vous avez quelques exemples d'utilisation dans le tableau ci-dessous
| Utilisation méthode get | Résultat |
|----------------------------|---------------------------------------------|
| get(Calendar.DAY_OF_WEEK) | 1 (Calendar.SUNDAY) à 7 (Calendar.SATURDAY) |
| get(Calendar.YEAR) | année |
| get(Calendar.MONTH) | 0 (Calendar.JANUARY) à 11 (Calendar.DECEMBER) |
| get(Calendar.DAY_OF_MONTH) | 1 à 31 |
| get(Calendar.DATE) | 1 to 31 |
Vous n'aurez pas à manipuler directement la classe *Calendar* mais *Calendrier*.
### 2) développement de la méthode *update()* dans la vue
Cette méthode permet la mise à jour de la vue lors d'une modification de date.
### 3) affichage de la vue
Il faudra, au lancement de l’application, que le calendrier affiche la date du jour.
> ajout dans Main.kt
### 4) Modification de la date via un appui de touche
Lorsqu’on appuie sur les touches *LEFT* ou *RIGHT* du clavier la date avance ou recule d’un jour. Il faut bien sûr que soit géré le changement de jour, de mois et d’année.
> - modification à réaliser dans ControleurTouche
> - développement d'une méthode dans la vue pour associer le contrôleur à la vue
> - association du contrôleur à la vue dans Main
### 4) Modification du mois dans la comboBox
Quand on sélectionne un mois dans la *comboBox* alors le jour s’adapte. Dans l’exemple de la capture d’écran vue plus haut, si on sélectionne *mai*, le jour devient *jeudi*.
> - modification à réaliser dans ControleurComboBox
> - développement d'une méthode dans la vue pour associer le contrôleur à la vue
> - association du contrôleur à la vue dans Main
/*rootProject.name = "TD1"
*/
package ihm.td4.calculatriceMVC
import javafx.application.Application
import javafx.stage.Stage
class Calculatrice: Application(){
override fun start(primaryStage: Stage) {
TODO()
}
}
fun main(){
Application.launch(Calculatrice::class.java)
}
\ No newline at end of file
package ihm.td4.calculatriceMVC.controleur
class ControleurBoutonChiffre{
// TODO
}
\ No newline at end of file
package ihm.td4.calculatriceMVC.controleur
class ControleurEfface{
// TODO
}
package ihm.td4.calculatriceMVC.controleur
class ControleurOperation{
// TODO
}
\ No newline at end of file
package ihm.td4.calculatriceMVC.controleur
class ControleurResultat{
// TODO
}
package ihm.td4.calculatriceMVC.modele
class Modele {
// TODO
}
\ No newline at end of file
package ihm.td4.calculatriceMVC.vue
import javafx.event.ActionEvent
import javafx.event.EventHandler
import javafx.geometry.Insets
import javafx.scene.control.Button
import javafx.scene.control.TextField
import javafx.scene.layout.ColumnConstraints
import javafx.scene.layout.GridPane
import javafx.scene.layout.RowConstraints
import javafx.scene.paint.Color
class Vue: GridPane() {
private val textField: TextField
private val tabButton: ArrayList<Button>
init {
val labelsBouton = arrayOf("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "+", "*", "/", "=", "C")
this.textField = TextField("")
this.textField.setPrefSize(10.0, 50.0)
this.tabButton = ArrayList<Button>(14)
// création des boutons de la calculatrice
for (i in 0..labelsBouton.size - 1) {
val button = Button(labelsBouton[i])
button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE)
button.textFill= Color.BLUEVIOLET
this.tabButton.add(button)
}
// ajout des boutons dans le gridpane
this.add(textField, 0, 0, 4, 1)
this.addRow(1,tabButton[7], tabButton[8], tabButton[9],tabButton[10] )
this.addRow(2,tabButton[4], tabButton[5], tabButton[6],tabButton[11] )
this.addRow(3,tabButton[1], tabButton[2], tabButton[3],tabButton[12] )
this.addRow(4,tabButton[0], tabButton[13], tabButton[14],tabButton[15] )
// mise en place des contraintes sur les lignes et colonnes du gridpane
val columnConstraint = ColumnConstraints()
columnConstraint.percentWidth = 25.00
val rowConstraint = RowConstraints()
rowConstraint.percentHeight = 25.00
val tabColumnConstraints= Array(4){columnConstraint}
this.columnConstraints.addAll(tabColumnConstraints)
val tabRowConstraints= Array(5){rowConstraint}
this.rowConstraints.addAll(tabRowConstraints)
this.vgap=10.0
this.hgap=10.0
this.padding= Insets(10.0)
this.style="-fx-background-color: lightblue"
}
// pour valuer le texte de TextField
fun setTexte(s: String){
this.textField.text=s
}
// pour récupérer le texte de textField
fun getTexte():String=this.textField.text
// pour concaténer s au texte de textField
fun ajoutTexte(s: String){
this.textField.text+=s
}
fun fixeControleurBoutonOperation() {
TODO()
}
fun fixeControleurBoutonChiffre() {
TODO()
}
// concerne le bouton =
fun fixeControleurBoutonResultat() {
TODO()
}
// concerne le bouton C
fun fixeControleurBoutonEfface() {
TODO()
}
}
\ No newline at end of file
package ihm.td4.calendrierMVC
import javafx.application.Application
import javafx.stage.Stage
class Main: Application() {
override fun start(primaryStage: Stage) {
TODO()
}
}
fun main(){
Application.launch(Main::class.java)
}
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter