Hello.import java.awt.*; import javax.swing.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.*; public class JVideo2 extends JFrame implements ItemListener { final int FRAME_WIDTH = 800; final int FRAME_HEIGHT = 200; int totalprice; int dislike = 1; int most = 2; int favorite = 3; JLabel label = new JLabel("Please type the movie you would like to rent and press enter. The price is as followed:"); String[] movietitles = { "" ,"Taken", "Monty Python and the Holy Grail", "Ong-bak", "Ip Man", "The Goonies", "Labyrinth", "The Hobbit", "Balto", "Fairy Tail: Priestess of the Phoenix", "The NeverEnding Story"}; JComboBox movietitlesbox = new JComboBox(movietitles); JTextField totPrice = new JTextField(5); public JVideo2() { super("Movies For Rent"); movietitlesbox.addItemListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setBackground(Color.black); label.setFont(new Font("Arial", Font.BOLD, 18)); label.setForeground(Color.white); setLayout (new FlowLayout()); add(movietitlesbox); add(totPrice); add(label); movietitlesbox.setEditable(true); totPrice.setText("$" + totalprice); setSize(FRAME_WIDTH, FRAME_HEIGHT); } public void itemStateChanged(ItemEvent event) { Object source = event.getSource(); int select = event.getStateChange(); if (movietitlesbox.getSelectedItem().equals("")) { totalprice = 0; } if (movietitlesbox.getSelectedItem().equals("Taken")) { totalprice = most; } if (movietitlesbox.getSelectedItem().equals("Monty Python and the Holy Grail")) { totalprice = favorite; } if (movietitlesbox.getSelectedItem().equals("Ong-bak")) { totalprice = dislike; } if (movietitlesbox.getSelectedItem().equals("Ip Man")) { totalprice = favorite; } if (movietitlesbox.getSelectedItem().equals("The Goonies")) { totalprice = dislike; } if (movietitlesbox.getSelectedItem().equals("Labyrinth")) { totalprice = favorite; } if (movietitlesbox.getSelectedItem().equals("The Hobbit")) { totalprice = most; } if (movietitlesbox.getSelectedItem().equals("Balto")) { totalprice = favorite; } if (movietitlesbox.getSelectedItem().equals("Fairy Tail: Priestess of the Phoenix")) { totalprice = most; } if (movietitlesbox.getSelectedItem().equals("The NeverEnding Story")) { totalprice = most; } totPrice.setText("$" + totalprice); } public static void main(String[] args) { JVideo2 frame = new JVideo2(); frame.setVisible(true); } }
I am trying to make it that if you type anything else not listed in the string within the editable JCOMBOBOX the code tells you please use one of the names of the movies located in the string. I was wondering how you go about doing that.