You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
General <strong>Java</strong> Questions IV<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<br />
has 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 />
Q: Is it possible to use switch with range of values?<br />
Ex:<br />
switch (iBegins){<br />
case 2 to 10:<br />
}<br />
Answer:<br />
not exactly like this but:<br />
switch (iBegins){<br />
case 2:<br />
case 3:<br />
file:///F|/350_t/350_tips/general_java-IV.htm (5 of 10) [2002-02-27 21:18:34]