File tree Expand file tree Collapse file tree
muratagenc/MyJavaFXStudies Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ javadoc.splitindex=true
5454javadoc.use =true
5555javadoc.version =false
5656javadoc.windowtitle =
57- main.class =a_hello_world.HelloWorld
57+ main.class =a_stage_button_event.FirstApp
5858manifest.file =manifest.mf
5959meta.inf.dir =${src.dir}/META-INF
6060mkdist.disabled =false
Original file line number Diff line number Diff line change 1- package a_hello_world ;
1+ package a_stage_button_event ;
22
33import javafx .application .*;
4+ import javafx .event .ActionEvent ;
5+ import javafx .event .EventHandler ;
46import javafx .scene .*;
57import javafx .scene .control .Button ;
68import javafx .scene .layout .StackPane ;
79import javafx .stage .*;
810
9- public class HelloWorld extends Application {
11+ public class FirstApp extends Application implements EventHandler < ActionEvent > {
1012
1113 Button button ;
1214
@@ -21,7 +23,9 @@ public void start (Stage primaryStage) throws Exception{
2123
2224 primaryStage .setTitle ("Hello World" );
2325
24- button = new Button ("Click me" );
26+ button = new Button ();
27+ button .setText ("Click me" );
28+ button .setOnAction (this );
2529
2630 StackPane layout = new StackPane ();
2731 layout .getChildren ().add (button );
@@ -31,4 +35,11 @@ public void start (Stage primaryStage) throws Exception{
3135 primaryStage .show ();
3236
3337 }
38+
39+ @ Override
40+ public void handle (ActionEvent event ){
41+ if (event .getSource () == button ){
42+ System .out .println ("Hello World" );
43+ }
44+ }
3445}
Original file line number Diff line number Diff line change 1+ package b_innerclass_lambda ;
2+
3+ import javafx .application .Application ;
4+ import javafx .event .ActionEvent ;
5+ import javafx .event .EventHandler ;
6+ import javafx .scene .Scene ;
7+ import javafx .scene .control .Button ;
8+ import javafx .scene .layout .StackPane ;
9+ import javafx .stage .Stage ;
10+
11+ public class InnerClass extends Application {
12+
13+ Button button ;
14+
15+ public static void main (String []args ){
16+ launch (args );
17+ }
18+
19+ public void start (Stage primaryStage ){
20+ primaryStage .setTitle ("Inner Class and Lambdas" );
21+ button = new Button ();
22+ button .setText ("Click Me" );
23+
24+ //you don't have to check multiple resources
25+ //with anonymous classes, since they are already
26+ //implemented for a specific object
27+ //downside: needs to be implemented for each
28+ //object..
29+ button .setOnAction (new EventHandler <ActionEvent >(){
30+
31+ @ Override
32+ public void handle (ActionEvent event ){
33+ System .out .println ("I am anonymous class" );
34+ }
35+ });
36+
37+ StackPane layout = new StackPane ();
38+ layout .getChildren ().add (button );
39+ Scene scene = new Scene (layout , 300 , 250 );
40+ primaryStage .setScene (scene );
41+ primaryStage .show ();
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ package c_lambdas_intro ;
2+
3+ import javafx .application .Application ;
4+ import static javafx .application .Application .launch ;
5+ import javafx .scene .Scene ;
6+ import javafx .scene .control .Button ;
7+ import javafx .scene .layout .StackPane ;
8+ import javafx .stage .Stage ;
9+
10+ public class LambdasIntro extends Application {
11+
12+ Button button ;
13+
14+ public static void main (String []args ){
15+ launch (args );
16+ }
17+
18+ public void start (Stage primaryStage ){
19+ primaryStage .setTitle ("Inner Class and Lambdas" );
20+ button = new Button ();
21+ button .setText ("Click Me" );
22+
23+ //Lambdas are available only with Java 8 and above..
24+ button .setOnAction (e -> System .out .println ("First Lambda Expression" ));
25+
26+ StackPane layout = new StackPane ();
27+ layout .getChildren ().add (button );
28+ Scene scene = new Scene (layout , 300 , 250 );
29+ primaryStage .setScene (scene );
30+ primaryStage .show ();
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments