A Java desktop application that fetches real-time weather data using the OpenWeatherMap API and displays it with an interactive map interface.
- 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
- Java 25 or higher
- Dependencies (included as JAR files):
json-20240303.jar- JSON parsing libraryhttpclient-4.5.14-javadoc.jar- HTTP connectionsJMapViewer.jar- Interactive map display (OpenStreetMap)jgoodies-forms-1.8.0.jar- UI layout utilitiesmiglayout15-swing.jar- Layout manager
-
Clone or download the project
cd JavaFinalProj -
Create API Configuration
- Create a
config.propertiesfile in the project root directory - Add your OpenWeatherMap API key:
apiKey=YOUR_API_KEY_HERE - Get your free API key from OpenWeatherMap
- Create a
-
Add Image Asset
- Ensure the loading GIF exists at:
imagersc/hzk6C.gif - This is displayed while fetching weather data
- Ensure the loading GIF exists at:
-
Compile and Run
javac src/JavaFinalProj/Weatherapi.java java -cp src JavaFinalProj.Weatherapi
- Enter a location name in the text field (e.g., "Manila", "New York")
- Click "Fetch Weather" button or press Enter
- View real-time weather data in the UI panels
- Click "Open Map" button to open the interactive map
- Click on any location on the map to place a marker
- The app automatically fetches and displays weather for that location
- Map window closes automatically after selection
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
- 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
- User inputs location (text or map)
- Geocoding API converts location → coordinates
- Weather API fetches data using coordinates
- JSON response parsed and displayed in UI labels
- Loading GIF hidden once data is ready
| 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 |
- 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)
https://api.openweathermap.org/data/2.5/weather- Current weatherhttp://api.openweathermap.org/geo/1.0/direct- Geocoding (location → coordinates)http://api.openweathermap.org/geo/1.0/reverse- Reverse geocoding (coordinates → location)
- Invalid location input validation
- Empty API response checking
- Exception handling with user-friendly error messages
- Console logging for debugging
- Weather forecast (5-day, hourly)
- Multiple location favorites/bookmarks
- Temperature unit toggle (Celsius/Fahrenheit)
- Search history
- Location-based weather alerts
This project is provided as-is for educational purposes.
Created as a Java final project combining Swing GUI, REST API integration, and interactive mapping.