[personal profile] fardell24

Digital and Interactive Games 2015 – Term 2, Week 5, Session 1
Today
Intro to JavaFX
Basic Skeleton
・ Button
・ Checkbox
・ Listview
・ TextField

Chapter 17

BaseFXTwo
import javafx.application.Application;
import javafx.stage.Stagel

public class BaseFXTwo extends Application {
public static void main (string [] args) {
// Base JavaFX Application
Launch (args);




http://i.imgur.com/IOjnjaV.png?1

If you want to use the component anywhere in the application – declare it on a class level.

Screen design – The screen should be designed first.


http://i.imgur.com/jEiI1gg.png

Scene scene1 = new Scene(pane, 320, 200);

pane.getChildren().addAll(label1, label2, label3, label4)
Stage.setScene(scene1(i));

text1.setOnAction(new EventHandler() {
public void handle(ActionEvent a) {
// Handle click event here
}
});

setText
getText

label4.setText(text1.getText());

Integer.______

int i = sumIn(new Integer(text1.getText()), new Integer(text2.getText()));
label4.setText(Integer.toString(i)); ← catch exception here.



GridPane
SumInt.java
import javafx.event.ActionEvent;

public class SumInt {
int firstValue = 0;
int SecondValue = 0;

public static int sum(int a, int b) {
return a + b;
}
}

GridPane.java
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

public class gridPane extends Application {
Label label1;
Label label2;
Label label3;
Label label4;
Textfield text1;
Textfield text2;



public static void main(string[] args) {
// Base JavaFX Application

Launch (args);
}

@Override
public void start(Stage stage) throws Exception {
Stage.setTitle(“Grid Pane Sample”);

GridPane pane = new GridPane();
label1 = new Label(“First Value”);
label2 = new Label(“Second Value”)
label3 = new Label(“Total: ”);
label4 = new Label(“”);

text1 = new Textfield(“”);
text2 = new Textfield(“”);

text1.setOnAction(new EventHandler() {
public void handle(ActionEvent()) {
// Handle click event here

try {
int I = sumInt.sum(newInteger(text1.getText()), new Integer(text2.getText()));
} catch (NumberFormatException exception) {
label4.setText(“”);
}
}
});

// Second Text Field

pane.setConstraints(label1, 1, 1);
pane.setConstraints(label2, 1, 2);
pane.setConstraints(lable3, 1, 3);
pane.setConstraints(label4, 1, 4);
pane.setConstraints(text1, 2, 1);
pane.setConstraints(text2, 2, 2);
pane.getChildren().addAll(label1, label2, label3, label4);

Scene scene1 = new scene(pane, 320, 200);

Stage.show();
}
}



May 2025

S M T W T F S
     1 23
45 6 78910
11 12 13 141516 17
1819 2021 22 2324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 23rd, 2025 03:31 pm
Powered by Dreamwidth Studios