title: Jcombobox, when an item is selected, a value is displayed
body: <p>Basically, I have a <code>JComboBox</code> and currently, the selected value is then displayed next to the combo box in a text box.</p>
  
  <p>However, what I would like to do, is upon selection of a value from the combo box - a different value is displayed in the text box (This displayed value is specific to the value selected from the combo box.</p>
  
  <p>So in this case I have sizes in the combo box, and I want costs displayed in the text field.</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  
  public class ComboBox{
    JComboBox combo;
    JTextField txt;
    public static void main(String[] args) {
      ComboBox b = new ComboBox();
    }
  
    public ComboBox(){
      String course[] = {"18x18cm (7x7inches)","18x20cm (7x8inches)",};
      JFrame frame = new JFrame("Cost Calculator");
      JPanel panel = new JPanel();
      combo = new JComboBox(course);
      combo.setBackground(Color.white);
      combo.setForeground(Color.black);
      txt = new JTextField(25);
      panel.add(combo);
      panel.add(txt);
      frame.add(panel);
      combo.addItemListener(new ItemListener(){
        public void itemStateChanged(ItemEvent ie){
          String str = (String)combo.getSelectedItem();
          txt.setText(str);
        }
      });
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(400,200);
      frame.setVisible(true);
    }
  }
  </code></pre>
  
  <p>So my question is how do I go about this?</p>