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.

General <strong>Java</strong> Questions I<br />

to the specified position of the destination array. A subsequence of array components<br />

are copied from the source array referenced by src to the destination array<br />

referenced by dst. The number of components copied is<br />

equal to the length argument. The components at positions srcOffset through<br />

srcOffset+length-1 in the source array are copied into positions dstOffset through<br />

dstOffset+length-1, respectively, of the destination array.<br />

If the src and dst arguments refer to the same array object, then the copying is<br />

performed as if the components at positions srcOffset through srcOffset+length-1<br />

were first copied to a temporary array with length components and then the contents<br />

of the temporary array were copied into positions dstOffset through<br />

dstOffset+length-1 of the argument array."<br />

Q: More about Robot! I met with a problem in using class Robot.mousePress...<br />

The compiling process is successful. But when I run it, I receive<br />

"IllegalArgumentException:<br />

Invalid combination of button flags". I don't quit understand this information. Part of<br />

my code is as following:<br />

Robot rMouse=new Robot();<br />

int button=1;<br />

rMouse.mousePress(button);<br />

rMouse.mouseRelease(button);<br />

I am really confused. Will you please give me some advice? Thank you in advance!<br />

Answer: You are not using a valid value for the argument to the mousePress() and<br />

mouseRelease() methods. If you check the API documentation, you'll find the valid<br />

values are a combination of one or more of the following constants:<br />

InputEvent.BUTTON1_MASK<br />

InputEvent.BUTTON2_MASK<br />

InputEvent.BUTTON3_MASK<br />

plus others which represent the Ctrl, Alt, and Shift keys. To press the left<br />

mouse button, you want to use:<br />

rMouse.mousePress(InputEvent.BUTTON1_MASK);<br />

--<br />

Lee Weiner<br />

Q: In what situation an exception has to be caught otherwise the compiler will<br />

complain?<br />

e.g. IOException does NOT have to be explicitly caught, however, SQLException has<br />

to be caught otherwise VisalAge will not compile the program.<br />

Answer: The only unchecked exceptions in <strong>Java</strong> are RuntimeException and its<br />

subclasses. This includes such familiar classes as NullPointerException,<br />

ClassCastException, and IndexOutOfBoundsException.<br />

IOException is not one of these, and *does* have to be explicitly caught or thrown<br />

-jeff_robertson<br />

file:///F|/350_t/350_tips/general_java-I.htm (26 of 31) [2002-02-27 21:18:17]

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

Saved successfully!

Ooh no, something went wrong!