Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
1
1_HANOUCHE_MOHAMED_2_BLAISEKAPLANSKI_TEO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
POUYE Alassane
1_HANOUCHE_MOHAMED_2_BLAISEKAPLANSKI_TEO
Commits
8d65438d
Commit
8d65438d
authored
4 years ago
by
Alexis Nasr
Browse files
Options
Downloads
Patches
Plain Diff
ajout de tp2
parent
b9bfe82c
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
tp2/Crossword.java
+86
-0
86 additions, 0 deletions
tp2/Crossword.java
tp2/CrosswordGUI.java
+100
-0
100 additions, 0 deletions
tp2/CrosswordGUI.java
tp2/Main.java
+25
-0
25 additions, 0 deletions
tp2/Main.java
tp2/WORDS.txt
+10
-0
10 additions, 0 deletions
tp2/WORDS.txt
with
221 additions
and
0 deletions
tp2/Crossword.java
0 → 100644
+
86
−
0
View file @
8d65438d
import
java.util.Scanner
;
import
java.io.*
;
/**
* Class Crossword : Creates a 2D array of characters read from the input file
*/
public
class
Crossword
{
private
char
array
[][];
// Tableaux 2D contenant les caractères
private
int
rows
;
// Nombres de lignes de array
private
int
columns
;
// Nombres de colonnes de array
private
int
WordCount
;
// Nombre d'occurences d'un mot
private
int
PositionX
;
// Colonne de début du mot
private
int
PositionY
;
// Ligne de début du mot
private
int
EndX
;
// Colonne de fin du mot
private
int
EndY
;
// Ligne de fin du mot
/*** Constructor: Reads each line from File <file> and writes to a new row in the array.
** Updates <rows> and <columns> to height and width of the array. */
public
Crossword
(
File
file
)
throws
IOException
{
// Code pour calculer la taille du tableau et initialiser les variables d'instance "rows" et "columns"
// Code pour créer le tableau "array"
// Code pour remplir "array" avec les caractères du Fichier "file"
}
/*** Methode Search(String) : Trouver le premier occurence du mot <word> dans le Tableau
*** Si touver, mettre à jour les valeurs (PositionY, PositionX, EndY, EndX)*/
public
boolean
search
(
String
word
)
{
// Verifier que le taile du mot "word" est supérieure à zero. Sinon rien à faire.
// Chercher le premier caractère du mot "word" dans le tableau array.
// Si array[i][j] contient ce caractère, alors le mot peut apparaître dans le même ligne,
// ou dans le même colonne. Utiliser les methodes SearchRow() ou searchColumn() selon le cas.
return
false
;
// mot pas trouvé
}
/* Methode Interne SearchRow(int,int, String) : Cherche une ligne du tableaux pour le mot <word> à partir de array[y][x] */
private
boolean
searchRow
(
int
y
,
int
x
,
String
word
)
{
// Ecrire code ici ...
return
false
;
}
/* Methode Interne SearchRow(int,int, String) : Cherche une colonne du tableaux pour le mot <word> à partir de array[y][x] */
private
boolean
searchColumn
(
int
y
,
int
x
,
String
word
)
{
// Ecrire code ici ...
return
false
;
}
/*** Methode pour visualiser le tableau. (Déjà fourni) */
public
void
display
()
{
if
(
rows
>
0
&&
columns
>
0
)
CrosswordGUI
.
display
(
array
);
else
System
.
out
.
println
(
"Error: Array is Empty."
);
}
/*** Methode pour visualiser le tableau avec le mot en surbrillance. (Déjà fourni) */
public
void
displayWord
()
{
if
((
PositionX
<
0
)
||
(
PositionX
>
EndX
)
||
(
EndX
>=
columns
))
{
System
.
out
.
println
(
"Error: Incorrect x-coordinates for Word"
);
return
;
}
if
((
PositionY
<
0
)
||
(
PositionY
>
EndY
)
||
(
EndY
>=
rows
))
{
System
.
out
.
println
(
"Error: Incorrect y-coordinates for Word"
);
return
;
}
CrosswordGUI
.
display
(
array
,
PositionY
,
PositionX
,
EndY
,
EndX
);
}
}
This diff is collapsed.
Click to expand it.
tp2/CrosswordGUI.java
0 → 100644
+
100
−
0
View file @
8d65438d
/**
* Classe pour visualiser le tableau "Crossword"
* ATTENTION: NE PAS MODIFIER CETTE CLASSE
**/
import
java.awt.BorderLayout
;
import
java.awt.Color
;
import
java.awt.FlowLayout
;
import
java.awt.GridLayout
;
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
import
javax.swing.JLabel
;
import
javax.swing.JPanel
;
import
javax.swing.JTextField
;
import
javax.swing.SwingUtilities
;
public
class
CrosswordGUI
{
public
enum
Directions
{
HORIZONTAL
,
VERTICAL
};
public
static
void
display
(
char
array
[][])
{
final
CrosswordPanel
panel
=
new
CrosswordPanel
(
array
);
displayPanel
(
panel
);
}
public
static
void
display
(
char
array
[][],
int
y1
,
int
x1
,
int
y2
,
int
x2
)
{
final
CrosswordPanel
panel
=
new
CrosswordPanel
(
array
);
if
(
y1
==
y2
&&
x1
<=
x2
)
panel
.
highlight
(
y1
,
x1
,
1
+
x2
-
x1
,
CrosswordGUI
.
Directions
.
HORIZONTAL
);
if
(
x1
==
x2
&&
y1
<=
y2
)
panel
.
highlight
(
y1
,
x1
,
1
+
y2
-
y1
,
CrosswordGUI
.
Directions
.
VERTICAL
);
displayPanel
(
panel
);
}
private
static
void
displayPanel
(
CrosswordPanel
panel
)
{
JFrame
f
=
new
JFrame
();
f
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
f
.
getContentPane
().
setLayout
(
new
BorderLayout
());
JPanel
container
=
new
JPanel
(
new
FlowLayout
());
container
.
add
(
panel
);
f
.
getContentPane
().
add
(
container
,
BorderLayout
.
CENTER
);
f
.
setSize
(
800
,
800
);
f
.
setLocationRelativeTo
(
null
);
f
.
setVisible
(
true
);
}
}
class
CrosswordPanel
extends
JPanel
{
private
JTextField
textFields
[][];
public
CrosswordPanel
(
char
array
[][])
{
int
height
=
array
.
length
;
int
width
=
array
[
0
].
length
;
setLayout
(
new
GridLayout
(
height
,
width
));
textFields
=
new
JTextField
[
height
][
width
];
for
(
int
y
=
0
;
y
<
height
;
y
++)
{
for
(
int
x
=
0
;
x
<
width
;
x
++)
{
char
c
=
array
[
y
][
x
];
if
(
c
!=
0
)
{
textFields
[
y
][
x
]
=
new
JTextField
(
String
.
valueOf
(
c
));
textFields
[
y
][
x
].
setFont
(
textFields
[
y
][
x
].
getFont
().
deriveFont
(
20.0f
));
add
(
textFields
[
y
][
x
]);
}
else
{
add
(
new
JLabel
());
}
}
}
repaint
();
}
public
void
highlight
(
int
startY
,
int
startX
,
int
length
,
CrosswordGUI
.
Directions
dir
)
{
int
endY
=
startY
+
1
;
int
endX
=
startX
+
1
;
if
(
dir
==
CrosswordGUI
.
Directions
.
HORIZONTAL
)
endX
+=
(
length
-
1
);
else
endY
+=
(
length
-
1
);
for
(
int
y
=
startY
;
y
<
endY
;
y
++)
for
(
int
x
=
startX
;
x
<
endX
;
x
++)
{
textFields
[
y
][
x
].
setBackground
(
Color
.
yellow
);
}
repaint
();
}
}
This diff is collapsed.
Click to expand it.
tp2/Main.java
0 → 100644
+
25
−
0
View file @
8d65438d
import
java.io.*
;
import
java.util.Scanner
;
/*** Methode Main : Lire le fichier donné et créer un tableau 2D qui contint le characters du fichier.
*** Demander un mot d'utilisateur et le chercher dans le tableau
*** Visualiser the tableau avec le mot trouver ou informer l'utilisatuer si le mot n'est pas present */
public
class
Main
{
public
static
void
main
(
String
args
[])
throws
IOException
{
String
filename
;
// Demander le nom de Fichier à l'utisateur
// Constriure une instance de la classe "Crossword"
// Crossword tableau = ...
//tableau.display();
// Demander un mot à chercher ...
// Utiliser la méthode Crossword.search() pour chercher le mot
// Ecrire un message sur le terminal pour informer l'utilisateur du resultat.
}
}
This diff is collapsed.
Click to expand it.
tp2/WORDS.txt
0 → 100644
+
10
−
0
View file @
8d65438d
KSHFJGIVCBVN
ASDVKNADLDSS
MANASVADFERT
UMARSEILLEOA
WATERXXHOTID
POKBSEEYOURE
RRRQUOI?SDFG
KARAMBALOOKR
PLOCKDLROOFJ
MNMSIURGNIPD
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment