Computerized Garden - a.k.a. GardenSim - is a Java 17 + JavaFX 22 project that simulates a small garden.
You can plant (Rose, Tomato, Orange), simulate weather, spawn/control pests, and watch plants survive or die over days.
It supports two modes:
- GUI mode (JavaFX): interactive, visual garden
- API mode (headless): programmatic simulation for graders/automation
- Background grid (7×8) with fixed, equal cells
- Click-to-plant with radio buttons (Rose, Tomato, Orange)
- Pests randomly spawn; pesticide removes them; pests can kill plants
- Weather controls: Rain, Sprinklers, Temperature (heating)
- Auto day progression via Simulate (toggle Start/Pause)
- Logs panel + file logging to
garden-simulation.log
- Programmatic control via
GardenSimulator&GardenSimulatorAPI - Reads
config.jsonfor plant definitions - Simulates rain, temperature, and parasites
- Adjustable speed and parameters via JVM flags (e.g.
-Ddays,-Dpest,-DtickMs)
GardenSim/
├── run # macOS/Linux runner (GUI by default; "api" for headless)
├── run.bat # Windows runner (GUI by default; "api" for headless)
├── pom.xml # Maven build file
├── README.md # Project documentation
├── garden-simulation.log # Runtime log (gitignored/local)
├── src/
│ ├── main/
│ │ ├── java/com/gardensim/
│ │ │ ├── GUIMain.java # JavaFX app entry (GUI)
│ │ │ ├── ViewController.java # UI logic
│ │ │ ├── GardenSimulator.java # Headless simulation entry
│ │ │ ├── GardenSimulatorAPI.java # API surface; loads config.json
│ │ │ ├── GardenController.java # Simulation control
│ │ │ ├── GardenThread.java # Simulation thread/timing
│ │ │ ├── Plant.java
│ │ │ ├── Rose.java
│ │ │ ├── Tomato.java
│ │ │ ├── Orange.java
│ │ │ ├── Pest.java
│ │ │ ├── PestAttackController.java # Pest behavior
│ │ │ ├── RainController.java
│ │ │ ├── SprinklerController.java
│ │ │ ├── PesticideController.java
│ │ │ ├── TemperatureController.java
│ │ │ └── HeatingController.java
│ │ └── resources/
│ │ ├── com/gardensim/view.fxml # JavaFX layout
│ │ ├── config.json # Simulation config
│ │ ├── log4j2.properties # Logging config
│ │ └── images/ # GUI assets
│ │ ├── garden.jpg
│ │ ├── sunny.png
│ │ ├── rain.png
│ │ ├── rose.png
│ │ ├── tomato.png
│ │ ├── orange.png
│ │ └── bug.png
│ └── test/java/ # (empty placeholder for unit tests)
├── docs/ # Project report and slides.
│ ├── Report.pdf
│ ├── Slides.pdf
│ └── Slides.pptx
└── imagesReadMe/ # For screenshots in README.md
├── image1.png
├── image2.png
├── image3.png
├── image4.png
├── image5.png
├── image6.png
└── image7.png
- Java: JDK 17 (or newer, compatible with JavaFX 22)
- Maven: 3.9+
- Git: for cloning (optional but recommended)
- IDE (optional): Any modern Java IDE.
- Initially developed in IntelliJ IDEA Community Edition
- Also tested with Visual Studio Code
java -version
mvn -vgit clone https://github.com/gardensim/GardenSim.git
cd GardenSimchmod +x run- macOS / Linux
./run
- Windows
run
This launches the JavaFX app (
GUIMain).
- macOS / Linux
./run api
- Windows
run api
-Ddays=<int>: how many days to simulate (default: script/main decides)-Dpest=<0..1>: pest spawn probability per occupied cell per day (e.g.0.3)-DtickMs=<int>: ms per simulated “day tick” (e.g.1000ms)
macOS / Linux
./run api -Dexec.jvmArgs="-Ddays=15 -Dpest=0.35 -DtickMs=1200"Windows
run api -Dexec.jvmArgs="-Ddays=20 -Dpest=0.25 -DtickMs=800"Under the hood,
run apiuses a Maven profile to launchGardenSimulator.
-
Click Simulate to start/pause the day cycle (e.g., 1 day every 10s).
-
Choose a plant (Rose (default) / Tomato / Orange).
-
Click a grid cell to plant.
-
Use Rain, Sprinklers, Apply Pesticide, and Handle Temperature.
-
Watch the Logs panel (and
garden-simulation.log) for events.
Build (compile & package):
mvn -q -DskipTests package
Run GUI via Maven (without scripts):
mvn -q -DskipTests javafx:run
Run API via Maven (without scripts):
mvn -q -Papi exec:java
A fat/uber JAR is not provided by default because JavaFX apps typically run with the Maven JavaFX plugin. Use the run scripts or the Maven commands above.
If you don’t have Maven installed globally, you can use the provided Maven Wrapper scripts (mvnw, mvnw.cmd, .mvn/wrapper/).
This ensures the correct Maven version is downloaded automatically.
-
macOS/Linux
./mvnw clean javafx:run
-
Windows
mvnw.cmd clean javafx:run
-
You can also package the project:
./mvnw -q -DskipTests package
The API loads plant definitions from src/main/resources/config.json.
Here’s a recommended minimal example (aligns with the GUI options):
{
"plants": [
{ "name": "Rose", "waterRequirement": 20, "temperature": 22, "parasites": ["Aphids", "Spider mites"] },
{ "name": "Tomato", "waterRequirement": 18, "temperature": 23, "parasites": ["Whiteflies", "Leafhoppers"] },
{ "name": "Orange", "waterRequirement": 24, "temperature": 25, "parasites": ["Scale", "Leaf miners"] }
]
}You can extend this list; the API will load any additional plants you define here. The GUI currently provides radio buttons for the three above.
- All significant events are logged to:
- UI panel (right side)
- File:
garden-simulation.log(project root)
If the file grows large, you can delete it safely; a new one will be created next run.
-
Insets is not a valid type (FXML load error)
Ensure there’s no<Insets .../>node without proper import. Ourview.fxmlavoids this. If you edited FXML, remove strayInsetselements or specify them via styles. -
ClassCastException: Group -> StackPanewhen clicking cell
This happens if the grid contains a non-StackPanechild. Use the providedview.fxmland controller code. If you migrated from an older layout, clean and rebuild:mvn -q -DskipTests clean javafx:run -
Images not visible
File names insrc/main/resources/images/must match exactly:garden.jpg, sunny.png, rain.png, bug.png, rose.png, tomato.png, orange.png. -
JavaFX native access warnings
You may see warnings about--enable-native-access=javafx.graphics. They’re harmless for this project. -
GUI looks uneven
Make the window larger. The grid uses equal-percentage rows/columns and scales cleanly.
Typing long Maven commands gets old.
We provide:
run(macOS/Linux) andrun.bat(Windows)run→ JavaFX GUIrun api→ headless API via Maven exec profile
This keeps the project platform-independent and one-command to start.
This project is open-source under the MIT License.
See LICENSE. Feel free to adapt and extend!
- Team of three
Originally developed between Sept 2024 – Dec 2024 as the final project for the course OOADP (Object-Oriented Analysis, Design, and Programming) at SCU.
The Garden Simulator project (a Computerized Garden) was built in Java and JavaFX, applying core OOADP concepts.
It featured management of weather effects, plants, pests, seasons, logs (date/time), and sprinkler sensors.
The project was graded on the survival of the garden, with the grader running the simulation via the API to test its sustainability.
See docs/ for the original course report and presentation used in submission.
Our team achieved full marks (best survival).
In 2025, the project was cleaned up, polished, and debugged before being published on GitHub as a showcase of both a JavaFX GUI application and a headless API-based simulator.
