Question: My button will not print out any statements when it is supposed to print the total amount. This is Java GUI Code: import javax.swing.*; import

My button will not print out any statements when it is supposed to print the total amount. This is Java GUI

Code:

import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

public class CEP_P01 implements ActionListener { private int dormCost = 0; private int mealCost = 0; private int costOfTotalCharges = 0; private Object variable; private String costOfTotalChargesLabel; public CEP_P01() { JPanel dormPanel = new JPanel(); JFrame frame = new JFrame ("Dorm Calculator"); frame.setVisible(true); String[] dormNames = new String[] {"Allen Hall", "Pike Hall", "Farthing Hall", "University Suites" }; JLabel dormLabel = new JLabel("Enter dorm room hall name:"); dormLabel.getText(); dormPanel.add(dormLabel); JComboBox dormTitles = new JComboBox(dormNames); dormPanel.add(dormTitles); dormTitles.setEditable(true); String[] mealPlans = new String[] {"7 meals per week", "14 meals per week", "Unlimited meals per week"}; JLabel mealLabel = new JLabel("Enter meal plans:"); dormPanel.add(mealLabel); mealLabel.getText(); JComboBox mealNumbers = new JComboBox(mealPlans); dormPanel.add(mealNumbers); mealNumbers.setEditable(true); JButton button = new JButton("Total charges"); button.setBounds(50,100,95,30); dormPanel.add(button); frame.add(dormPanel); frame.setVisible(true); button.addActionListener(this); if(dormTitles.getName() == "Allen Hall") { dormCost = 1500; } else if(dormTitles.getName() == "Pike Hall") { dormCost = 1600; } else if(dormTitles.getName() == "Farthing Hall") { dormCost = 1200; } else if(dormTitles.getName() == "University Suites") { dormCost = 1800; } else { System.out.println("Error"); } if(mealNumbers.getName() == "7 meals per week") { mealCost = 560; } else if(mealNumbers.getName() == "14 meals per week") { mealCost = 1095; } else if(mealNumbers.getName() == "Unlimited meals") { mealCost = 1500; } else { System.out.println("Error"); } JLabel costOfTotalChargesLabel = new JLabel(""); dormPanel.add(costOfTotalChargesLabel); costOfTotalChargesLabel.setBounds(50,100,95,30); } @Override public void actionPerformed(ActionEvent e) { int costOfTotalCharges = dormCost + mealCost; costOfTotalChargesLabel = ("Total Charges = $" + Integer.toString(costOfTotalCharges)); } public String toString() //toString method to return a null statement { return null; } public void thisVariable() { Object variable = null; this.variable = variable; } public static void main(String[] args) { CEP_P01 testToGetLabels = new CEP_P01(); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!