Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Transferring console output to a textArea....how to make this happen?

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Thanked 0 Times in 0 Posts

    Default Transferring console output to a textArea....how to make this happen?

    import java.util.ArrayList;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ThreeArrayLists extends JFrame {
    private static final long serialVersionUID = 1L;
    public ThreeArrayLists(){
    	setLayout(new FlowLayout());
    	JButton button = new JButton("Press");
    	JLabel label1 = new JLabel("Three Array Lists");
    	JTextArea textArea;
    	textArea = new JTextArea(200, 200);
    	buttonHandler bHandle = new buttonHandler();
    	class buttonHandler implements ActionListener {
    		public void actionPerformed(ActionEvent e)
    			ArrayList<Double> priceList = new ArrayList<Double>();
    			ArrayList<Double> quantityList = new ArrayList<Double>();
    			ArrayList<Double> amountList = new ArrayList<Double>();
    			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));
    			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));
    				for (int i = 0; i < 10; i++) {
    					amountList.add((Double.valueOf(priceList.get(i).toString())) * (Double.valueOf(quantityList.get(i).toString())));
    			textArea.setText(String.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()));	
    			System.out.printf("%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()));
    public static void main(String[] args){
    	ThreeArrayLists newArray = new ThreeArrayLists();

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 698 Times in 680 Posts

    Default Re: Transferring console output to a textArea....how to make this happen?

    Why would you mix console input/output and graphical input/output in the same program? That's annoying.

    The answer to your question is relatively simple. How do you normally get the user's input from the console? What is that object, or what could that input object be to be most convenient? What does a JTextArea contain? What do you write to a JTextArea, and how do you write to it? If you can answer those questions, you can answer your own post.

Similar Threads

  1. How to make console output bold
    By ColeTrain in forum Java Theory & Questions
    Replies: 6
    Last Post: October 16th, 2012, 09:54 AM
  2. [SOLVED] Is there a way to make things happen if a certain text is entered in a TextField?
    By DusteroftheCentury in forum Java Theory & Questions
    Replies: 25
    Last Post: January 26th, 2012, 08:14 PM
  3. Having problems with output to console....help!
    By toppcon in forum What's Wrong With My Code?
    Replies: 21
    Last Post: July 13th, 2011, 06:38 PM
  4. Store Values in 2D array and output to textarea
    By raverz1tildawn in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 7th, 2011, 03:13 PM
  5. Changing output from console to .html
    By RSYR in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: December 10th, 2009, 07:55 PM