I need help making this to display the results into a Jframe GUI instead of a console im failry new to java so please help me thanks, here is the code ive used:

import java.util.ArrayList;

public class ThreeArrayLists {

    public static void main(String[] args) {
        ArrayList priceList = new ArrayList();
        ArrayList quantityList = new ArrayList();
        ArrayList amountList = new ArrayList();
        //PRICE lIST
        priceList.add(new Double(10.62));
        priceList.add(new Double(14.89));
        priceList.add(new Double(13.21));
        priceList.add(new Double(16.55));
        priceList.add(new Double(18.62));
        priceList.add(new Double(9.47));
        priceList.add(new Double(6.58));
        priceList.add(new Double(18.32));
        priceList.add(new Double(12.15));
        priceList.add(new Double(3.98));
        //QUANTITY LIST   
        quantityList.add(new Double(4.0));
        quantityList.add(new Double(8.5));
        quantityList.add(new Double(6.0));
        quantityList.add(new Double(7.35));
        quantityList.add(new Double(9.0));

        quantityList.add(new Double(15.3));
        quantityList.add(new Double(3));
        quantityList.add(new Double(5.4));
        quantityList.add(new Double(2.9));
        quantityList.add(new Double(4.8));

        extend(amountList, quantityList, priceList);
        displayList(quantityList, priceList, amountList);


    }

    private static void displayList(ArrayList quantityList, ArrayList priceList, ArrayList amountList)  {

        for (int i = 0; i < 10; i++) {

            System.out.format("%d)  %.2f * %.2f = %.2f \n",i+1, Double.valueOf(priceList.get(i).toString()), Double.valueOf(quantityList.get(i).toString()), Double.valueOf(amountList.get(i).toString()));
        }
    }

    private static void extend(ArrayList amountList, ArrayList quantityList, ArrayList priceList) {

        for (int i = 0; i < 10; i++) {
            amountList.add((Double.valueOf(priceList.get(i).toString())) * (Double.valueOf(quantityList.get(i).toString())));

        }

    }
}

Recommended Answers

All 5 Replies

Where do you define the JFrame? If this is your first atempt at writing a GUI program, it is not as simple as you would like. To start you should read the java tutorial:
http://docs.oracle.com/javase/tutorial/uiswing/index.html
There is a lot to cover before you will be able to convert this code to use a GUI.

I havente declared the Jframe becasue i am only using a console in this example, just trying to get a visual example...and yesi have been to that link and used it quite often thanks

Your use of ArrayLists corresponds to how Java was years ago, before version 1.5, and that's why your calculations (line 50) are difficult.
With modern Java you can declare what kind of Objects the ArrayList can hold, eg
ArrayList<Double> priceList = new ArrayList<Double>();
now Java knows the contents will always be Doubles, so priceList.get(i) will always return a Double, so you can just use it, eg
amountList.add(priceList.get(i) * quantityList.get(i));

Let us know how you are getting on with yout GUI.

I am actualy working on the same program and have also been able to create a GUI and show console output, but can not get the console output to display in my GUI, specifically a textArea.

Hi jakhondi
Welcome to DaniWeb

Please start your own new thread for your question, and explain exactly what the problem is, and post the relevant code so someone can help you.

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.