Saturday 15 May 2010

java - cannot instantiate a class using a button -


I'm trying to create a screen capture program.

I have a transparent window, which will capture the area on a button capture , and I try to instantiate a class captureScreen I'm doing a good job on captureScreen

is executed individually by using a command prompt

I have captureScreen When the button Capture is hit by the class, I am trying to instantiate.

I tried to put class on my screenrecord.java , put the code in the event listener is. In both of these cases, I get these errors

  AWTException should be caught or declared   

in

 < Code> robot robot = new robot (); IOException in line   

and BufferedImage image .

And touching the screen. Java does not contain anything different. System.out.println ("Start"); will also not print anything.

Here is my screenrecord.java code

  the public square screenorder applied to GeFrame ActionListener {public screenrecord () {...} Public Zero Functionality (if ("record" .equals (e.getActionCommand ())) {capture screen = a new capture screen (); }}}   

and captureScreen.java , works fine individually.

  extends the public class capture screen object {public static zero main (string agr []) {... robot robot = new robot (); Buffet image image = robot.createcrescapture (screenrecognally); ImageIO.write (image, "PNG", new file (filename)); Println ("full"); }}   

All your suggestions, comments, recommendations are welcome and commendable. Please help me solve this problem Thank you.

You need to use effort / catch, so there are not many errors in the form of those warnings. For, put around a code that has AWTException:

  try {// code cause AWTException Robot Robot = new robot (); } Hold (AWTException e) {System.out.println ("Error" + e); }   

and:

  try {// code due to IOException BufferedImage image = robot.createScreenCapture (screenRectangle); } Hold (IOException e) {System.out.println ("error" + e); }   

Or combine both:

  try {// code whereby AWTException or IOException robot robot = new robot (); Buffet image image = robot.createcrescapture (screenrecognally); } Hold (IOException e) {System.out.println ("error" + e); } Hold (AWTException e) {System.out.println ("Error" + e); }   

For further reading, this can help clarify the exception:



No comments:

Post a Comment