Hello everyone,

I have a question regarding a Japplet that I am creating for a theatre. The program is supposed to take a yes or no response from the user, take which section the user will be sitting in, ask how many tickets they would like to purchase, and then calculate their total cost when the total button is clicked. The problem I am having is that when I click the total button nothing is happening. I think it may be because I have my while loops in the wrong place, but any help you can give me would be much appreciated!

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;

/**
The Test class is an applet that calulates
ticket prices for a theatre.
*/

public class Test extends JApplet
{
private JPanel mPanel; // To hold a text field
private JPanel aPanel; // To hold a text field
private JPanel bPanel; // To hold a text field
private JPanel tPanel; // To hold a text field
private JPanel buttonPanel; // To hold a button
private JTextField member; // members
private JTextField area; // seating area
private JTextField ticketnum; // tickets
private JTextField total; // total cost

/**
init method
*/

public void init()
{
// Build the panels.
 buildmPanel();
 buildaPanel();
 buildbPanel();
 buildtPanel();
 
 buildButtonPanel();

// Create a layout manager.
setLayout(new GridLayout(5, 1));

// Add the panels to the content pane.
add(mPanel);
add(aPanel);
add(bPanel);
add(tPanel);
add(buttonPanel);
}

/**
The buildtPanel method creates a panel with a text
field in which the user can enter whether they are a member
or not.

*/

private void buildmPanel()
{
// Create the panel.
mPanel = new JPanel();

// Create a label to display a message.
JLabel message1 =
new JLabel("Are You a Member (Y/N)?: ");

// Create a text field for the Member temp.
member = new JTextField(10);

// Create a layout manager for the panel.
mPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

// Add the label and text field to the panel.
mPanel.add(message1);
mPanel.add(member);
}

private void buildaPanel()
{
// Create the panel.
aPanel = new JPanel();

// Create a label to display a message.
JLabel message2 =
new JLabel("What Seating Area?: ");

// Create a text field for the Member temp.
area = new JTextField(10);

// Create a layout manager for the panel.
aPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

// Add the label and text field to the panel.
aPanel.add(message2);
aPanel.add(area);
}

private void buildbPanel()
{
// Create the panel.
bPanel = new JPanel();

// Create a label to display a message.
JLabel message3 =
new JLabel("How many Tickets?: ");

// Create a text field for the Member temp.
ticketnum = new JTextField(10);

// Create a layout manager for the panel.
bPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

// Add the label and text field to the panel.
bPanel.add(message3);
bPanel.add(ticketnum);
}


/**
The buildpPanel method creates a panel that
displays the pounds in a
read-only text field.
*/

private void buildtPanel()
{
// Create the panel.
tPanel = new JPanel();

// Create a label to display a message.
JLabel message4 =
new JLabel("Total: ");
//Create a text field for the pounds temp.
total = new JTextField(10);

// Make the text field read-only.
total.setEditable(false);

// Create a layout manager for the panel.
tPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

// Add the label and text field to the panel.
tPanel.add(message4);
tPanel.add(total);
}

/**
The buildButtonPanel method creates a panel with
a button that converts the kgram temperature
to pounds.
*/

private void buildButtonPanel()
{
// Create the panel.
buttonPanel = new JPanel();

// Create a button with the text "Convert".
JButton convButton = new JButton("Total");

// Add an action listener to the button.
convButton.addActionListener(new ButtonListener());

// Add the button to the panel.
buttonPanel.add(convButton);
}

/**
Private inner class that handles the action event
that is generated when the user clicks the convert
*/

private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{

double btemp, ttemp ; // To hold the

if (member.equals ("Y") || member.equals("y")){
    boolean isMember = true;
    double totals = 0;

while (isMember){
if ( area.equals ("A") || area.equals ("a")){
        
        totals = 68;
        
    } else if ( area.equals ("B") || area.equals ("b")){
        
        totals = 42.50;
    
        } else if ( area.equals ("C") || area.equals ("c")){
            
            totals = 25.50;
            
        } else if (member.equals ("N") || member.equals("n")){
            
            isMember = false;
        
}
while (isMember = false){
    
    if ( area.equals ("A") || area.equals ("a")){
        
	totals = 80;
        
    } else if ( area.equals ("B") || area.equals ("b")){
        
        totals = 50;
    
        } else if ( area.equals ("C") || area.equals ("c")){
            
            totals = 30;
            
           }
        
}

//Create a DecimalFormat object to format numbers.
DecimalFormat formatter = new DecimalFormat("0.0");

// Get the number of tickets and convert to a double.
btemp = Double.parseDouble(ticketnum.getText());

 
// Calculate the total.
ttemp = btemp * totals;

// Display the total .
total.setText(formatter.format(ttemp));
}
}
}
}
}
import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
import java.text.DecimalFormat;
     
    /**
    The Test class is an applet that calulates
    ticket prices for a theatre.
    */
     
    public class Test extends JApplet
    {
    private JPanel mPanel; // To hold a text field
    private JPanel aPanel; // To hold a text field
    private JPanel bPanel; // To hold a text field
    private JPanel tPanel; // To hold a text field
    private JPanel buttonPanel; // To hold a button
    private JTextField member; // members
    private JTextField area; // seating area
    private JTextField ticketnum; // tickets
    private JTextField total; // total cost
     
    /**
    init method
    */
     
    public void init()
    {
    // Build the panels.
    buildmPanel();
    buildaPanel();
    buildbPanel();
    buildtPanel();
     
    buildButtonPanel();
     
    // Create a layout manager.
    setLayout(new GridLayout(5, 1));
     
    // Add the panels to the content pane.
    add(mPanel);
    add(aPanel);
    add(bPanel);
    add(tPanel);
    add(buttonPanel);
    }
     
    /**
    The buildtPanel method creates a panel with a text
    field in which the user can enter whether they are a member
    or not.
     
    */
     
    private void buildmPanel()
    {
    // Create the panel.
    mPanel = new JPanel();
     
    // Create a label to display a message.
    JLabel message1 =
    new JLabel("Are You a Member (Y/N)?: ");
     
    // Create a text field for the Member temp.
    member = new JTextField(10);
     
    // Create a layout manager for the panel.
    mPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
     
    // Add the label and text field to the panel.
    mPanel.add(message1);
    mPanel.add(member);
    }
     
    private void buildaPanel()
    {
    // Create the panel.
    aPanel = new JPanel();
     
    // Create a label to display a message.
    JLabel message2 =
    new JLabel("What Seating Area?: ");
     
    // Create a text field for the Member temp.
    area = new JTextField(10);
     
    // Create a layout manager for the panel.
    aPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
     
    // Add the label and text field to the panel.
    aPanel.add(message2);
    aPanel.add(area);
    }
     
    private void buildbPanel()
    {
    // Create the panel.
    bPanel = new JPanel();
     
    // Create a label to display a message.
    JLabel message3 =
    new JLabel("How many Tickets?: ");
     
    // Create a text field for the Member temp.
    ticketnum = new JTextField(10);
     
    // Create a layout manager for the panel.
    bPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
     
    // Add the label and text field to the panel.
    bPanel.add(message3);
    bPanel.add(ticketnum);
    }
     
     
    /**
    The buildpPanel method creates a panel that
    displays the pounds in a
    read-only text field.
    */
     
    private void buildtPanel()
    {
    // Create the panel.
    tPanel = new JPanel();
     
    // Create a label to display a message.
    JLabel message4 =
    new JLabel("Total: ");
    //Create a text field for the pounds temp.
    total = new JTextField(10);
     
    // Make the text field read-only.
    total.setEditable(false);
     
    // Create a layout manager for the panel.
    tPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
     
    // Add the label and text field to the panel.
    tPanel.add(message4);
    tPanel.add(total);
    }
     
    /**
    The buildButtonPanel method creates a panel with
    a button that converts the kgram temperature
    to pounds.
    */
     
    private void buildButtonPanel()
    {
    // Create the panel.
    buttonPanel = new JPanel();
     
    // Create a button with the text "Convert".
    JButton convButton = new JButton("Total");
     
    // Add an action listener to the button.
    convButton.addActionListener(new ButtonListener());
     
    // Add the button to the panel.
    buttonPanel.add(convButton);
    }
     
    /**
    Private inner class that handles the action event
    that is generated when the user clicks the convert
    */
     
    private class ButtonListener implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
     
    double btemp, ttemp ; // To hold the
    boolean isMember = false;
    double totals = 0.0;
    if (member.getText().equals ("Y") || member.getText().equals("y")){
    isMember = true;  
    }
    
    if (isMember){
    if ( area.getText().equals ("A") || area.getText().equals ("a")){
     
    totals = 68.0;
     
    } else if ( area.getText().equals ("B") || area.getText().equals ("b")){
     
    totals = 42.50;
     
    } else if ( area.getText().equals ("C") || area.getText().equals ("c")){
     
    totals = 25.50;
     
    } else if (member.getText().equals ("N") || member.getText().equals("n")){
     
    isMember = false;
     
    }
   } 
   
    if (!isMember){     
    if ( area.getText().equals ("A") || area.getText().equals ("a")){
     
    totals = 80.0;
     
    } else if ( area.getText().equals ("B") || area.getText().equals ("b")){
     
    totals = 50.0;
     
    } else if ( area.getText().equals ("C") || area.getText().equals ("c")){
     
    totals = 30.0;
     
    }     
    }
      
    //Create a DecimalFormat object to format numbers.
    DecimalFormat formatter = new DecimalFormat("0.0");
     
    // Get the number of tickets and convert to a double.
    btemp = Double.parseDouble(ticketnum.getText());
     
     
    // Calculate the total.
    ttemp = btemp * totals;
     
    System.out.println(ttemp);
    System.out.println(btemp);
    System.out.println(totals);
    
    // Display the total .
    total.setText(formatter.format(ttemp));
    }
    }
 }

