Java Applet data into a HTML document

I want to create a simple program that lets a user enter data and then converts/puts it into HTML format with tags.

For example,
The java applet contains 3 text fields (first, middle, and last name). A user enters information and then the applet stores it in an array or string. The user can then enter more information. Then when the user clicks a button it produces the code necessary to put it into a table in HTML or just a list.
(to signify seperate boxes I am using ,)

User enters in applet:  Bob,,Smith     Fred,Paul,Johnson     James,Frederick,Jones

I would like it to show the HTML code so that someone can copy it to a HTML file

Example output:
<p>Bob Smith
<p>Fred Paul Johnson
<p>James Frederick Jones

I want it to show the tags as well. So that someone can just copy that code into a HTML file and that will show:

Bob Smith
Fred Paul Johnson
James Frederick Jones

I have tried using text fields but you can't seem to copy data from them and if you use drawString you can't copy that data. I have tried passing parameters using ? in the web address but how could I convert that into copyable HTML code.

I only need code of how to convert user input into copyable code. If you can do it using textfields or textarea (if it exists :S) then please tell me. I think it can be done using JavaScript but I don't know enough to do it.

Thanks
decswxaqzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
 YOu can do it with text area, yes. Lets say that your text field instance is called "textField" and your text area instance is called "textArea". Then you can so something like:

// reads the text from the text field.
String text = textField.getText();

// appends the etxt into the text area.
textArea.append("<p>" + text + "</p>");

  Hope it helps.
0
TimYatesCommented:
applet Copying to the  clipboard
0
TimYatesCommented:
oops...ignore me ;-)
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

girionisCommented:
 I'll go into a bit more detail. If you have a 3 text fields you can put them into an array by doing:

  String myArray [] = new String[3];

  myArray[0] = textField1.getText();
  myArray[1] = textField2.getText();
  myArray[2] = textField3.getText();

  Now you can create a table HTML in your text area by doing:

   textArea.append("<table>");
   textArea.append("    <tr>");
   for (int i=0; i<myArray.length; i++)
   {
      textArea.append("        <td>");
      textArea.append("            " + myArray[0]);
      textArea.append("        </td>");
   }
   textArea.append("    </tr>");
   textArea.append("</table>");
0
decswxaqzAuthor Commented:
@girionis
What I need to know, please, is how to make it copyable? I can do all the array/string manipulation but actually getting it to output so that people can copy it is what I am stupmped on. Can you copy from textfields or textareas (Do they exist? What params do I need?)? If so, why can't I copy text from the applet from Linux? I do have Java at home on my PC but mostly play games there! :P .

@timyates
OK :D ;)


btw. I think I could do it by writing a text file but I would be hosting the applet on Geocities and they won't allow that I think.
0
girionisCommented:
 Yes you can copy from both text fields and text areas but you will need to implement clipboard functionality. Applets do not allow it by default. You will also need to give permissions to applet to access the clipboard: permission java.awt.AWTPermission "accessClipboard";
0
girionisCommented:
 If you can post a small compilable example I can help you do it.
0
decswxaqzAuthor Commented:
ok. I mage a quick example but I don't thinks it's working :@ :'(
http://www.geocities.com/decswxaqz/names.html . I just need to know where to get that code piece. Thanks. You have been a great help girionis.
0
girionisCommented:
 Well I just tried your applet. It works fine if I select the text and then do a right mouse click. I can copy the text. Do you want to have the same functionality with a button?
0
decswxaqzAuthor Commented:
Oh. But I haven't implemented your AWTPermission thing! Are you able to paste it and everything is fine? You must be able to copy text from a textarea on a PC but not from Linux. Yes if you could implement a button to copy the text to the clipboard so people could just press CTRL+V that would be great.
Would you be so kind as to copy that code I put on the web site and put in the permission java.awt.AWTPermission code snippet? That is if the button thingy doesn't work.

Thanks for all your help
0
decswxaqzAuthor Commented:
Oh. But I haven't implemented your AWTPermission thing! Are you able to paste it and everything is fine? You must be able to copy text from a textarea on a PC but not from Linux. Yes if you could implement a button to copy the text to the clipboard so people could just press CTRL+V that would be great.
Would you be so kind as to copy that code I put on the web site and put in the permission java.awt.AWTPermission code snippet? That is if the button thingy doesn't work.

Thanks for all your help
0
girionisCommented:
 I have implemented a clipboard applet in the past and I remember it asked me for accessClipboard permissions. Anyway, I cannot access your applet (I get a "bad magic numebr" error) so I put it on the web server I am currently working on. take a look and tell me if it's working:

http://195.110.86.117:8080/panos/pso.htm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
decswxaqzAuthor Commented:
Link not working.
0
decswxaqzAuthor Commented:
I will try all of this when I get back home on my PC
0
girionisCommented:
0
decswxaqzAuthor Commented:
Ok. I on a PC now and it works. If only I had waited until I was on a PC I wouldn't have wasted 350 points. Oh well. I will give you the answer when I get home.
0
girionisCommented:
 Shouldn't matter if you are using Linux or Windows. It should work on both exactly the same. And btw you do not have to give me the points :-)
0
TimYatesCommented:
dunno what it's supposed to do...but it doesn't do it on Linux with Netscape and JDK 1.4.1

Maybe the text areas are just too wide for me to see that's going on?
0
decswxaqzAuthor Commented:
Yeah I know it shouldn't matter but it does! lol. I shall give you the points because it was my fault about the platform thing and I honour all my agreements. Besides, you at least tried. However, go to http://www.geocities.com/decswxaqz/hotel.html . Everyone I told to go there couldn't see the pie chart type thing in the bottom right corner. Any ideas? Different java versions. I have given you the points. Thanks.
0
decswxaqzAuthor Commented:
I was wondering if you could help me with positioning buttons, textfields etc wherever I want from a standalone web applet. I have looked on the web but they run from like normal and open an applet window. Could you email me or add me to MSN. My email is henderson_luke@hotmail.com
0
girionisCommented:
 I can see a pie chart thing on my browser (Opera 7.01 with 1.4 JRE) on the right hand corner (not sure if you can consider it bottom right) with 3 blue pieces and the rest are red.

>  was wondering if you could help me with positioning buttons, textfields etc wherever I want from a standalone web applet

  I'll do my best but it is always better to post here since this could help other people with similar problems as well.
0
decswxaqzAuthor Commented:
Thanks for looking at it. Hmmmm. Must be the other people's versions of Java then.

I just want to specify where buttons, labels and textfields go with coordinates like you can with drawString. However, it seems like you have to use layout managers and the examples I have found so far (I use NetBeans for Java programming) run from within NetBeans instead of an appletviewer or HTML file. Which layout manager would be best and easiest to do this?
0
girionisCommented:
 Not sure which one is best... Try GridLayout since you can divide the area you want into grids and you can put the components wherever you want them to be. If you just want to use the drawString method though it might be easier ust to speficy coordinates for it.
0
decswxaqzAuthor Commented:
http://www.geocities.com/decswxaqz/pso2.html
Damn that took ages just to get the layout right.
Had to use cardlayout with two borderlayouts containing the buttons with each card having a borderlayout with the centre panel being a grid layout. Now just to make it work. :'( :@ :(
0
girionisCommented:
 I can't see the applet. What is the problem? Do you get any error messages?
0
decswxaqzAuthor Commented:
I can see the applet but it is probably in my cache hiding. I can see it but I get errors in the status bar. Doesn't matter unless you have PSO. Lol. Thanks for your help.
0
girionisCommented:
 If you tell me what errors you are getting I might be able to give you some hints :-)
0
decswxaqzAuthor Commented:
Don't know the errors, just says the page loaded with errors in status bar. Works fine in appletviewer. Doesn't matter. Nothing works yet so I will deal with problems when I get it to do something. Lol.
0
girionisCommented:
 You can always look at the Java console for error messages. If it works in appletviewer then I'd say it's probably some security issues.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.