General Java Questions IV
 Q: More about Robot! I met with a problem in using class Robot.mousePress...
The compiling process is successful. But when I run it, I receive
"IllegalArgumentException:
Invalid combination of button flags". I don t quit understand this information. Part of
my code is as following:
Robot rMouse=new Robot();
int button=1;
rMouse.mousePress(button);
rMouse.mouseRelease(button);
I am really confused. Will you please give me some advice? Thank you in advance!
Answer: You are not using a valid value for the argument to the mousePress() and
mouseRelease() methods. If you check the API documentation, you ll find the valid
values are a combination of one or more of the following constants:
InputEvent.BUTTON1_MASK
InputEvent.BUTTON2_MASK
InputEvent.BUTTON3_MASK
plus others which represent the Ctrl, Alt, and Shift keys. To press the left 
mouse button, you want to use:
rMouse.mousePress(InputEvent.BUTTON1_MASK);
  
Lee Weiner
 Q: In what situation an exception has to be caught otherwise the compiler will
complain?
e.g. IOException does NOT have to be explicitly caught, however, SQLException
has to be caught otherwise VisalAge will not compile the program.
Answer: The only unchecked exceptions in Java are RuntimeException and its
subclasses. This includes such familiar classes as NullPointerException,
ClassCastException, and IndexOutOfBoundsException.
IOException is not one of these, and *does* have to be explicitly caught or thrown
  
jeff_robertson
 Q: Is it possible to use switch with range of values?
Ex:
switch (iBegins){
   case 2 to 10:
}
Answer: 
not exactly like this but:
switch (iBegins){
   case 2:
   case 3:
   case 4:
   case 5:
file:///F|/a_jsite/350_tips/general_java IV.htm (5 of 10) [2001 07 08 11:24:54]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved