Real time Currency conversion Java GUI application using fixer io API

In this tutorial, we will learn how to create convert currency applications using fixer io API.

Before continuing make sure that you go through the below article:-

Introduction to GUI Build first GUI Application in Java using NetBeans IDE

Here we divide this article into different sections:-

  1. GUI interface.
  2. API and its implementation.
  3. Connecting both the interface and logic building.

Firstly create a GUI interface with text fields, buttons, and labels as shown in the snippet below.

Real time Currency conversion Java GUI application using fixer io API

What is API? How to use it in Java?

Well, API stands for Application Programming Interface. In short, it’s a set of rules that controls the interaction between software. APIs allow us to skip diving deeply into the source code of third-side software while allowing us to use their privileges fast and easily.

Pre-requisites before coding

public static void main(String[] args) throws Exception {
       
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        Request request = new Request.Builder()
                .url("http://data.fixer.io/api/latest?access_key=**************")
                .method("GET", null)
                .build();
        Response response = client.newCall(request).execute();
        String jsonData = response.body().string();
        JSONObject Jobject = new JSONObject(jsonData);
        System.out.println(Jobject.getJSONObject("rates"));   
        
        String s=Jobject.getJSONObject("rates").toString();
  • In the above code, OkHttp client is an efficient HTTP & HTTP/2 client for Android and Java applications.
  • As you get the access key (*****) it is confidential and hence different for different users.
  • Now, call the API and get the response in form of the JSON file using jsonData and JObject.

Connecting and Logic Building

Logic building 

Multiplying the rates with the amt(amount input) and get the Output.

String str = amt * s;
System.out.println(str);

Now our GUI interface, logic, and API are ready to time to connect the parts.

OUTPUT

Real time Currency conversion Java GUI application using fixer io API

One response to “Real time Currency conversion Java GUI application using fixer io API”

  1. ANAND RAJ says:

    please send me the project on currency convertor

Leave a Reply

Your email address will not be published. Required fields are marked *