[4824] in java-interest
Re: DOES ANY ONE SEE THIS MESSAGE, PLEASE HELP
daemon@ATHENA.MIT.EDU (trk@bilbo.wipsys.soft.net)
Tue Jan 16 05:03:42 1996
From: trk@bilbo.wipsys.soft.net
To: Jonathan_Mark_Smith@CCMAIL.PRUSEC.COM
Date: Tue, 16 Jan 1996 14:00:12 -0500 (GMT)
Cc: java-interest@java.sun.com (jig)
In-Reply-To: <95Dec15.113944est.2287@prufire1.prusec.com> from "Jonathan_Mark_Smith@CCMAIL.PRUSEC.COM" at Jan 15, 96 11:26:35 am
Jonathan_Mark_Smith@CCMAIL.PRUSEC.COM writes:
> I would like top build a applet that will read data from a file on my
> site and put the information in a textbox on the sceen and let the
> user change the information and save in my site.
Hi!
The following applet (quite sketchily written) reads a file from the
document base and displays its contents..
BTW, I imagine that when you wrote "my site", you are referring to the
host from which the Applet is loaded. Otherwise I do not think that it
is possible to to read a file on some other machine.
Hope this helps...
Cheers
TRK
=========================
import java.lang.System;
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class Test extends Applet {
String filename;
Reader stp;
Font firfont;
int x=0;
int y=0;
Vector lines;
URL docBase;
public void init() {
resize(600,200);
firfont = new java.awt.Font("TimesRoman",Font.BOLD, 36);
filename = getParameter("file");
System.out.println(filename);
docBase = getDocumentBase();
stp = new Reader(docBase,filename);
lines = stp.giveStrings();
}
public void paint(Graphics g) {
x=y=15;
for(int i=0; i < lines.size(); ++i){
g.drawString((String)lines.elementAt(i), x,y);
y=y+18;
}
}
}
class Reader {
DataInputStream dat;
String inps;
String filename;
Vector inpt;
public Reader(URL docBase,String f){
try{
dat = new DataInputStream( (new URL(docBase,f)).openStream());
} catch (MalformedURLException m){
System.out.println(e);
return;
} catch ( IOException ie){
return;
}
inpt = new Vector(4,2);
while(true){
try {
inps = dat.readLine();
if(inps != null){
inpt.addElement(inps);
}
else {
break;
}
} catch ( EOFException e){
break;
} catch ( IOException ie){
return;
}
}
}
public Vector giveStrings()
{
return (inpt);
}
}
=============
HTML File
=============
<title>SayHi</title>
<hr>
<applet code="Test.class" width=607 height=552>
<param name="file" value="foo.data">
</applet>
<hr>
<H1>Animation using JAVA</H1>
==============
--
_________________________________________________________________
T. Rama Kumar ph: 91-80-2210818
Wipro Systems e-mail: trk@bilbo.wipsys.soft.net
40/1A,Lavelle Road
Bangalore
India
-----------------------------------------------------------------
Life is too important to be taken seriously.
_________________________________________________________________
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com