Wow, where to start because you have quite a few things wrong here. Lets start with the simple.
1. In your main at the bottom you have curly braces rather than square brackets after "String" remember it is a string array.
2. Second you have a bunch of variables defined and not used and using variables that are not defined. My guess is that you went with one set of names and changed them mid way through development. One such example is "myName" and "name". Another is "costTotal" and "totalBill".
3. Another is that you aren't setting your Jlabels in your "try" part of your try catch so you are not going to see output.
4. You needed a space between the words "new" and "FlowLayout"
Now once you fix these you have to put in some code for your actionListener. Remember the actionListener is going to need to listen for a specific event from the button, in this case an "actionPerformed". This is defined as an anonymous function or in this case an inline class.
Lastly to print out the results to your Jlabels you are going to have to wrap your primitive doubles into a Double class and using toString() to print it to the Jlabels.
Below is a fully functioning and tested solution correcting all the problems above.
CODE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Restaurant extends JFrame
{
private Container contents;
private JLabel name, courseNum, welcome, prompt, chickP, fishP;
private JLabel chargeSand, chargeService, totalBill;
private JTextField numChick, numFish;
private JButton compute;
public Restaurant()
{
super("Barker's Menu");
contents = getContentPane();
contents.setLayout(new FlowLayout());
name=new JLabel("Programmer: Jake Reibert");
courseNum=new JLabel("CSI 161/875");
welcome=new JLabel("Welcome To Barker's Sandwich Shop");
prompt=new JLabel("Enter # of Sandwiches for each; 0 if none");
chickP=new JLabel("Chicken Sandwiches @ $4.59 each");
chickP.setForeground(Color.BLUE);
numChick=new JTextField(3);
fishP=new JLabel("Salmon Sandwiches @ $4.99 each");
fishP.setForeground(Color.BLUE);
numFish=new JTextField(3);
chargeSand = new JLabel("Charge for Sandwiches = $");
chargeService = new JLabel("Charge for Service = $");
totalBill= new JLabel("Total Bill = $");
chargeSand = new JLabel("???");
chargeService = new JLabel("???");
totalBill = new JLabel("???");
compute = new JButton("Calculate Bill");
contents.add(name);
contents.add(courseNum);
contents.add(welcome);
contents.add(prompt);
contents.add(chickP);
contents.add(numChick);
contents.add(fishP);
contents.add(numFish);
contents.add(chargeSand);
contents.add(chargeService);
contents.add(totalBill);
contents.add(chargeSand);
contents.add(chargeService);
contents.add(totalBill);
contents.add(compute);
ButtonHandler bh = new ButtonHandler();
compute.addActionListener(bh);
setSize(400,400);
setVisible(true);
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e) {
try
{
double one = Double.parseDouble(numChick.getText());
double two = Double.parseDouble(numFish.getText());
// Calculations for determining total price of bill
double orderAmount = (one*4.59)+(two*4.99);
double toppingsPrice = (one+two)*.70;
double serviceAmount = (orderAmount+toppingsPrice)*.15;
double totalAmount = (orderAmount+toppingsPrice+serviceAmount);
// Now to display the charges
chargeSand.setText(new Double(orderAmount).toString());
chargeService.setText(new Double(serviceAmount).toString());
totalBill.setText(new Double(totalAmount).toString());
}
catch(NumberFormatException ex)
{
numChick.setText("Enter a Number");
numFish.setText("");
totalBill.setText("???");
}
}
}
public static void main(String[] args)
{
Restaurant rest= new Restaurant();
rest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Of course this project still needs further work for error handling and such.
This post has been edited by Martyr2: 3 Jul, 2007 - 02:11 PM