-->

Thursday, March 21, 2013

Java Interesting Questions - Screen Capture

Posted by Sharath
public class RandomClassWeird {

/**
* @param args
*/
public static void main(String[] args) {
//Question 1
Random random = new Random(441287210);
for (int i = 0; i < 10; i++)
System.out.print(random.nextInt(10) + " ");

//Question 2
random = new Random(-6732303926L);
for (int i = 0; i < 10; i++)
System.out.println(random.nextInt(10) + " ");

//Question 3
int i = (byte) + (char) - (int) + (long) - 1;
System.out.println("dd"+i);

//Taking Screenshot Example
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
Robot robot;
try {
robot = new Robot();
BufferedImage img = robot.createScreenCapture(new Rectangle(size));
File save_path=new File("E:\\screen.jpg");
ImageIO.write(img, "JPG", save_path);

} catch (AWTException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

}

0 comments:

Post a Comment