Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to display a applet?

 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've wrote a applet and a html, when open the html with IE6, there's always a gray box there? I don't know why I cannot display it. I can just play it well in a appletviewer.
I use inner class in my applet, does that matter?
pls help me, thx a lot.
 
Caven Wang
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
show me your code including applet and html. without code, how can we identify your problem?!
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java file:
package test;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.FileInputStream;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class ReadFileApplet extends Applet {
TextArea text = new TextArea();
Button goButton = new Button("Read Local File");
Panel panel = new Panel();
String fileName = "";
public void init(){
fileName = getParameter("fileName");
setLayout(new BorderLayout());
goButton.addActionListener(new ButtonHandler());
panel.add(goButton);
add("North",panel);
add("Center",text);
}
class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
String s = e.getActionCommand();
if("Read Local File".equals(s)){
try{
FileInputStream inStream = new FileInputStream(fileName);
int inBytes = inStream.available();
byte inBuf[] = new byte[inBytes];
int bytesRead = inStream.read(inBuf,0,inBytes);
text.setText(new String(inBuf));
}catch(Exception ex){
text.setText(ex.toString());
}
}
}
}
}
html file:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>
An Applet that reads local files.
</title>
</head>
<body>
test.ReadFileApplet will appear below in a Java enabled browser.<br>
<applet
codebase = "."
code = "test.ReadFileApplet.class"
name = "TestApplet"
width = "600"
height = "300"
hspace = "0"
vspace = "0"
align = "middle"
>
<param name = "fileName" value = "">
</applet>
</body>
</html>
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ar...
I have same problem.
My situation is that my JApplet work well in the JBuilder and Oracle JDeveloper but can not run on browser,it appears grey box on the web
page(HTML file) when it run on the M$XP window explorer
I find a situation that the Applet can not display
The Applet contains GIF file
Actually,I really want to place my assignment game to my home page

Although,it is a little bit simple
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I surpose there must be some solution to this problem, maybe we just don't know it. hope some experienced guy can tell us.
 
Jay Dellinger
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably do not have an adequate version of java enabled in your browser. I have IE6 on a clean recent build of Windows 2000, and I too get the gray box. However, I've also installed java 1.4.2 from Sun and by enabling the Java plugin and it worked fine. So you either need to install the java plugin or install the microsoft jvm (I can never find it easily).
FYI, you will get a security exception trying to open files from an applet. It violates the "sandbox" security. You would have to digitally sign your applet and request priveleges to open files.
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tks, maybe it's the problem of microsoft. I'll try it later.
I know sandbox will stop me opening files, I was just trying to write some security policy file to change the default priority.
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ar
yes
FYI, you will get a security exception trying to open files from an applet. It violates the "sandbox" security. You would have to digitally sign your applet and request priveleges to open files.
I face the above problem that contains some exception when I read the GIF file within the JApplet
I know sandbox will stop me opening files, I was just trying to write some security policy file to change the default priority.
How can I do it?
thanks
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's something cannot explain in one sentense. but I suggest you to run the policytool in jdk. then you will find you can change the policy by yourself.
try it and good luck!
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Sean Lee
thanks for your time to answer my question
but I suggest you to run the policytool in jdk
I find the policytool in \j2re1.4.2\bin
Do I need to download the J2sdk?
Could you tell me the path that I can find it out?
thanks again
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there's a policytool in j2sdk\bin, but I think it's the same with the one in j2sdk\jre\bin.
both of them are ok, I think what you should do is just set your PATH.
hope it helps.
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some questions about the Java.policy file
When I click the policytool,it tells me that I can not find out the Java.policy file
Could you tell me where I can find the Java.policy file out?
And
If I hava not Java.policy file
Could you tell me how can I do some configuration?
thanks for your time
 
Caven Wang
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steps:
1) make sure You have installed JRE1.2~4.x ,
if ture
you will see the Java Plug_in in your control panel in win 9x/2k/xp
2)if it still doesn't work, you'd better open the java console to view the message inside;
3) if the message is about some security problem, try to use signature in your applet.
how to add digital signature in your applet?
a. make your class(es) int one jar
b. use keytool to creat your own digital signature file;
c. use jarsigner to add signature
d. while running the applet, accept the signature!

Goooooooooooooooooooooooooood luck!
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by siu chung man:
I have some questions about the Java.policy file
When I click the policytool,it tells me that I can not find out the Java.policy file
Could you tell me where I can find the Java.policy file out?
And
If I hava not Java.policy file
Could you tell me how can I do some configuration?
thanks for your time

Yes, I know what you mean, I got the same problem at the begining. No worry, if it suggests you it cannot file the file, just create one and save it as it needs. and it works.
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
I edit the security file and the path of the reading java.policy file
And it works

But also one question occurs
Why the GIF file can not display?

It works in JBuilder and JDeveloper
But it can not work in web page(html file)
Any idea??
many thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic