27.04.2013 Views

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Applets<br />

the <strong>Java</strong> applet is refering, you cluster them in a JAR file with the help of JAR utility that comes with<br />

the JDK version. Check out the help for the options of that utility and make a ".jar" file out of the<br />

applets refered classes and images and other relevent data which you want to load.<br />

Use the archive option of the applet tag and assign the .jar file:<br />

<br />

<br />

When I reload my applet my hidden canvas is shown directly! Why?<br />

Answer: Put mycanvas.setVisible (false); in Start() rather than init()...<br />

I want to be able to print debugging text messages during the whole applet's lifetime. Is there an<br />

easy way to do that???<br />

Q: I'm a beginner in java. Right now i am doing an applet and i want to<br />

write messages to the browser window for debugging purposes i.e. to<br />

follow how the applet executes. Like when i'm developing an C++<br />

application i usually use lots of "couts" to check values and the<br />

programs behavior. Is there an easy way to do things like that when<br />

making a <strong>Java</strong> applet? For me it seems like everything happens in a<br />

function called "paint(graphics g)" and that function is only called at<br />

the beginning of the applet start. I want to be able to print text<br />

messages during the whole applet's lifetime. Is there an easy way to do<br />

that???<br />

Answer: you'd be better off doing a<br />

System.out.println("the value is " + whateverValue);<br />

This will show up in the java console. to see it in ie5, do View-><strong>Java</strong> Console, and in netscape4.7, do<br />

Communicator->Tools-><strong>Java</strong> Console and it will pop up the java console window.<br />

If you are doing it in appletviewer from dos, it will show up in the dos window you used to call<br />

appletviewer.<br />

What are restrictions for applet?<br />

Q: What are applets prevented from doing?<br />

Answer: In general, applets loaded over the net are prevented from reading and<br />

writing files on the client file system, and from making network connections<br />

except to the originating host.<br />

In addition, applets loaded over the net are prevented from starting other<br />

programs on the client. Applets loaded over the net are also not allowed to<br />

load libraries, or to define native method calls. If an applet could define<br />

native method calls, that would give the applet direct access to the<br />

underlying computer.<br />

Q: I am writing an applet that will use images. I would like to ship out the images using a jar file<br />

that contains all the images that the applet is going to use. I have seen a piece of code that does that<br />

in the past, but I don't remember where.<br />

Answer: by David Risner The following is from:<br />

http://developer.netscape.com/docs/technote/java/getresource/getresource.html<br />

file:///F|/350_t/350_tips/applets.htm (2 of 10) [2002-02-27 21:17:49]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!