Skip to content

mayanktomar-04/TemperatureConversionusingJava

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Temperature Converter (Fahrenheit to Celsius)

A simple Java-based GUI application that converts temperatures from Fahrenheit to Celsius. Users can input a temperature in Fahrenheit, click the CONVERT button, and the equivalent Celsius temperature is displayed.


Features

  • User-Friendly GUI: Built with Java Swing for a clean and simple interface.

  • Temperature Conversion: Converts Fahrenheit to Celsius using the formula:

    [ C = (F - 32) \times \frac{5}{9} ]

  • Placeholder Text: Input fields include placeholder text for guidance.

  • Icons: Displays Fahrenheit and Celsius icons for better UX (stored in the resources/ folder).


Components

1. FToC.java

  • Main class that runs the temperature conversion GUI application.
  • GUI Elements:
    • tField1: Text field for user input (Fahrenheit).
    • tField2: Text field for displaying the result (Celsius).
    • CONVERT button: Triggers the conversion.
  • ActionListener: Converts temperature on button click. Displays an error message for invalid input.

2. PlaceholderHandler.java

  • Handles placeholder text in text fields.
  • apply(): Sets placeholder text, removes it on focus, and restores it if the field is empty.

3. iconLoader.java

  • Loads Fahrenheit and Celsius icons.
  • loadIcon(): Loads and scales icons from the resources/ folder.
  • getFahrenheitIcon() & getCelsiusIcon(): Return the respective icons.

Installation

  1. Clone the Repository:

    git clone <repository-url>
    
  2. Ensure Dependencies This project uses Java Swing, included in the JDK. No additional dependencies are required.

  3. Resources Folder Ensure the resources/ folder contains the icons:

  • fahrenheit.png
  • celsius.png

Usage

Run the Program

Execute the FToC class. A window will appear with a text field for Fahrenheit input.

Enter Temperature

Type a temperature in Fahrenheit (e.g., 100) in the first text field.

Click "CONVERT"

The equivalent Celsius temperature will appear in the second text field.

Example

Input:

Temperature in °F: 100

Output:

Result in °C: 37.78 °C

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages