Created
December 30, 2017 00:46
-
-
Save diogobaltazar/92a060bae33e4f25b9243c117156e437 to your computer and use it in GitHub Desktop.
(JAVA) Event handlers, Anonymous inner classes, lambda expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Connection; | |
import javafx.application.Application; | |
import javafx.stage.Stage; | |
import javafx.event.ActionEvent; | |
import javafx.event.EventHandler; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.layout.StackPane; | |
public class UI extends Application { | |
private static Connection con = null; | |
private static Button btnConnect | |
, btnGetRows; | |
public static void main(String[] args) { | |
launch(args); | |
} | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
primaryStage.setTitle("Thought log"); | |
btnConnect = new Button(); | |
btnConnect.setText("Connect"); | |
btnConnect.setOnAction(new EventHandler<ActionEvent>() { | |
@Override | |
public void handle(ActionEvent event) { | |
con = RemoteConnection.connect(); | |
} | |
}); | |
btnGetRows = new Button(); | |
btnGetRows.setText("Get items"); | |
btnConnect.setOnAction(new EventHandler<ActionEvent>() { | |
@Override | |
public void handle(ActionEvent event) { | |
PostgreSQLDatabase.getRows(con, "schemaName", "tableName"); | |
} | |
}); | |
StackPane layout = new StackPane(); | |
layout.getChildren().add(btnConnect); | |
// root.getChildren().add(btnGetRows); | |
Scene scene = new Scene(layout, 400, 400); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Connection; | |
import javafx.application.Application; | |
import javafx.stage.Stage; | |
import javafx.event.ActionEvent; | |
import javafx.event.EventHandler; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.layout.StackPane; | |
public class UI extends Application implements EventHandler<ActionEvent> { | |
private static Connection con = null; | |
private static Button btnConnect | |
, btnGetRows; | |
public static void main(String[] args) { | |
launch(args); | |
} | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
primaryStage.setTitle("Thought log"); | |
btnConnect = new Button(); | |
btnConnect.setText("Connect"); | |
btnConnect.setOnAction(this); | |
btnGetRows = new Button(); | |
btnGetRows.setText("Get items"); | |
btnGetRows.setOnAction(this); | |
StackPane layout = new StackPane(); | |
layout.getChildren().add(btnConnect); | |
Scene scene = new Scene(layout, 400, 400); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
/** | |
* Handle user triggered events | |
*/ | |
@Override | |
public void handle(ActionEvent event){ | |
Object reference = event.getSource(); | |
if(reference == btnConnect) | |
con = RemoteConnection.connect(); | |
if (reference == btnGetRows) | |
PostgreSQLDatabase.getRows(con, "schemaName", "tableName"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Connection; | |
import javafx.application.Application; | |
import javafx.stage.Stage; | |
import javafx.event.ActionEvent; | |
import javafx.event.EventHandler; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.layout.StackPane; | |
public class UI extends Application { | |
private static Connection con = null; | |
private static Button btnConnect | |
, btnGetRows; | |
public static void main(String[] args) { | |
launch(args); | |
} | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
primaryStage.setTitle("Thought log"); | |
btnConnect = new Button(); | |
btnConnect.setText("Connect"); | |
btnConnect.setOnAction(e -> con = RemoteConnection.connect()); | |
btnGetRows = new Button(); | |
btnGetRows.setText("Get items"); | |
btnConnect.setOnAction(e -> PostgreSQLDatabase.getRows(con, "schemaName", "tableName")); | |
StackPane layout = new StackPane(); | |
layout.getChildren().add(btnConnect); | |
// root.getChildren().add(btnGetRows); | |
Scene scene = new Scene(layout, 400, 400); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment