Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8605173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:45:39+00:00 2026-06-12T02:45:39+00:00

I’m trying to get a simple currency converter in Java. My problem is that

  • 0

I’m trying to get a simple currency converter in Java.
My problem is that I can’t get the different equations to work, I have tried using ActionListener for the JComboBox, and if statements, but it doesent seem to work.
Could someone help me?
http://pastebin.com/RuM2jF5q
Is my entire code, please ask me if something is unclear 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:45:40+00:00Added an answer on June 12, 2026 at 2:45 am

    try this:

    import java.awt.Container;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    
    public class Copy {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
    
            JFrame ramme = new JFrame("Valutakalkulator");
            ramme.setResizable(true);
            ramme.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            ramme.setBounds(200, 300, 400, 200);
            Container panel = ramme.getContentPane();
            panel.setLayout(new GridLayout(4,1,10,10));
    
            String[] Valutavalg = { "USD","NOK","EUR" };        
    
            final JComboBox<?> Valutavalg1 = new JComboBox<Object>(Valutavalg);
            final JComboBox<?> Valutavalg2 = new JComboBox<Object>(Valutavalg);
    
            final JTextField konvleft = new JTextField("0");
            final JTextField konvright = new JTextField("0");
            final JTextField utbytte = new JTextField ("Utbytte av valuta");
    
    
            JButton bleft = new JButton("Konverter  -->");
            JButton bright = new JButton("<--  Konverter");
    
            bleft.setFont(new Font("sansserif", Font.PLAIN + Font.BOLD, 14));
            bright.setFont(new Font("sansserif", Font.PLAIN + Font.BOLD, 14));
    
            panel.add(Valutavalg1);
            panel.add(Valutavalg2);
            panel.add(bleft);
            panel.add(bright);
            panel.add(konvleft);
            panel.add(konvright);
            panel.add(utbytte);
    
            ramme.setVisible(true);
    
    
    
            ActionListener ValutaLeft = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
    
                    double numl = Double.parseDouble(konvleft.getText());
                    int combovalg1 = Valutavalg1.getSelectedIndex();
                    int combovalg2 = Valutavalg2.getSelectedIndex();
    
                    if (combovalg1==0){
                        if (combovalg2==0){
                            double totaltVerdi = numl*10;
                            setTotal(totaltVerdi, utbytte);
                        }
                        if (combovalg2==1){
                            double totaltVerdi = numl*100;
                            setTotal(totaltVerdi, utbytte);
                        }
                        if (combovalg2==2){
                            double totaltVerdi = numl*1000;
                            setTotal(totaltVerdi, utbytte);
                        }   
                    }
                    if (combovalg1==1){
                        if (combovalg2==0){
                            double totaltVerdi = numl*1000;
                            setTotal(totaltVerdi, utbytte);
                        }
                        if (combovalg2==1){
                            double totaltVerdi = numl*100000;
                            setTotal(totaltVerdi, utbytte);
                        }
                        if (combovalg2==2){
                            double totaltVerdi = numl*1000000;
                            setTotal(totaltVerdi, utbytte);
                        }   
                    }
                    if (combovalg1==2){
                        if (combovalg2==0){
                            double totaltVerdi = numl*1000000;
                            setTotal(totaltVerdi, utbytte);
                        }
                        else if (combovalg2==1){
                            double totaltVerdi = numl*1000000;
                            setTotal(totaltVerdi, utbytte);
                        }
                        else if (combovalg2==2){
                            double totaltVerdi = numl*10000000;
                            setTotal(totaltVerdi, utbytte);
                        }   
                    }
                };
                public void setTotal(double totaltVerdi, JTextField text){
                    totaltVerdi = Math.round(totaltVerdi*100)/100.0d;
                    String total1 = Double.toString(totaltVerdi);
                    utbytte.setText(total1);
                }
            };
    
            ActionListener ValutaRight = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
    
                    double numl = Double.parseDouble(konvright.getText());
                    int combovalg1 = Valutavalg1.getSelectedIndex();
                    int combovalg2 = Valutavalg2.getSelectedIndex();
    
                    if (combovalg2==0){
                        if (combovalg1==0){
                            double totaltVerdi = numl*10;
                            setTotal(totaltVerdi, utbytte);
                        }
                        if (combovalg1==1){
                            double totaltVerdi = numl*100;
                            setTotal(totaltVerdi, utbytte);
                        }
                        if (combovalg1==2){
                            double totaltVerdi = numl*1000;
                            setTotal(totaltVerdi, utbytte);
                        }   
                    }
                    if (combovalg2==1){
                        if (combovalg1==0){
                            double totaltVerdi = numl*1000;
                            setTotal(totaltVerdi, utbytte);
                        }
                        if (combovalg1==1){
                            double totaltVerdi = numl*100000;
                            setTotal(totaltVerdi, utbytte);
                        }
                        if (combovalg1==2){
                            double totaltVerdi = numl*1000000;
                            setTotal(totaltVerdi, utbytte);
                        }   
                    }
                    if (combovalg2==2){
                        if (combovalg1==0){
                            double totaltVerdi = numl*1000000;
                            setTotal(totaltVerdi, utbytte);
                        }
                        if (combovalg1==1){
                            double totaltVerdi = numl*1000000;
                            setTotal(totaltVerdi, utbytte);
                        }
                        if (combovalg1==2){
                            double totaltVerdi = numl*10000000;
                            setTotal(totaltVerdi, utbytte);
                        }   
                    }
                };
                public void setTotal(double totaltVerdi, JTextField text){
                    totaltVerdi = Math.round(totaltVerdi*100)/100.0d;
                    String total1 = Double.toString(totaltVerdi);
                    utbytte.setText(total1);
                }
            };
            bleft.addActionListener(ValutaLeft);
            bright.addActionListener(ValutaRight);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.