Blackvein
Blackvein

Reputation: 558

Simple input/output applet with text boxes

I have a console application that uses System.out.println's to output text. What I want to do is turn it into an applet, where instead of System.out.println's, it displays the text in a text box. Is there a relatively easy way to convert this?

Upvotes: 0

Views: 3539

Answers (2)

Bart Kiers
Bart Kiers

Reputation: 170158

Is there a relatively easy way to convert this?

Sure, all you need to do is create an applet1 and add a single JTextArea2 to it. And then instead of your System.out.println(str)'s, you do textArea.setText(str) (or textArea.setText(textArea.getText() + "\n" + str) to append text)

  1. http://download.oracle.com/javase/tutorial/deployment/applet/
  2. http://download.oracle.com/javase/tutorial/uiswing/components/textarea.html

EDIT

And to get user input, checkout the showInputDialog method from the JOptionPane class. Examples can be found here:

Upvotes: 0

camickr
camickr

Reputation: 324118

Message Console is a simple class that will allow you to redirect ouput to a JTextArea or JTextPane.

Upvotes: 2

Related Questions