[ zafa @ 15.11.2007. 12:18 ] @
Problem je u sledecem:
aplet koji u nastavku sledi ima u kodu zadatu tekstualnu datoteku
kako modifikovati aplet tako da prihvata ime datoteke kao patametar apleta zadat u HTML kodu
kako modifikovati HTML kod da prihvati paramatar

u nastavku sledi kod java apleta i kod HTML-a

java aplet

import java.net.*;
import java.io.*;
public class textreader extends java.applet.Applet implements Runnable
{ Thread thread;
URL url;
String output;
String fileName="p.txt";/* ovo je ime tekstalne datoteke*/
public void getFile(String fileName) throws IOException {



String result, line;
InputStream connection;
DataInputStream dataStream;
StringBuffer buffer = new StringBuffer();
try {
url = new URL(getDocumentBase(),fileName);
}
catch (MalformedURLException e) {
output = "AppletError " + e;
}
try {
connection = url.openStream();
dataStream = new DataInputStream(new BufferedInputStream(connection));
while ((line = dataStream.readLine()) != null) {
buffer.append(line + "\n");
}
result = buffer.toString();
}
catch (IOException e) {
result = "AppletError: " + e;
}
output = result;
}
public String fetchText() {
return output;
}
public void init() {
}
public void start() {
if (thread == null) {
thread = new Thread(this);
thread.start();
}
}
public void stop() {
if (thread != null) {
thread.stop();
thread = null;
}
}
public void run(){
try {
getFile(fileName);
}
catch (IOException e) {
output = "AppletError: " + e;
}
}
}

html kod:
<HTML>
<HEAD>
<TITLE>Letting an Applet Do The Work</TITLE>
<SCRIPT LANGUAGE="JavaScript1.1">
function getFile(form) {
var output = document.readerApplet.fetchText()
form.fileOutput.value = output
}
function autoFetch() {
var output = document.readerApplet.fetchText()
if (output != null) {
document.forms[0].fileOutput.value = output
return
}
var t = setTimeout("autoFetch()",1000)
}
</SCRIPT>
</HEAD>
<BODY onLoad="autoFetch()">

<H1>Text from a text file...</H1>
<FORM NAME="reader">
<INPUT TYPE="button" VALUE="Get File" onClick="getFile(this.form)">
<P>
<TEXTAREA NAME="fileOutput" ROWS=10 COLS=60 WRAP="hard"></TEXTAREA>
<P>
<INPUT TYPE="Reset" VALUE="Clear">
</FORM>
<APPLET CODE="textreader.class" NAME="readerApplet" WIDTH=1 HEIGHT=1>

</APPLET>
</BODY>
</HTML>
[ bgd2500 @ 15.11.2007. 15:21 ] @
<APPLET CODE="textreader.class" NAME="readerApplet" WIDTH=1 HEIGHT=1>
<PARAM NAME="filename" VALUE="p.txt"/>
</APPLET>

U apletu ga dohvatas sa:

String fileName = getParameter("filename");

[ zafa @ 16.11.2007. 09:07 ] @
Dobio sam textreader.class ali html i dalje ne zeli da cita textualnu datoteku
koju sam preneo, ne znam gde gresim
[ bgd2500 @ 16.11.2007. 16:42 ] @
Aplet je zakomplikovan vise nego sto bi trebalo, ali radi.
Hint:

String filename;
....
public void init() {
fileName = getParameter("filename");
}

[ zafa @ 19.11.2007. 16:05 ] @
Hvala, uocio sam gresku i ispravio.
>
>
> __________ NOD32 2665 (20071117) Information __________
>
> This message was checked by NOD32 antivirus system.
> http://www.eset.com
>
>