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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Applets<br />

that looks more or less like this (it is an imaginary code just to show what I would like to do)<br />

(if.event.target.ComponentType==Button) etc.<br />

I tried a lot of things with getClass but none of them worked<br />

Answer: Have your applet implement the ActionListener interface, and have every button that's<br />

instantiated add the applet as an ActionListener. Then, inside of your applet, have the following<br />

method:<br />

public void actionPerformed(ActionEvent event) {<br />

// check to see if the source of the event was a button<br />

if(event.getSource() instanceof Button) {<br />

// do whatever it is you want to do with buttons...<br />

}<br />

}<br />

Darryl L. Pierce Visit <br />

Q: Could you suggest how to draw one centimeter grid in applet, please? One cm on the screen<br />

must be equal to real cm.<br />

Answer: If you're not all that picky about it, you can always use java.awt.Toolkit's<br />

getScreenResolution() to see how far between the lines should be in the grid....that's assuming the<br />

applet security allows it.<br />

But have it _exactly_ one cm, you can't do, since the user can always adjust the display with the<br />

monitor controls (making the picture wider/taller/whatever), and no computer that I know of can know<br />

those settings.<br />

--<br />

Fredrik Lännergren<br />

Not only that, the OS (and thus <strong>Java</strong>) does not know if I am using a 21" or a 14" monitor and thus<br />

can't know the actual physical size of a given number of pixels. By convention, on Windows monitors<br />

are assumed to be either 96dpi or 120dpi (depending on the selection of large or small fonts). <strong>Java</strong><br />

usually assumes 72dpi. None of these values is likely to be<br />

accurate.<br />

--<br />

Mark Thornton<br />

Q: Does anyone know how to or where I can find information about determining if cookies are<br />

disabled on a client browser making a request to a servlet or JSP (or any server side request handler,<br />

for that matter)? Also, is there a way to determine whether or not a client's browser has style sheets<br />

enabled?<br />

Answer: To test if the client has cookies enabled, create a cookie, send it, and read it back. If you<br />

can't read it back, then the client does not accept them. It's not a clean way of doing it, but it's the only<br />

way (that I know if).<br />

As for CSS, there is no way to know if they allow CSS. Different versions of the browsers support<br />

varying levels of CSS. You can get the browser type from the request object and then make decisions<br />

based on that.<br />

Q: How can two applets communicate with each other? Have you some examples?<br />

file:///F|/350_t/350_tips/applets.htm (6 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!