Create a GUI interface for a currency converter - Dollar-to-Euro. It should look something like the following: Have the user enter the amount of dollars to convert and the conversion rate. When the button is clicked, the amount of Euros should be displayed.Also include a Clear button that clears the input fields.

Question
Asked Nov 1, 2019
120 views

 Create a GUI interface for a currency converter - Dollar-to-Euro. It should look something like the following:

 

Have the user enter the amount of dollars to convert and the conversion rate. When the button is clicked, the amount of Euros should be displayed.

Also include a Clear button that clears the input fields.

check_circle

Expert Answer

Step 1

To create a GUI converter that converts the currency from dollar to euro below is the approach and java code is given:

Approach:

  • Using libraries javax.swing 
  • Using action listeners and event listeners.
  • Creating class converter.
  • Inside the converter class, a constructor is declared.
  • Inside constructor labels and text fields are declared as per the requirement.
  • Code to provide the actions performed by buttons as per the requirement. Clear button and converter buttons are used.
  • Setting up the alignment.
  • Declaring the main method.
  • Invoke the runnable function.
  • Inside the main method run method is defined which sets the visibility as true.

Variables are declared inside the main method as per the requirement.

Step 2

Code: -

public class Converter extends javax.swing.JFrame {

    /*

     * Design a form Converter

     */

    public Converter() {

        initComponents();

    }

    //Constructor that holds the JComponents

    private void initComponents() {

        //jbutton1 used for the conversion

        jButton1 = new javax.swing.JButton();

        //jbutton2 used for the clear

        jButton2 = new javax.swing.JButton();

        //jlabel1 used for the dollar tag

        jLabel1 = new javax.swing.JLabel();

        //jlabel2 used for the euro tag

        jLabel2 = new javax.swing.JLabel();

        //jTextField1 used to prompt user to enter the dollar value

        jTextField1 = new javax.swing.JTextField();

        //jTextField2 used to display the conversion of the dollar value into euro

        jTextField2 = new javax.swing.JTextField();

        //header  

        jLabel3 = new javax.swing.JLabel();

 

        //Action performance

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        //Create the action listener the event for button 1 and button 2

        //convert

        jButton1.setText("Convert");

        jButton1.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                jButton1ActionPerformed(evt);

            }

        });

        //clear

        jButton2.setText("Clear");

        jButton2.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                jButton2ActionPerformed(evt);

            }

        });

        //setting the label the names

        jLabel1.setText("Dollar");

        jLabel2.setText("Euro");

        //setting the label for header

        jLabel3.setFont(new java.awt.Font("Comic Sans MS", 3, 12)); // NOI18N

        // Alignment =>don't modify  

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        jLabel3.setText("Dollar to Euro");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addGap(52, 52, 52)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)

                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

                .addGap(18, 18, 18)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addComponent(jTextField1)

                    .addComponent(jTextField2))

                .addGap(192, 192, 192))

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                        .addComponent(jButton1)

                        .addGap(98, 98, 98))

                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                        .addComponent(jButton2)

             ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Using MIPS assembly language can someone help me write a program that does .. Write a program to fin...

A: Program Instructions:Ask the user for number of integers and get those integers.Load the array, redu...

question_answer

Q: 4. Given the for loop, rewrite the code so that it executes exactly the same but uses a while loop f...

A: For-loop syntax:             for(initialization ; condition ; updation)                             ...

question_answer

Q: A double-ended queue or deque is a generalization of a stack and a queue that supports adding and re...

A: Program descriptionThe answer for part-1 cannot be attempted as interface and skeleton has not been ...

question_answer

Q: c. Outline an algorithm for finding the largest key in a B-tree.

A: B-tree is a data structure tree that sorts the data, allows insertion and deletion, searching, and s...

question_answer

Q: In a large organization, how do you typically request permission to perform a network change?

A: Make the necessary management decisions regarding the changes.

question_answer

Q: Write a C++ program: you are now working for an accounting firm. Your employer is interested in dete...

A: This program accepts the number of hours and pay rate of an employee as input.For 40 regular hours a...

question_answer

Q: Blood alcohol content (BAC) is a measure of how much alcohol is in someone’s blood. It is usually me...

A: Program AlgorithmDeclare the required variables in the main().Get the input from the user for option...

question_answer

Q: (check all that are necessary) Which Oracle server parameters do you need to know in order toset up ...

A: Oracle server parameters required for the client to connect to the server are:Host name or the IP ad...

question_answer

Q: Write the MIPS assembly code that corresponds to the pseudo codebelow. Assume that the address for i...

A: MIPS instruction:The full form of MIPS is Million Instructions Per Second.The speed of computer’s pr...