Step-by-Step: Creating Your First App with JGUIFramework
Overview
A concise, practical tutorial that walks a Java developer from project setup to a working desktop app using JGUIFramework. Focuses on core concepts: project structure, main window, layout, event handling, and packaging.
Prerequisites
- Java JDK 17+ installed
- Build tool: Maven or Gradle (Maven examples below)
- Basic Java and OOP knowledge
1. Create the project (Maven)
- Run:
bash
mvn archetype:generate -DgroupId=com.example -DartifactId=my-jgui-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false cd my-jgui-app
- Add JGUIFramework dependency to pom.xml (example coordinates — replace with actual ones):
xml
<dependency> <groupId>org.jgui</groupId> <artifactId>jguiframework</artifactId> <version>1.0.0</version> </dependency>
2. Initialize the framework and main window
Create src/main/java/com/example/App.java:
java
import org.jgui.AppLauncher; import org.jgui.Window; public class App { public static void main(String[] args) { AppLauncher.launch(() -> { Window main = new Window(“My JGUI App”, 800, 600); // further UI setup… main.show(); }); } }
3. Layout and basic components
Use framework layout managers and components:
java
import org.jgui.components.Button; import org.jgui.components.TextField; import org.jgui.layout.VBox; VBox root = new VBox(10); // spacing TextField nameField = new TextField(); Button greetBtn = new Button(“Greet”); root.add(nameField); root.add(greetBtn); main.setContent(root);
4. Event handling
Add a click handler to update UI:
java
greetBtn.onClick(e -> { String name = nameField.getText().trim(); String message = name.isEmpty() ? “Hello!” : “Hello, “ + name + ”!”; main.showDialog(“Greeting”, message); });
5. Styling and resources
- Apply a CSS-like theme if supported:
java
main.getScene().addStylesheet(”/styles/app.css”);
- Include images in src/main/resources and load via resource API.
6. Data persistence (optional)
- For simple settings, use Preferences API or framework-provided storage:
java
Preferences prefs = Preferences.userRoot().node(“com/example/my-jgui-app”); prefs.put(“lastName”, nameField.getText());
7. Packaging and running
- Build:
bash
mvn package
- Run:
bash
java -jar target/my-jgui-app-1.0-SNAPSHOT.jar
- Create native installers if JGUIFramework offers bundling tools (check docs).
Troubleshooting tips
- Ensure correct Java version and dependency coordinates.
- Check framework docs for exact class/method names (APIs may vary).
- Use logging and exception stack traces to trace UI initialization issues.
Further enhancements
- Add menus, dialogs, and keyboard shortcuts
- Implement MVC or MVVM for larger apps
- Integrate with databases or web services
Leave a Reply