Thursday, October 29, 2015

JavaFx Tutorial For Beginners 6 - Events with JavaFX Scene Builder

package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;

public class Main extends Application {
 public void start(Stage primaryStage) {
  try {
   //BorderPane root = new BorderPane();

   Parent root = FXMLLoader.load(getClass().getResource("/application/Main.fxml"));
   Scene scene = new Scene(root,400,400);
  } catch(Exception e) {
 public static void main(String[] args) {

package application;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;

import java.util.Random;
public class MainController {
    private Label myMessage; 
 public void generateRandom(ActionEvent event) {
  Random rand = new Random();
  int myrand = rand.nextInt(50) + 1;

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="300" prefWidth="500" xmlns:fx="" xmlns="" fx:controller="application.MainController">
      <Button fx:id="clickme" layoutX="213.0" layoutY="202.0" mnemonicParsing="false" onAction="#generateRandom" text="Click me" />
      <Label fx:id="myMessage" layoutX="116.0" layoutY="59.0" prefHeight="112.0" prefWidth="229.0" />

Partner Sites

Stuff I use to make videos

Windows notebook -

Apple MacBook Pro -

Microphone -

notebook mouse -