Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CanvasTemplateJavaFX
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Kaller
CanvasTemplateJavaFX
Commits
57e71213
Commit
57e71213
authored
3 years ago
by
kaller01
Browse files
Options
Downloads
Patches
Plain Diff
init
parent
0a13947a
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
Main.java
+57
-57
57 additions, 57 deletions
Main.java
with
57 additions
and
57 deletions
Main.java
+
57
−
57
View file @
57e71213
import
javafx.animation.KeyFrame
;
import
javafx.animation.Timeline
;
import
javafx.application.Application
;
import
javafx.scene.Scene
;
import
javafx.stage.Stage
;
import
javafx.util.Duration
;
import
java.util.HashSet
;
public
class
Main
extends
Application
{
public
static
final
double
WIDTH
=
1600
;
public
static
final
double
HEIGHT
=
800
;
public
static
final
int
FRAMES_PER_SECOND
=
60
;
private
static
final
int
MILLISECOND_DELAY
=
1000
/
FRAMES_PER_SECOND
;
private
static
final
double
SECOND_DELAY
=
1.0
/
FRAMES_PER_SECOND
;
private
HashSet
<
String
>
currentlyActiveKeys
=
new
HashSet
<>();
private
App
app
;
@Override
public
void
start
(
Stage
primaryStage
)
throws
Exception
{
primaryStage
.
setTitle
(
"JavaFX canvas"
);
app
=
new
App
(
primaryStage
);
// timeline and fps
KeyFrame
frame
=
new
KeyFrame
(
Duration
.
millis
(
MILLISECOND_DELAY
),
e
->
{
app
.
update
(
SECOND_DELAY
);
});
Timeline
animation
=
new
Timeline
();
animation
.
setCycleCount
(
Timeline
.
INDEFINITE
);
animation
.
getKeyFrames
().
add
(
frame
);
animation
.
play
();
// Listeners
keyListener
(
app
.
getScene
());
}
public
void
keyListener
(
Scene
scene
)
{
scene
.
setOnKeyPressed
(
event
->
{
String
codeString
=
event
.
getCode
().
toString
();
if
(!
currentlyActiveKeys
.
contains
(
codeString
))
{
currentlyActiveKeys
.
add
(
codeString
);
System
.
out
.
println
(
currentlyActiveKeys
);
app
.
update
(
currentlyActiveKeys
);
}
});
scene
.
setOnKeyReleased
(
event
->
{
currentlyActiveKeys
.
remove
(
event
.
getCode
().
toString
());
app
.
update
(
currentlyActiveKeys
);
});
}
public
static
void
main
(
String
[]
args
)
{
launch
(
args
);
}
}
import
javafx.animation.KeyFrame
;
import
javafx.animation.Timeline
;
import
javafx.application.Application
;
import
javafx.scene.Scene
;
import
javafx.stage.Stage
;
import
javafx.util.Duration
;
import
java.util.HashSet
;
public
class
Main
extends
Application
{
public
static
final
double
WIDTH
=
1600
;
public
static
final
double
HEIGHT
=
800
;
public
static
final
int
FRAMES_PER_SECOND
=
60
;
private
static
final
int
MILLISECOND_DELAY
=
1000
/
FRAMES_PER_SECOND
;
private
static
final
double
SECOND_DELAY
=
1.0
/
FRAMES_PER_SECOND
;
private
HashSet
<
String
>
currentlyActiveKeys
=
new
HashSet
<>();
private
App
app
;
@Override
public
void
start
(
Stage
primaryStage
)
throws
Exception
{
primaryStage
.
setTitle
(
"JavaFX canvas"
);
app
=
new
App
(
primaryStage
);
// timeline and fps
KeyFrame
frame
=
new
KeyFrame
(
Duration
.
millis
(
MILLISECOND_DELAY
),
e
->
{
app
.
update
(
SECOND_DELAY
);
});
Timeline
animation
=
new
Timeline
();
animation
.
setCycleCount
(
Timeline
.
INDEFINITE
);
animation
.
getKeyFrames
().
add
(
frame
);
animation
.
play
();
// Listeners
keyListener
(
app
.
getScene
());
}
public
void
keyListener
(
Scene
scene
)
{
scene
.
setOnKeyPressed
(
event
->
{
String
codeString
=
event
.
getCode
().
toString
();
if
(!
currentlyActiveKeys
.
contains
(
codeString
))
{
currentlyActiveKeys
.
add
(
codeString
);
System
.
out
.
println
(
currentlyActiveKeys
);
app
.
update
(
currentlyActiveKeys
);
}
});
scene
.
setOnKeyReleased
(
event
->
{
currentlyActiveKeys
.
remove
(
event
.
getCode
().
toString
());
app
.
update
(
currentlyActiveKeys
);
});
}
public
static
void
main
(
String
[]
args
)
{
launch
(
args
);
}
}
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