i CORRECTED EVERY THING.... :)

commented: Don't spoon feed by Giving full code -3

Thank you very much sir! it all was stemming from the area.getText().equals. I appreciate you taking the time to help me out.

Why a negative point, i wasted my 20 min to help this guy so he will appreciate my work, you @Norm1 posted a negative reputation on my post... Why? There are no rules regards to spoon feeding in rule section.... I m not against the rule.. So please take it back.

> There are no rules regards to spoon feeding in rule section.
Correct, but re-writing someone's code and just handing it to them is generally discouraged here. You didn't even tell them what you fixed, just "Here ya go, I fixed it".

It's usually preferable to try to guide them towards a solution themselves, because fixing a problem on your own is much more of a learning experience than having the answer just given to you with no explanation.

Norm's rep comment is merely expressing his own feelings and the community sentiment on this. He is not limited to only commenting on things that violate a rule.

Sorry, but u can give me warning , not a negative point......

down-voting == I'm disagree with your answer, nothing else,

up-voting == your answer is excelent, nothing else,

then what's matter about points score, talking about nothing on all forums where I member of,

only I'm so too long time here, I have deepest knowledge about topics, then I obtain some up-vote sometimes, nothing else,

and (always) scoring system is very unfair, and don't expect any of clarification..., that's nonsence

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.