Jump to content

Java : JComboBox with IF Statement

chazat123

I'm currently programming a pretty basic Java Currency Converter. 

I decided to use ComboBoxes as I've familiarized myself with them before.

 

I want to receive the user's input from those combo boxes and implement them into an IF statement

 

How would I go about recording their input.

 

Many thanks,

Charlie

import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class Currency_Converter {    public static void main(String[] args) {        JFrame mainframe = new JFrame("CConverter 4");        new Currency_Converter();        //Begin Welcome Message        JLabel welcome_message = new JLabel("Welcome to CConverter V4.0", JLabel.CENTER);        welcome_message.setForeground(Color.RED);        mainframe.add(welcome_message);        welcome_message.setVerticalTextPosition(JLabel.TOP);        welcome_message.setHorizontalTextPosition(SwingConstants.CENTER);        //End Welcome Message        mainframe.add(Box.createVerticalStrut(100));        // Begin Drop Down Menu 1        final String[] comboList = {"Please select the currency you wish to convert from.", "EUR", "GBP", "USD"};        JComboBox comboBox = new JComboBox(comboList);        comboBox.setForeground(Color.BLUE);        comboBox.setSelectedIndex(0);        comboBox.setMaximumSize(new Dimension(1280, 100));        mainframe.add(comboBox);        // End Drop Down Menu 1        mainframe.add(Box.createVerticalStrut(100));        //Begin Drop Down Menu 2        String[] ComboList2 = {"Please select the currency you wish to convert to.", "EUR", "GBP", "USD"};        JComboBox ComboBox2 = new JComboBox(ComboList2);        ComboBox2.setSelectedIndex(0);        ComboBox2.setMaximumSize(new Dimension(1280, 100));        mainframe.add(ComboBox2);        //End Drop Down Menu 2        mainframe.add(Box.createVerticalStrut(100));        //Begin Frame Customisation        {            mainframe.setLayout(new BoxLayout(mainframe.getContentPane(), BoxLayout.Y_AXIS));        }        mainframe.setSize(1280, 720);        mainframe.setLocationRelativeTo(null);        mainframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);        mainframe.setVisible(true);        mainframe.setBackground(Color.BLUE);        mainframe.setResizable(false);        //End Frame Customisation    }}
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×