| | |
Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!!
![]() |
•
•
Join Date: Sep 2004
Posts: 14
Reputation:
Solved Threads: 0
Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!!
0
#1 May 8th, 2005
Hi there,
I have got this problem which is rather puzzling, to me at least.
My team-mate and I each did our coding and they work as standalone. His part is the UI and mine the backend processing.
He did his code using BlueJ using JDK 1.3, I did mine in JCreator using JDK 1.4.2_8. (I know its bad to not use the same version... :o but please read on.)
Apparently when compiling his code using BlueJ on my pc (WinXP), there were some compilation errors, and I fixed them. (Most prob due to different JDK versions. The error was in his type casting.) Compiled them again as standalone on my pc and they worked fine once more when i run them.
Now I tried to run his applet code with my code integrated, through BlueJ, by just integrating one simple function as a test. The applet opens and loads up. All the UI appears. Tried the function but cannot work. :eek:
Next I tried using JCreator to compile his code with mine, it compiled fine. Then I created a html file with the <applet> tags. It opens up the applet as before with all the UI buttons loaded but the integrated function cannot work. :eek:
Next I used the commands at command prompt:
"appletviewer sample.htm"
The applet opens up and works fine. The integrated command is working. :!:
The integrated command is opening a textfile and retrieve and store its contents into an arraylist. Upon user clicking a button on the UI, it would seek out the a particular cell of contents in the arraylist.
I did some debugging for the failed scenarios and discovered that my code could not find my myTextFile.txt file when it exists on the same directory. Tried to convert file type from unix to windows, still have the same problem. :cry:
Could someone please enlighten me on how to go about solving this problem please...
Very sincerely,
Rackus
Code:
UI Snipplet:
========
public class UIFILE extends JApplet implements MouseListener, ActionListener, ItemListener
{ .... ... //declaration of global variables
private TextArea TA = new TextArea (5,10);
myClassFile cs = new myClassFile;
... ... ...
public void actionPerformed ( ActionEvent e ) {
Object source = e.getSource();
... ...
if (source == getContent ) {
TA.append("Contents: "+cs.retrieveDetails("XXX"));
}
... ...
}
... ... ...
}
BackEndProcessing Snipplet:
=====================
pulic class myClassFile {
.....
//declaration of my global variables
readFile rf = new readFile();
..... ....
public myClassFile()
{
rf.openNstore(); //opens the txt file and stores it into an array list. as standalone it works.
}
... ...
public String retrieveDetails( String toCheckAgainst )
{
String result = rf.getValue(toCheckAgainst); //it gets the value. works as standalone.
return result;
}
... .... ...
}
I have got this problem which is rather puzzling, to me at least.
My team-mate and I each did our coding and they work as standalone. His part is the UI and mine the backend processing.
He did his code using BlueJ using JDK 1.3, I did mine in JCreator using JDK 1.4.2_8. (I know its bad to not use the same version... :o but please read on.)
Apparently when compiling his code using BlueJ on my pc (WinXP), there were some compilation errors, and I fixed them. (Most prob due to different JDK versions. The error was in his type casting.) Compiled them again as standalone on my pc and they worked fine once more when i run them.
Now I tried to run his applet code with my code integrated, through BlueJ, by just integrating one simple function as a test. The applet opens and loads up. All the UI appears. Tried the function but cannot work. :eek:
Next I tried using JCreator to compile his code with mine, it compiled fine. Then I created a html file with the <applet> tags. It opens up the applet as before with all the UI buttons loaded but the integrated function cannot work. :eek:
Next I used the commands at command prompt:
"appletviewer sample.htm"
The applet opens up and works fine. The integrated command is working. :!:
The integrated command is opening a textfile and retrieve and store its contents into an arraylist. Upon user clicking a button on the UI, it would seek out the a particular cell of contents in the arraylist.
I did some debugging for the failed scenarios and discovered that my code could not find my myTextFile.txt file when it exists on the same directory. Tried to convert file type from unix to windows, still have the same problem. :cry:
Could someone please enlighten me on how to go about solving this problem please...
Very sincerely,
Rackus
Code:
UI Snipplet:
========
public class UIFILE extends JApplet implements MouseListener, ActionListener, ItemListener
{ .... ... //declaration of global variables
private TextArea TA = new TextArea (5,10);
myClassFile cs = new myClassFile;
... ... ...
public void actionPerformed ( ActionEvent e ) {
Object source = e.getSource();
... ...
if (source == getContent ) {
TA.append("Contents: "+cs.retrieveDetails("XXX"));
}
... ...
}
... ... ...
}
BackEndProcessing Snipplet:
=====================
pulic class myClassFile {
.....
//declaration of my global variables
readFile rf = new readFile();
..... ....
public myClassFile()
{
rf.openNstore(); //opens the txt file and stores it into an array list. as standalone it works.
}
... ...
public String retrieveDetails( String toCheckAgainst )
{
String result = rf.getValue(toCheckAgainst); //it gets the value. works as standalone.
return result;
}
... .... ...
}
Re: Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!!
0
#2 May 8th, 2005
Well, I can't see anything from your code.. nor can I test it.
But my best guest is that you haven't actually given focus to the applet when you load it in an html page. When you load it in appletviewer, it is given focus (as it is obviously the only thing running). This is not the case in an html browser (because other items on the page may want focus or the browser simply doesn't give the applet focus for security reasons).
You have possibly tried clicking on the applet then seeing if it accepts user input events?
But my best guest is that you haven't actually given focus to the applet when you load it in an html page. When you load it in appletviewer, it is given focus (as it is obviously the only thing running). This is not the case in an html browser (because other items on the page may want focus or the browser simply doesn't give the applet focus for security reasons).
You have possibly tried clicking on the applet then seeing if it accepts user input events?
•
•
Join Date: Sep 2004
Posts: 14
Reputation:
Solved Threads: 0
Re: Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!!
0
#3 May 8th, 2005
Hi alpha_foobar,
I can't post up my whole code coz its over 20 class files. :o (unless you dun mind... )
As for giving focus, I don't really get you.
As for clicking on the applet to detect user inputs, yes, it works. but just in the backend makes no sense.
The applet in html is able to detect user input events. When I modify the code in actionPerformed(), to display a test message in a textarea after each button is clicked before attempting to call a function in my set of the code, it is able to display the test message.
E.g. I got 5 buttons. Upon clicking each button it will display "Going to retrieveDetails("XXX") now..." in the textarea. Then it calls that method and returns null. The problem is that it is not suppose to return null but a string instead.
The reason why it is returning null is because it can't find a certain textfile in the directory. But I made sure that the textfile exists. I checked the name and extension of the file. It is correct.
I checked the bufferedreader code to open that file to read in stuff. Its also correct.
Anyone able to help??
I can't post up my whole code coz its over 20 class files. :o (unless you dun mind... )
As for giving focus, I don't really get you.
As for clicking on the applet to detect user inputs, yes, it works. but just in the backend makes no sense.
The applet in html is able to detect user input events. When I modify the code in actionPerformed(), to display a test message in a textarea after each button is clicked before attempting to call a function in my set of the code, it is able to display the test message.
E.g. I got 5 buttons. Upon clicking each button it will display "Going to retrieveDetails("XXX") now..." in the textarea. Then it calls that method and returns null. The problem is that it is not suppose to return null but a string instead.
The reason why it is returning null is because it can't find a certain textfile in the directory. But I made sure that the textfile exists. I checked the name and extension of the file. It is correct.
I checked the bufferedreader code to open that file to read in stuff. Its also correct.
Anyone able to help??
Re: Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!!
0
#4 May 9th, 2005
it could just be cached...
open control panel
double click java
under "general" --> temporary internet files click delete files
make sure "downloaded applets" is checked
click ok, click ok
now try loading your applet again
open control panel
double click java
under "general" --> temporary internet files click delete files
make sure "downloaded applets" is checked
click ok, click ok
now try loading your applet again
Re: Help!! Applet only works in AppletViewer but not in html file with <applet> tags!
0
#5 May 9th, 2005
ahhh.. my bad i overlooked that part about reading a textfile.... on which computer is the file stored and how are you trying to read the file?
sandboxing of applets prevents them from opening files on your computer... what is the code that you are using to open the file... The UI code probably has nothing to do with this.
-- and i hadn't read the above post when i posted.
sandboxing of applets prevents them from opening files on your computer... what is the code that you are using to open the file... The UI code probably has nothing to do with this.
-- and i hadn't read the above post when i posted.
•
•
Join Date: Sep 2004
Posts: 14
Reputation:
Solved Threads: 0
Re: Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!!
0
#6 May 9th, 2005
Hi paradox814 and alpha_foobar,
paradox814:
I found a "Java-Plugin" in Control Panel, but can't find a General tab. (I'm using 1.4.2_8). So I went to "Internet Options" to delete all my cookies and offline files. Tried.. but the applet can't work.
Thanks though for trying to help me out.
alpha_foobar:
Currently, the textfile is stored on my computer (OS: winXP; a local system). If we ever get it all working, it would be applet running on client browser and retrieving the details from a server.
Sandboxing... hmm... did not do anything specifically sandboxing.
The code below works when not integrated with the UI. As in if I were to put print statements to check the retrieved values, the assgined values in an arraylist, they are all working as expected prior to integrating.
Help help...
paradox814:
I found a "Java-Plugin" in Control Panel, but can't find a General tab. (I'm using 1.4.2_8). So I went to "Internet Options" to delete all my cookies and offline files. Tried.. but the applet can't work.
Thanks though for trying to help me out.alpha_foobar:
Currently, the textfile is stored on my computer (OS: winXP; a local system). If we ever get it all working, it would be applet running on client browser and retrieving the details from a server.
Sandboxing... hmm... did not do anything specifically sandboxing.
The code below works when not integrated with the UI. As in if I were to put print statements to check the retrieved values, the assgined values in an arraylist, they are all working as expected prior to integrating.
Help help...
Java Syntax (Toggle Plain Text)
public class myFileReader{ private String myFile = "myFile.txt"; public fileReader() { readFile(myFile); } private void readFile(String filename) { String line; System.out.println("TEST filename:"+filename); try { BufferedReader buffer = new BufferedReader(new FileReader(filename)); while ((line = buffer.readLine()) != null) { storeLine(line); } buffer.close(); } catch (Exception e) { System.out.println("Exception occurred: /n" +e); System.exit(0); } } }
Re: Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!!
0
#7 May 9th, 2005
Sandboxing refers to the security levels of Java Applets...
Typically a Java Applet is downloaded from the internet, and so it would be a security risk if the applet could access arbitrary files on the client computer. It can however access arbitrary files from a server.
The 'sandbox' that a java applet runs in is supposed to symbolise an environment on a client computer, that can be played in without causing much of a mess. It is possible to get around sandboxing with signed code.
check out this link: http://www.securingjava.com/chapter-three/
Typically a Java Applet is downloaded from the internet, and so it would be a security risk if the applet could access arbitrary files on the client computer. It can however access arbitrary files from a server.
The 'sandbox' that a java applet runs in is supposed to symbolise an environment on a client computer, that can be played in without causing much of a mess. It is possible to get around sandboxing with signed code.
check out this link: http://www.securingjava.com/chapter-three/
Re: Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!!
0
#8 May 9th, 2005
This is perhaps a better link: http://java.sun.com/docs/books/tutor...y1.2/overview/
Re: Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!!
0
#9 May 9th, 2005
•
•
Join Date: Sep 2004
Posts: 14
Reputation:
Solved Threads: 0
Re: Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!!
0
#10 May 9th, 2005
Hi alpha_foobar,
Thank you for the links for sandboxing. I understand better now what is sandboxing.
But is there a way to get it to work locally, by running the applet through a html file on a local computer system with all the files in the same directory instead of using the appletviewer? The current setup i have is everything stored in the same directory on my pc.
Is it only possible for me to test it through a web browser via a html file only after the server is setup and I access the applet via a web browser on a client system?
Thank you once again for your url links about sandboxing. I really appreciate it.
Very sincerely,
rackus
Thank you for the links for sandboxing. I understand better now what is sandboxing.
But is there a way to get it to work locally, by running the applet through a html file on a local computer system with all the files in the same directory instead of using the appletviewer? The current setup i have is everything stored in the same directory on my pc.
Is it only possible for me to test it through a web browser via a html file only after the server is setup and I access the applet via a web browser on a client system?
Thank you once again for your url links about sandboxing. I really appreciate it.
Very sincerely,
rackus
![]() |
Similar Threads
- desktop html file missing (Windows NT / 2000 / XP)
- Can JMenuItem point to a HTML file that opens in IE? (Java)
- mailing html file (PHP)
- Opening HTML file from Program (Visual Basic 4 / 5 / 6)
- How to display a HTML file (in browser window) from Java Program...? (Java)
Other Threads in the Java Forum
- Previous Thread: Please anyone help tweak my code
- Next Thread: How do you pass objects as arguements?
| Thread Tools | Search this Thread |
-xlint 911 actionlistener addressbook android applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer csv database desktop developmenthelp eclipse error fractal ftp game gameprogramming givemetehcodez graphics gui health html image j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main method mobile netbeans notdisplaying number objects online oriented printf problem program projects qt recursion replaydirector reporting researchinmotion rotatetext rsa scanner screen se server set singleton sms sort sql string swing system test textfields threads time title tree tutorial-sample ubuntu update variablebinding windows xor





