?
Solved

Java Applet data into a HTML document

Posted on 2003-03-31
29
Medium Priority
?
237 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:decswxaqz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 13
  • 3
29 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8237694
 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
 
LVL 35

Expert Comment

by:TimYates
ID: 8237699
applet Copying to the  clipboard
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8237700
oops...ignore me ;-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:girionis
ID: 8237727
 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
 

Author Comment

by:decswxaqz
ID: 8238075
@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
 
LVL 35

Expert Comment

by:girionis
ID: 8238169
 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
 
LVL 35

Expert Comment

by:girionis
ID: 8238179
 If you can post a small compilable example I can help you do it.
0
 

Author Comment

by:decswxaqz
ID: 8238357
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
 
LVL 35

Expert Comment

by:girionis
ID: 8238489
 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
 

Author Comment

by:decswxaqz
ID: 8238597
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
 

Author Comment

by:decswxaqz
ID: 8238644
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
 
LVL 35

Accepted Solution

by:
girionis earned 1050 total points
ID: 8238647
 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
 

Author Comment

by:decswxaqz
ID: 8238725
Link not working.
0
 

Author Comment

by:decswxaqz
ID: 8238806
I will try all of this when I get back home on my PC
0
 
LVL 35

Expert Comment

by:girionis
ID: 8238821
0
 

Author Comment

by:decswxaqz
ID: 8238892
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
 
LVL 35

Expert Comment

by:girionis
ID: 8238926
 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
 
LVL 35

Expert Comment

by:TimYates
ID: 8239168
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
 

Author Comment

by:decswxaqz
ID: 8239435
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
 

Author Comment

by:decswxaqz
ID: 8240014
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
 
LVL 35

Expert Comment

by:girionis
ID: 8240044
 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
 

Author Comment

by:decswxaqz
ID: 8240118
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
 
LVL 35

Expert Comment

by:girionis
ID: 8241432
 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
 

Author Comment

by:decswxaqz
ID: 8241678
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
 
LVL 35

Expert Comment

by:girionis
ID: 8244017
 I can't see the applet. What is the problem? Do you get any error messages?
0
 

Author Comment

by:decswxaqz
ID: 8244297
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
 
LVL 35

Expert Comment

by:girionis
ID: 8244318
 If you tell me what errors you are getting I might be able to give you some hints :-)
0
 

Author Comment

by:decswxaqz
ID: 8244354
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
 
LVL 35

Expert Comment

by:girionis
ID: 8244417
 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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question