title: Java Eclipse: ComboBox action button based on item selected (e.g., temperature conversion)
body: <p>I am new to Java, and currently using Java Eclipse for practicing. I am having some trouble with comboBox where I am not sure how to go about making the program do something depending on the items selected from two comboboxes. I have two comboBoxes for converting temperature (Celsius, Fahrenheit, kelvin), and I managed to add these items. I am stuck on the convert button. My intention is if combobox1 = Celsius, and combobox2 = Fahrenheit, then use this calculation and output to textField_1 as a Fahrenheit value. Could you help me explicitly how to do this please?  Your help is greatly appreciated. Thank you so much!  I have tried searching for something similar, but I couldn't find one that is like mine, and others used netbeans and were quite different.    </p>
  
  <pre><code>        JButton btnNewButton = new JButton("Convert");//converts temperature input to output based on the comboBox and comboBox1 selections. 
      btnNewButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
  
  
              String inputTemp = (String)comboBox.getSelectedItem();
              String inputTemp1 = (String)comboBox_1.getSelectedItem();
  
              double inputTemp, inputTemp1, Celsius, Fahrenheit, Kelvin;
              inputTemp=Double.parseDouble(textField.getText());
  
              if (inputTemp.equals("Celsius") &amp;&amp; inputTemp1.equals("Fahrenheit")) {
                  Celsius = inputTemp;
              Fahrenheit = (Celsius*1.8)+32;
              textField_1.setText(Double.toString(Fahrenheit));
  
          }else{JOptionPane.showMessageDialog(null, "Invalid value.");
              }
  
          }
      });
      btnNewButton.setFont(new Font("Times New Roman", Font.PLAIN, 13));
      btnNewButton.setBounds(335, 64, 89, 103);
      frame.getContentPane().add(btnNewButton);
  
      textField_1 = new JTextField();
      textField_1.setBounds(41, 129, 147, 38);
      frame.getContentPane().add(textField_1);
      textField_1.setColumns(10);
  
      JComboBox comboBox = new JComboBox();
      comboBox.setBounds(198, 67, 127, 38);
      frame.getContentPane().add(comboBox);
  
      comboBox.addItem("Celsius");
      comboBox.addItem("Fahrenheit");
      comboBox.addItem("Kelvin");
  
      JComboBox comboBox_1 = new JComboBox();
      comboBox_1.setBounds(198, 129, 127, 38);
      frame.getContentPane().add(comboBox_1);
  
      comboBox_1.addItem("Celsius");
      comboBox_1.addItem("Fahrenheit");
      comboBox_1.addItem("Kelvin");
  </code></pre>