Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Mathdoku
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
tmp1u19
Mathdoku
Commits
cc87648b
Commit
cc87648b
authored
5 years ago
by
tmp1u19
Browse files
Options
Downloads
Patches
Plain Diff
Memorise values from cells with an event handler
parent
eb1d03b8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Mathdoku.java
+57
-9
57 additions, 9 deletions
Mathdoku.java
with
57 additions
and
9 deletions
Mathdoku.java
+
57
−
9
View file @
cc87648b
import
javafx.application.Application
;
import
javafx.event.ActionEvent
;
import
javafx.event.EventHandler
;
import
javafx.geometry.Insets
;
import
javafx.geometry.Pos
;
import
javafx.scene.Scene
;
...
...
@@ -12,13 +14,15 @@ import javafx.stage.Stage;
import
javafx.scene.control.Label
;
public
class
Ma
in
extends
Application
{
public
class
Ma
thdoku
extends
Application
{
private
GridPane
grid
=
new
GridPane
();
private
VBox
menu
=
new
VBox
();
private
HBox
topButton
=
new
HBox
();
private
HBox
bottomButton
=
new
HBox
();
private
int
n
=
2
;
private
int
n
=
4
;
private
Cell
[][]
cells
;
private
int
[][]
values
;
public
static
void
main
(
String
[]
args
)
{
launch
(
args
);
...
...
@@ -49,15 +53,18 @@ public class Main extends Application {
//bottomButton.getChildren().addAll(clear, fileLoad, textLoad);
draw
();
retainValues
();
primaryStage
.
widthProperty
().
addListener
((
obs
,
oldVal
,
newVal
)
->
{
//menu.setPrefWidth((Double) newVal);
//draw();
draw
();
drawInput
();
});
primaryStage
.
heightProperty
().
addListener
((
obs
,
oldVal
,
newVal
)
->
{
//menu.setPrefHeight((Double) newVal);
//draw();
draw
();
drawInput
();
});
menu
.
getChildren
().
addAll
(
topButton
,
grid
);
...
...
@@ -73,16 +80,50 @@ public class Main extends Application {
}
public
void
draw
()
{
cells
=
new
Cell
[
n
][
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
for
(
int
j
=
0
;
j
<
n
;
j
++)
{
Cell
cell
=
new
Cell
(
"5"
);
Cell
cell
=
new
Cell
(
""
);
cell
.
setTranslateX
(
j
*(
600
/
n
));
cell
.
setTranslateY
(
i
*(
600
/
n
));
cells
[
i
][
j
]
=
cell
;
grid
.
getChildren
().
add
(
cell
);
}
}
}
public
void
drawInput
()
{
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
for
(
int
j
=
0
;
j
<
n
;
j
++)
{
if
(
values
[
i
][
j
]
!=
0
)
{
cells
[
i
][
j
].
setText
(
String
.
valueOf
(
values
[
i
][
j
]));
}
}
}
}
public
void
retainValues
()
{
values
=
new
int
[
n
][
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
for
(
int
j
=
0
;
j
<
n
;
j
++)
{
int
finalI
=
i
;
int
finalJ
=
j
;
cells
[
i
][
j
].
getText
().
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
actionEvent
)
{
values
[
finalI
][
finalJ
]
=
Integer
.
parseInt
(
cells
[
finalI
][
finalJ
].
getText
().
getText
());
}
});
}
}
}
class
Cell
extends
StackPane
{
private
Label
label
;
...
...
@@ -93,6 +134,9 @@ public class Main extends Application {
this
.
label
=
new
Label
(
label
);
this
.
text
=
new
TextField
();
this
.
label
.
setFont
(
Font
.
font
(
20
));
//this.label.setAlignment(Pos.TOP_LEFT);
text
.
setPrefWidth
(
10
);
text
.
setFont
(
Font
.
font
(
35
));
text
.
setStyle
(
"-fx-text-box-border: transparent; -fx-background-color: transparent;"
);
...
...
@@ -102,17 +146,21 @@ public class Main extends Application {
rectangle
.
setFill
(
null
);
rectangle
.
setStroke
(
Color
.
BLACK
);
setAlignment
(
Pos
.
CENTER
);
setPadding
(
new
Insets
(
40
));
getChildren
().
addAll
(
rectangle
,
this
.
text
);
getChildren
().
addAll
(
rectangle
,
this
.
text
,
this
.
label
);
}
public
String
getLabel
()
{
return
this
.
label
.
getText
();
}
public
String
getText
()
{
return
text
.
getText
();
public
TextField
getText
()
{
return
this
.
text
;
}
public
void
setText
(
String
text
)
{
this
.
text
.
setText
(
text
);
}
}
...
...
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