Alter 7 files

Add `.gitignore`
Add `pom.xml`
Add `module-info.java`
Add `App.java`
Add `Controller.java`
Add `TodoObject.java`
Add `primary.fxml`
This commit is contained in:
akp 2023-01-31 21:24:40 +00:00
commit af94ecb129
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
7 changed files with 228 additions and 0 deletions

46
.gitignore vendored Normal file
View file

@ -0,0 +1,46 @@
### Java ###
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
### Maven Patch ###
# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

51
openjfx-todo/pom.xml Normal file
View file

@ -0,0 +1,51 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.akpain.todo</groupId>
<artifactId>_01-openjfx-intro</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>19</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>net.akpain.todo.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,7 @@
module net.akpain.todo {
requires javafx.controls;
requires javafx.fxml;
opens net.akpain.todo to javafx.fxml;
exports net.akpain.todo;
}

View file

@ -0,0 +1,38 @@
package net.akpain.todo;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
/**
* JavaFX App
*/
public class App extends Application {
private static Scene scene;
@Override
public void start(Stage stage) throws IOException {
scene = new Scene(loadFXML("primary"), 400, 400);
stage.setScene(scene);
stage.show();
}
static void setRoot(String fxml) throws IOException {
scene.setRoot(loadFXML(fxml));
}
private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
return fxmlLoader.load();
}
public static void main(String[] args) {
launch();
}
}

View file

@ -0,0 +1,59 @@
package net.akpain.todo;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class Controller {
public VBox todoDisplayBox;
public TextField todoTextField;
public Controller() {
todoDisplayBox = new VBox();
}
@FXML
private void addTodo() {
String input = todoTextField.getCharacters().toString();
if (input.length() == 0) {
return;
}
HBox p = new HBox(10);
CheckBox cb = new CheckBox();
cb.onMouseClickedProperty().set(this::checkBoxChecked);
p.getChildren().add(cb);
p.getChildren().add(new Label(input));
todoDisplayBox.getChildren().add(p);
todoTextField.clear();
}
private void checkBoxChecked(MouseEvent event) {
System.out.printf("checkbox checked %s\n", event.toString());
CheckBox source = (CheckBox) event.getSource();
HBox hbox = (HBox) source.getParent();
Label label = (Label) hbox.getChildren().get(1);
label.setStyle("-fx-strikethrough: true");
System.out.println(label.getStyle());
}
@FXML
private void onTextFieldKeyPress(KeyEvent keyEvent) {
if (keyEvent.getCode().getCode() == 10) {
// 10 is the keycode for enter
addTodo();
}
}
private void renderTodos() {}
}

View file

@ -0,0 +1,11 @@
package net.akpain.todo;
public class TodoObject {
private String text;
private boolean completed;
public TodoObject(String text) {
this.completed = false;
this.text = text;
}
}

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<GridPane xmlns:fx="http://javafx.com/fxml" hgap="5" vgap="5" xmlns="http://javafx.com/javafx"
fx:controller="net.akpain.todo.Controller">
<TextField fx:id="todoTextField" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.columnSpan="7" onKeyPressed="#onTextFieldKeyPress" />
<Button GridPane.columnIndex="8" GridPane.rowIndex="1" text="Add todo" onMouseClicked="#addTodo"/>
<VBox fx:id="todoDisplayBox" GridPane.columnIndex="1" GridPane.rowIndex="3" spacing="4" />
</GridPane>