Monday, 15 September 2014

java - class not getting instantiated, doesn't work using actionlistener, works fine separately -


I'm trying to create a screen capture program.

I have a transparent window, which will capture this area on a button Capture , and I try to instantiate a class captureScreen I am using a command prompt , which is used when it is executed individually in different files.

I hit the button capture when trying to instantiate this captureScreen class but it does not work and Capture Screen Java does not do anything differently when this file is transformed immediately

  captureScreen a = new captureScreen ();   

System.out.println ("Start"); will not print anything, even though it works correctly when running with command prompt like

  Java caption screen   

ScreenRecord.java here

  The public class's screen record is JFrame applying ActionListener {public screenrecord () {....} Public Zero Action implemented (ActionEvent E) {if ("records" .equals (e.getActionCommand ())) {captureScreen a = new captureScreen (); Println ("Donesssssss"); }}} Extends the class capture screen object {Public Ink Capture Screen () {... Robot Robot = New Robot (); Buffet image image = robot.createcrescapture (screenrecognally); ImageIO.write (image, "PNG", new file (filename)); Println ("full"); Return 1;} Hold (AWTException pre) {System.out.println ("Error" + East); Return 1; } Hold (IOException pre) {System.out.println ("error" + east); Return 1; }}}    

public int capture screen () { It's not a constructor, it's a method, so call caption screen a = new capture screen () will not activate this method.

You can ...

Change it so that it is a constructor

  public capture screen () {...}   

or you can ...

Call the method ...

  capture screen = a new capture screen () ; A.captureScreen ();   

Now that the name of the classes has been started with the upper part, so you can tell the difference between a method and constructor, because one of them Causes are welcome, case letters i.e. CaptureScreen , where constructors follow the same code for the public capture screen () {...} and lower case letters Start with.

Just saying

No comments:

Post a Comment