I am having trouble writing code to multiply the fields times the number put in to equal the total. I was able to make the clear button work
/*
* Order1.java
*
* Created on December 18, 2006, 6:16 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author test
*/
import java.awt.*;
import java.awt.event. ActionEvent;
import java.awt.event. ActionListener;
import javax.swing.*;
public class Order1
{
public static void main(String[] args)
{
MyOrder1 myFrame = new MyOrder1() ;
myFrame.setVisi ble(true) ;
}
}
class MyOrder1 extends JFrame implements ActionListener
{
private static final int WIDTH = 225 ;
private static final int HEIGHT = 150 ;
private static final int X_ORIGIN = 400 ;
private static final int Y_ORIGIN = 200 ;
// create new buttons and label them
private JButton Total ;
private JButton Reset ;
private JTextField ChickenField ;
private JTextField PorkField ;
private JTextField CattleField ;
//creates new label icons for my items
public MyOrder1()
{
String Response = new String() ;
JLabel Chicken = new JLabel("Chicken : $1.19 LB ") ;
JLabel Pork = new JLabel("Pork: $2.17 LB ") ;
JLabel Cattle = new JLabel("Cattle: $3.27 LB ") ;
ChickenField = new JTextField(5) ;
PorkField = new JTextField(5) ;
CattleField = new JTextField(5) ;
Total = new JButton("Total" ) ;
Total.addAction Listener(this) ;
Reset = new JButton("Reset" ) ;
Reset.addAction Listener(this) ;
// get the content pane
Container contentPane = getContentPane( ) ;
// create a new layout manager for the pane
FlowLayout aLayout = new FlowLayout() ;
// assign the new layout manager to the content pane
contentPane.set Layout(aLayout) ;
// add the "Exit" button to the content pane
contentPane.add (Chicken) ;
contentPane.add (ChickenField) ;
contentPane.add (Pork) ;
contentPane.add (PorkField) ;
contentPane.add (Cattle) ;
contentPane.add (CattleField) ;
contentPane.add (Total) ;
contentPane.add (Reset) ;
setDefaultClose Operation(JFram e.EXIT_ON_CLOSE );
setBounds(X_ORI GIN, Y_ORIGIN, WIDTH, HEIGHT) ;
}
public void actionPerformed (ActionEvent e)
{
Object source = e.getSource() ;
if (source == Reset)
{
ChickenField.se tText(" ") ;
PorkField.setTe xt(" ") ;
CattleField.set Text(" ") ;
}
else if (source == Total)
/*
* Order1.java
*
* Created on December 18, 2006, 6:16 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author test
*/
import java.awt.*;
import java.awt.event. ActionEvent;
import java.awt.event. ActionListener;
import javax.swing.*;
public class Order1
{
public static void main(String[] args)
{
MyOrder1 myFrame = new MyOrder1() ;
myFrame.setVisi ble(true) ;
}
}
class MyOrder1 extends JFrame implements ActionListener
{
private static final int WIDTH = 225 ;
private static final int HEIGHT = 150 ;
private static final int X_ORIGIN = 400 ;
private static final int Y_ORIGIN = 200 ;
// create new buttons and label them
private JButton Total ;
private JButton Reset ;
private JTextField ChickenField ;
private JTextField PorkField ;
private JTextField CattleField ;
//creates new label icons for my items
public MyOrder1()
{
String Response = new String() ;
JLabel Chicken = new JLabel("Chicken : $1.19 LB ") ;
JLabel Pork = new JLabel("Pork: $2.17 LB ") ;
JLabel Cattle = new JLabel("Cattle: $3.27 LB ") ;
ChickenField = new JTextField(5) ;
PorkField = new JTextField(5) ;
CattleField = new JTextField(5) ;
Total = new JButton("Total" ) ;
Total.addAction Listener(this) ;
Reset = new JButton("Reset" ) ;
Reset.addAction Listener(this) ;
// get the content pane
Container contentPane = getContentPane( ) ;
// create a new layout manager for the pane
FlowLayout aLayout = new FlowLayout() ;
// assign the new layout manager to the content pane
contentPane.set Layout(aLayout) ;
// add the "Exit" button to the content pane
contentPane.add (Chicken) ;
contentPane.add (ChickenField) ;
contentPane.add (Pork) ;
contentPane.add (PorkField) ;
contentPane.add (Cattle) ;
contentPane.add (CattleField) ;
contentPane.add (Total) ;
contentPane.add (Reset) ;
setDefaultClose Operation(JFram e.EXIT_ON_CLOSE );
setBounds(X_ORI GIN, Y_ORIGIN, WIDTH, HEIGHT) ;
}
public void actionPerformed (ActionEvent e)
{
Object source = e.getSource() ;
if (source == Reset)
{
ChickenField.se tText(" ") ;
PorkField.setTe xt(" ") ;
CattleField.set Text(" ") ;
}
else if (source == Total)
Comment