Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
templateJavaFX
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
templateJavaFX
Commits
43e98dda
Commit
43e98dda
authored
3 years ago
by
kaller01
Browse files
Options
Downloads
Patches
Plain Diff
init
parents
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
+85
-0
85 additions, 0 deletions
Main.java
with
85 additions
and
0 deletions
Main.java
0 → 100644
+
85
−
0
View file @
43e98dda
import
javafx.application.Application
;
import
javafx.event.ActionEvent
;
import
javafx.event.EventHandler
;
import
javafx.scene.Scene
;
import
javafx.scene.canvas.Canvas
;
import
javafx.scene.canvas.GraphicsContext
;
import
javafx.scene.control.Button
;
import
javafx.scene.control.Label
;
import
javafx.scene.control.TextField
;
import
javafx.scene.layout.Background
;
import
javafx.scene.layout.BackgroundFill
;
import
javafx.scene.layout.HBox
;
import
javafx.scene.layout.VBox
;
import
javafx.scene.paint.Color
;
import
javafx.stage.Stage
;
public
class
Main
extends
Application
{
@Override
public
void
start
(
Stage
primaryStage
)
throws
Exception
{
primaryStage
.
setTitle
(
"JavaFX nodes"
);
// Horizontal box, nodes will stack on x axis
HBox
root
=
new
HBox
();
// Create root element for scene, ex group
root
.
setMinWidth
(
600
);
root
.
setMinHeight
(
600
);
root
.
setSpacing
(
20
);
root
.
setBackground
(
new
Background
(
new
BackgroundFill
(
Color
.
GREEN
,
null
,
null
)));
//Look for a green box
//These are nodes that can be put in a layout, read docs.
TextField
field
=
new
TextField
();
Button
button
=
new
Button
(
"Click me!"
);
//Canvas is special, because you can draw on it.
Canvas
canvas
=
new
Canvas
();
canvas
.
setHeight
(
200
);
canvas
.
setWidth
(
200
);
//Using the graphics context, you can draw. Canvas has x and y coordinates.
GraphicsContext
gc
=
canvas
.
getGraphicsContext2D
();
gc
.
setFill
(
Color
.
BLACK
);
gc
.
fillRect
(
0
,
0
,
canvas
.
getWidth
(),
canvas
.
getHeight
());
//Vertical box, nodes will stack on y axis.
VBox
box
=
new
VBox
();
box
.
setMinHeight
(
300
);
box
.
setMinWidth
(
300
);
box
.
setMaxHeight
(
400
);
box
.
setBackground
(
new
Background
(
new
BackgroundFill
(
Color
.
PINK
,
null
,
null
)));
//Look for a pink box!
// This is a listener, when you press the button this code will execute
button
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
actionEvent
)
{
String
text
=
field
.
getText
();
Label
label
=
new
Label
(
text
);
box
.
getChildren
().
add
(
label
);
field
.
setText
(
""
);
//Special case, try it
if
(
text
.
equals
(
"TDDC77"
)){
gc
.
setFill
(
Color
.
LIGHTBLUE
);
gc
.
fillOval
(
50
,
50
,
100
,
100
);
}
}
});
Scene
scene
=
new
Scene
(
root
);
// Create the scene with root element
primaryStage
.
setScene
(
scene
);
root
.
getChildren
().
add
(
field
);
//put field in green box
root
.
getChildren
().
add
(
button
);
//put button in green box
root
.
getChildren
().
add
(
box
);
//put pink box in green box
root
.
getChildren
().
add
(
canvas
);
//put canvas in green box
box
.
getChildren
().
add
(
new
Label
(
"Hello world"
));
//put label in pink box
//Last thing to do is show
primaryStage
.
show
();
}
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