Skip to content

dandangerero21/Java-API-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Weather API Application

A Java desktop application that fetches real-time weather data using the OpenWeatherMap API and displays it with an interactive map interface.

Features

  • Location Search: Search for weather by typing a location name
  • Interactive Map: Use an interactive map to pinpoint exact locations with map markers
  • Real-time Weather Data: Displays comprehensive weather information including:
    • Current temperature, feels-like temperature, min/max temps
    • Humidity and sea level pressure
    • Wind speed and direction
    • Weather description with weather icon
    • Location name and country information
  • Reverse Geocoding: Automatically get location names from map coordinates
  • Loading Animation: Visual feedback while fetching data from the API
  • Background Processing: Uses SwingWorker to prevent UI freezing during API calls

Requirements

  • Java 25 or higher
  • Dependencies (included as JAR files):
    • json-20240303.jar - JSON parsing library
    • httpclient-4.5.14-javadoc.jar - HTTP connections
    • JMapViewer.jar - Interactive map display (OpenStreetMap)
    • jgoodies-forms-1.8.0.jar - UI layout utilities
    • miglayout15-swing.jar - Layout manager

Installation

  1. Clone or download the project

    cd JavaFinalProj
  2. Create API Configuration

    • Create a config.properties file in the project root directory
    • Add your OpenWeatherMap API key:
      apiKey=YOUR_API_KEY_HERE
    • Get your free API key from OpenWeatherMap
  3. Add Image Asset

    • Ensure the loading GIF exists at: imagersc/hzk6C.gif
    • This is displayed while fetching weather data
  4. Compile and Run

    javac src/JavaFinalProj/Weatherapi.java
    java -cp src JavaFinalProj.Weatherapi

Usage

Quick Search (Text Field)

  1. Enter a location name in the text field (e.g., "Manila", "New York")
  2. Click "Fetch Weather" button or press Enter
  3. View real-time weather data in the UI panels

Map Search (Interactive)

  1. Click "Open Map" button to open the interactive map
  2. Click on any location on the map to place a marker
  3. The app automatically fetches and displays weather for that location
  4. Map window closes automatically after selection

Project Structure

JavaFinalProj/
├── src/
│   └── JavaFinalProj/
│       └── Weatherapi.java          # Main application class
├── imagersc/
│   └── hzk6C.gif                     # Loading animation
├── config.properties                  # API key configuration
├── .classpath                         # Eclipse classpath configuration
└── README.md                          # This file

How It Works

Architecture

  • Geocoding API: Converts location names to latitude/longitude coordinates
  • Reverse Geocoding API: Converts coordinates to location names
  • Weather API: Fetches current weather data using coordinates
  • SwingWorker: Executes API calls in background thread to keep UI responsive

Data Flow

  1. User inputs location (text or map)
  2. Geocoding API converts location → coordinates
  3. Weather API fetches data using coordinates
  4. JSON response parsed and displayed in UI labels
  5. Loading GIF hidden once data is ready

UI Components

Panel Data Displayed
Main Current condition, description, weather icon
Main Metrics Temperature, feels-like, min/max temps, humidity, sea level
Wind Wind speed, wind direction
Location Location name, country

Technical Details

  • Framework: Java Swing (GUI)
  • Map Library: JMapViewer (OpenStreetMap tiles)
  • API Communication: HttpURLConnection with JSON parsing
  • Threading: SwingWorker for non-blocking API calls
  • Data Format: JSON (OpenWeatherMap API v2.5)

API Endpoints Used

  • https://api.openweathermap.org/data/2.5/weather - Current weather
  • http://api.openweathermap.org/geo/1.0/direct - Geocoding (location → coordinates)
  • http://api.openweathermap.org/geo/1.0/reverse - Reverse geocoding (coordinates → location)

Error Handling

  • Invalid location input validation
  • Empty API response checking
  • Exception handling with user-friendly error messages
  • Console logging for debugging

Future Enhancements

  • Weather forecast (5-day, hourly)
  • Multiple location favorites/bookmarks
  • Temperature unit toggle (Celsius/Fahrenheit)
  • Search history
  • Location-based weather alerts

License

This project is provided as-is for educational purposes.

Author

Created as a Java final project combining Swing GUI, REST API integration, and interactive mapping.

About

A JAVA project made in Eclipse. This is an API weather project using OpenWeatherMap and also uses GeoCoding/reverse GeoCoding for a more precise location weather prediction.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages