Skip to content

Commit db1ea89

Browse files
committed
JavaFX: ButtonsAndEvents
1 parent bb4e1e7 commit db1ea89

File tree

9 files changed

+117
-4
lines changed

9 files changed

+117
-4
lines changed

JavaFX/ButtonsAndEvents/.classpath

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-8-oracle"/>
5+
<classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

JavaFX/ButtonsAndEvents/.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>ButtonsAndEvents</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
21+
<nature>org.eclipse.jdt.core.javanature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="ASCII"?>
2+
<anttasks:AntTask xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:anttasks="http://org.eclipse.fx.ide.jdt/1.0" buildDirectory="${project}/build">
3+
<deploy>
4+
<application name="ButtonsAndEvents"/>
5+
<info/>
6+
</deploy>
7+
<signjar/>
8+
</anttasks:AntTask>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package application;
2+
3+
import javafx.application.Application;
4+
import javafx.fxml.FXMLLoader;
5+
import javafx.scene.Parent;
6+
import javafx.scene.Scene;
7+
import javafx.stage.Stage;
8+
9+
10+
public class Main extends Application {
11+
@Override
12+
public void start(Stage primaryStage) {
13+
try {
14+
Parent root = FXMLLoader.load(getClass().getResource("/fxml/Main.fxml"));
15+
Scene scene = new Scene(root,600,400);
16+
primaryStage.setScene(scene);
17+
primaryStage.setTitle("Watermelon Window");
18+
primaryStage.show();
19+
} catch(Exception e) {
20+
e.printStackTrace();
21+
}
22+
}
23+
24+
public static void main(String[] args) {
25+
launch(args);
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package application;
2+
3+
import java.net.URL;
4+
import java.util.ResourceBundle;
5+
6+
import javafx.event.ActionEvent;
7+
import javafx.fxml.FXML;
8+
import javafx.fxml.Initializable;
9+
import javafx.scene.control.Label;
10+
11+
public class MainController implements Initializable {
12+
13+
@FXML
14+
private Label watermelonLabel;
15+
16+
@Override
17+
public void initialize(URL location, ResourceBundle resources) {
18+
19+
}
20+
21+
public void showWatermelon(ActionEvent event) {
22+
watermelonLabel.setText("Watermelon Ice-cream");
23+
}
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.geometry.*?>
4+
<?import javafx.scene.paint.*?>
5+
<?import javafx.scene.control.*?>
6+
<?import java.lang.*?>
7+
<?import javafx.scene.layout.*?>
8+
<?import javafx.scene.layout.AnchorPane?>
9+
10+
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController">
11+
<children>
12+
<BorderPane layoutX="3.0" layoutY="4.0" prefHeight="392.0" prefWidth="594.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
13+
<bottom>
14+
<Button mnemonicParsing="false" onAction="#showWatermelon" text="Click Me!" BorderPane.alignment="CENTER">
15+
<BorderPane.margin>
16+
<Insets bottom="25.0" />
17+
</BorderPane.margin>
18+
</Button>
19+
</bottom>
20+
<center>
21+
<Label fx:id="watermelonLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="142.0" prefWidth="350.0" text="Click the button" BorderPane.alignment="CENTER" />
22+
</center>
23+
</BorderPane>
24+
</children>
25+
</AnchorPane>

JavaFX/HelloWatermelonyWorld/src/application/Main.fxml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
<?import javafx.scene.layout.*?>
88
<?import javafx.scene.layout.AnchorPane?>
99

10-
11-
<AnchorPane prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: ff5470;" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
10+
<AnchorPane prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: ff5470;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
1211
<children>
1312
<Label alignment="CENTER" layoutX="122.0" layoutY="41.0" prefHeight="47.0" prefWidth="355.0" style="-fx-text-fill: ffffff;" text="Hello, watermelon-y world!" textAlignment="RIGHT" wrapText="true" AnchorPane.bottomAnchor="312.0" AnchorPane.leftAnchor="122.0" AnchorPane.rightAnchor="122.0" AnchorPane.topAnchor="41.0" />
14-
<ImageView fitHeight="260.0" fitWidth="401.0" layoutX="140.0" layoutY="112.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="28.0" AnchorPane.leftAnchor="140.0" AnchorPane.rightAnchor="139.01235961914062" AnchorPane.topAnchor="112.0">
13+
<ImageView fitHeight="260.0" fitWidth="401.0" layoutX="140.0" layoutY="112.0" pickOnBounds="true" preserveRatio="true">
1514
<image>
1615
<Image url="@../helloWatermelon.jpg" />
1716
</image>

JavaFX/HelloWatermelonyWorld/src/application/Main.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import javafx.fxml.FXMLLoader;
55
import javafx.scene.Parent;
66
import javafx.scene.Scene;
7-
import javafx.scene.layout.BorderPane;
87
import javafx.stage.Stage;
98

109

0 commit comments

Comments
 (0)