import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JVideo extends JFrame implements ActionListener { final int FAVORITE_PRICE = 3; final int LEAST_FAV_PRICE = 1; final int REG_PRICE = 2; int selectedArray; int totalPrice; JTextField checkoutTotal = new JTextField(10); String[] movieStrings = {"Reservoir Dogs", "Memento", "Oldboy", "Inglorious Bastards", "Snatch", "Slumdog Millionaire", "District 9", "Ip Man", "Gran Torino", "The Matrix"}; JComboBox greenBox = new JComboBox(movieStrings); JLabel explainSelector = new JLabel("Please use the drop down menu to select a movie to rent."); JLabel welcome = new JLabel("Welcome to Greenbox"); public JVideo() { super("Greenbox Rentals"); greenBox.setSelectedIndex(5); add(greenBox); greenBox.addActionListener(this); add(welcome); add(explainSelector); add(checkoutTotal); checkoutTotal.setText("$" + totalPrice); setLayout(new FlowLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(java.awt.event.ActionEvent e) { if(greenBox.getSelectedIndex() == 7) totalPrice = FAVORITE_PRICE; else if(greenBox.getSelectedIndex() == 6) totalPrice = LEAST_FAV_PRICE; else if(greenBox.getSelectedIndex() == 5) totalPrice = LEAST_FAV_PRICE; else totalPrice = REG_PRICE; } public static void main(String[] args) { JVideo aFrame = new JVideo(); final int WIDTH = 400; final int HEIGHT = 600; aFrame.setSize(WIDTH, HEIGHT); aFrame.setTitle("Greenbox Videos"); aFrame.setVisible(true); } }
Im having one vital issue with my code for a video renting program. It won't tell you how much the movie you are renting costs >.<
I have no clue why, no matter how much i stare at the code. Is there another way I have to go about detecting which index of the array is selected? Or are my if statements not actually being updated and checked or are they not performing their action? UGGHH I just dont know anymore