Projects

Weather App

Java JavaFX REST APIs JSON

Description

This project is a JavaFX desktop weather app designed around a phone-sized 400×800 window. It pulls live forecast data from the National Weather Service API and active weather alerts for Illinois, then presents them across a current conditions page, a three-day forecast, an alerts list, and an interactive radar map.

Features

  • Current weather view with temperature, high/low, and short forecast
  • Animated GIF backgrounds that change with the weather condition
  • Hourly temperature curve plus wind, humidity, and precipitation details
  • Three-day forecast page built with a shared page template
  • Active Illinois alerts fetched from the NWS alerts API
  • Radar map screen rendered in a JavaFX WebView

Loads forecast and alert data once at startup, then opens the home screen:

@Override
public void start(Stage primaryStage) throws Exception {
  this.mainStage = primaryStage;

  Font.loadFont(getClass().getResource("/fonts/InterVariable.ttf").toExternalForm(), 12);

  forecast = WeatherAPI.getForecast("LOT", 77, 70);
  alerts = AlertsAPI.getActiveAlertsForIllinois();

  showHomePage();
  mainStage.setTitle("Weather App");
  mainStage.show();
}

Fetches a National Weather Service forecast for a grid point and maps the JSON response into Java objects:

public static ArrayList<Period> getForecast(String region, int gridx, int gridy) {
  HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create("https://api.weather.gov/gridpoints/" + region + "/"
          + gridx + "," + gridy + "/forecast"))
      .build();

  HttpResponse<String> response = HttpClient.newHttpClient()
      .send(request, HttpResponse.BodyHandlers.ofString());

  Root r = getObject(response.body());
  return r.properties.periods;
}

Updates the home screen with the current period, night temperature, and whether any alerts should be shown:

public void updateData(Period dayData, Period nightData, boolean hasAlerts) {
  tempLabel.setText(dayData.temperature + "°");
  descLabel.setText(dayData.shortForecast);

  int high = dayData.temperature;
  int low = (nightData != null) ? nightData.temperature : high - 10;
  hiLoLabel.setText("H: " + high + "° L: " + low + "°");

  alertButton.setVisible(hasAlerts);
  alertButton.setManaged(hasAlerts);
}

Outcome

A complete JavaFX weather client with multiple screens, live API data, and a phone-style layout. The project was a chance to practice Java networking, JSON parsing, and building a multi-page desktop UI.