Anybody know why I my little application errors out when I click "Accept"?
Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Money extends JFrame implements ActionListener { //All of my items that will be placed on my panels JButton close; JButton accept; JTextField entryOne; JTextField entryTwo; JLabel lblOne; JLabel lblTwo; JLabel lblResults; TotalMoney amountOne; TotalMoney amountTwo; public Money() { super("Morgan"); Container container = getContentPane(); container.setLayout(new BorderLayout()); //Panels JPanel panelMain = new JPanel(); JPanel panelEntry = new JPanel(); JPanel panelResults = new JPanel(); panelEntry.setLayout(new GridLayout(5,2)); panelResults.setLayout(new GridLayout(2,1)); //Buttons accept = new JButton("Accept"); close = new JButton("Close"); //Text Fields entryOne = new JTextField(2); entryTwo = new JTextField(2); //Labels lblOne = new JLabel("First Amount"); lblTwo = new JLabel("Second Amount"); lblResults = new JLabel(); lblOne.setHorizontalAlignment(SwingConstants.RIGHT); lblTwo.setHorizontalAlignment(SwingConstants.RIGHT); lblResults.setHorizontalAlignment(SwingConstants.CENTER); //Add all items to panel panelMain.add(accept); panelMain.add(close); panelEntry.add(lblOne); panelEntry.add(entryOne); panelEntry.add(lblTwo); panelEntry.add(entryTwo); panelResults.add(lblResults); //Action Listener close.addActionListener(this); accept.addActionListener(this); //Add Panels to Frame container.add(panelMain,BorderLayout.SOUTH); container.add(panelEntry,BorderLayout.NORTH); container.add(panelResults,BorderLayout.CENTER); } //Main method public static void main(String[] args) { Money frame = new Money(); frame.setSize(300,200); frame.setVisible(true); } public void actionPerformed(ActionEvent event) { if(event.getSource() == close) //User has pressed the Close button { //Exit program gracefully System.exit(0); } if(event.getSource() == accept) //Use has pressed the Accept button { /* //Determine which is bigger if (entryOne.getText().compareTo(entryTwo.getText()) > 0) lblResults.setText(entryOne.getText() + " is bigger"); else lblResults.setText(entryTwo.getText() + " is bigger"); */ //Money Items amountOne = new TotalMoney("1.2"); // amountTwo = new TotalMoney(entryTwo.getText()); // System.out.println(amountOne + " " + amountTwo); }//End if }//End actionPerformed } //TotalMoney with 2 constructors class TotalMoney { long change; //Default constructor TotalMoney() { change = 0; } //Contructor that accepts an arg TotalMoney(String c) { change = Long.parseLong(c,10); } /* //Compare the amounts long compare() { //I have no clue what to do here.... UGH!! return change; } */ }




Reply With Quote