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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 2 of 2

Thread: Input and Output in JTextFields and JTextAreas - Interactive Fiction

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Input and Output in JTextFields and JTextAreas - Interactive Fiction

    import java.awt.FlowLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.JPasswordField;
    import javax.swing.JOptionPane;
     
    public class eventtuna extends JFrame {
     
    private JTextArea outputitem;
    private JTextField inputitem;
     
    public eventtuna(){
    super("한글");
    setLayout(new FlowLayout());
    outputitem = new JTextArea("", 20, 40);
    outputitem.getScrollableTracksViewpo…
    outputitem.setEditable(false);
    add(outputitem);
     
    inputitem = new JTextField(10);
    add(inputitem);
     
    thehandler handler = new thehandler();
    inputitem.addActionListener(handler)…
    }
    public class thehandler implements ActionListener{
     
    public void actionPerformed(ActionEvent eventvar){
    String stringvar = "";
    if(eventvar.getSource()==inputitem)
    stringvar = String.format("%s", eventvar.getActionCommand());
    outputitem.setText(stringvar);
     
    }
    }
     
    }
    This all works fine, and what it does is allow you to input text in the JTextField that is ouptut in the JTextArea. The problem is, I want to beable to input text, have it output in the textarea, and then have it let you input text again and have it output on the next line down in the textarea. I need to to beable to keep doing this as well to beable to scroll as the textarea fills up.

    Please help,
    Thanks


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Input and Output in JTextFields and JTextAreas - Interactive Fiction

    And where are you stuck? What's your actual question?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] Need help with input/output error
    By stefan2892 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 7th, 2011, 10:44 AM
  2. Creating Methods for Input/Output Files
    By PapaGL0VE in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 17th, 2010, 10:07 AM
  3. [SOLVED] T_T [hellllppppp] Input/Output
    By bontet in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: October 29th, 2010, 11:32 AM
  4. Input/Output file help
    By Plural in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 25th, 2010, 08:34 PM
  5. Input/Output file help
    By Plural in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 23rd, 2010, 06:26 PM