1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java project output problem. Can't output objects from a method.

  1. Apr 13, 2008 #1
    I'm trying to create a bookstore calculation program with two classes, a presentation and computation class. Here is my code for the presentation class:
    Code (Text):
    import javax.swing.*;
    import java.awt.event.*;
    import java.text.*;
    import java.awt.*;

    public class ch4Book extends JFrame implements ActionListener
    {

        // All the GUI objects
        JPanel mainPanel = new JPanel();
        JLabel companyLabel = new JLabel("       OrderBook Inc.         ");
        JTextField titleTextField = new JTextField(30);
        JTextField quantityTextField = new JTextField(15);
        JTextField priceTextField = new JTextField(15);
        JButton calculateButton = new JButton(" Calculate   ");
        JTextArea outputTextArea = new JTextArea("Your Total Cost:", 10, 25);
        JScrollPane outputScrollPane = new JScrollPane(outputTextArea);
       

       
       
        public static void main(String[] args)
        {
            //create an object of the class and code the close button
            ch4Book myCost = new ch4Book();
            myCost.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
       
        public ch4Book()
        {
            designFrame();
        }
       
        public void designFrame()
        {
            //add the components to the mainPanel
            mainPanel.add(companyLabel);
            mainPanel.add(new JLabel("       Title            "));
            mainPanel.add(titleTextField);
            mainPanel.add(new JLabel("    Quantity   "));
            mainPanel.add(quantityTextField);
            mainPanel.add(new JLabel("    Price       "));
            mainPanel.add(priceTextField);
            mainPanel.add(calculateButton);
            mainPanel.add(outputScrollPane);
           
            //add the listeners
            calculateButton.addActionListener(this);
           
           
            //add the panel to the frame
            add(mainPanel);
            setSize(500,500);
            setVisible(true);
           
        }
       
        public void actionPerformed(ActionEvent evt)
        {
            getInput();
            displayOutput();
            clear();
           
        }
       
        public void getInput()
        {
            //input variables

            double  priceDouble;
            int quantityInteger;
            String titleString;
           

            priceDouble = Double.parseDouble(priceTextField.getText());
            quantityInteger = Integer.parseInt(quantityTextField.getText());
            titleString = titleTextField.getText();
           
           
            //send the input the calculation class
            Cost myTotalCost = new Cost(priceDouble, quantityInteger);
            displayOutput();
           
           
        }
       
        public void displayOutput()
        {
            // object to format to currency
            DecimalFormat formatDecimalFormat = new DecimalFormat("$0.00");
           
            //variables to store the retrieved values from the computation class
            double  subTotalDouble, totalCostDouble;
            int counterInteger;
           
            Cost myTotalCost = new Cost();
           
            subTotalDouble = myTotalCost.getSubTotal();
            totalCostDouble = myTotalCost.getTotalCost();
            counterInteger = myTotalCost.getCounterInteger();
           
           
            outputTextArea.append('\n' + "Book Title:  " + titleString +
                    '\n' + " Quantity  " + formatDecimalFormat.format(quantityInteger)+
                    '\n' + "Number of Customers  " + counterInteger);
           
           
        }
       
        public void clear()
        {
            titleTextField.setText("");
            quantityTextField.setText("");
            priceTextField.setText("");
        }
    }
     
    Problem is, I'm unable to output the variables and objects from getInput()

    I'm not sure why.. can someone help me with this?
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you help with the solution or looking for help too?



Similar Discussions: Java project output problem. Can't output objects from a method.
  1. JAVA indexOf() method (Replies: 0)

  2. Measurement Method (Replies: 0)

  3. Scanner Help? (java) (Replies: 0)

Loading...