Java Production screenshot software (can also be saved to the clipboard)

Source: Internet
Author: User

 Packagecom.kaige123;ImportJava.awt.Rectangle;ImportJava.awt.Robot;ImportJava.awt.Toolkit;ImportJava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;ImportJava.awt.image.BufferedImage;ImportJava.io.File;ImportJavax.imageio.ImageIO;ImportJavax.swing.JButton;ImportJavax.swing.JFrame;/** * Screen page * * @author Edith * * *///Screen Start window This window will have a button click button to ActionListener is a button pressed an event Public  class actionjframe extends JFrame  implements  ActionListener {//constructor We need to initialize the button inside the constructorPublic   actionjframe() {//This is the buttonJButton JB =NewJButton (""); Jb.addactionlistener ( This);//Register the time on the button if you do not register, you will not be able to trigger the association of events and Buttons .  This. Add (JB);//Add the button to the window This. SetSize ( -, -); This. Setalwaysontop (true);//window above all Windows This. setvisible (true);//Display window}Public   static void main(string[] args) {NewActionjframe (); }Public   void actionperformed(actionevent e) { This. setvisible (false);//Window Hide up//Start//java.awtTry{Thread.Sleep ( -);//Pause for a moment//robot Control Mouse Control keyboard screenRobot r =NewRobot (); Toolkit t = Toolkit.getdefaulttoolkit ();//Get high screen width on screenintwidth = t.getscreensize (). width;intHeight = t.getscreensize (). Height;//Start parameter must tell people how bigBufferedImage image = R.createscreencapture (NewRectangle (width, height));//BufferedImage cache in-memory photos//Save the photos in the cache to the a.jpg of the disk//imageio.write (image, "JPEG", New File ("c:/a.jpg"));NewImagejframe (image); }Catch(Exception E2) { 
        }

    }
}
 Packagecom.kaige123;ImportJava.awt.Graphics;ImportJava.awt.Image;ImportJava.awt.Rectangle;ImportJava.awt.Robot;ImportJava.awt.Toolkit;ImportJava.awt.datatransfer.DataFlavor;Importjava.awt.datatransfer.Transferable;ImportJava.awt.datatransfer.UnsupportedFlavorException;ImportJava.awt.event.MouseEvent;ImportJava.awt.image.BufferedImage;ImportJava.awt.image.ImageObserver;ImportJava.io.IOException;ImportJavax.swing.JFrame;/** * Show Photos * Then save * @author Edith * * * *//Show Photos Public  class imagejframe extends JFrame implements Java. AWT. event. MouseListener {BufferedImage image =NULL;Public   imagejframe(bufferedimage image) { This. image = Image;//Save the passed-in object to the propertyToolkit t = Toolkit.getdefaulttoolkit ();//Get high screen width on screenintwidth = t.getscreensize (). width;intHeight = t.getscreensize (). Height; This. setSize (width, height);//Set the size of the window  This. Addmouselistener ( This); This. setundecorated (true);//Remove border from window This. setvisible (true);//window starts calling paint to paint once it is displayed}//Window painting method Public   void paint(Graphics g) {Super. Paint (g); G.drawimage (Image,0,0,NewImageObserver () {Public   boolean imageupdate(Image img, int infoflags, int x,  int y, int width, int height) {//TODO auto-generated method stubreturn false;
        }
        });
    G.drawrect (x, Y, W, h); }intx, y;intW, H;Booleanb =false;Public   void mousepressed(MouseEvent e) {//Pressif(b = =false) {x = E.getx ();
        y = e.gety (); }

    }Public   void mousereleased(MouseEvent e) {//Bounce upif(b = =false) {w = E.getx ()-X; h = e.gety ()-y; This. repaint (); b =true; }

    }@OverridePublic   void mouseclicked(MouseEvent e) {if(b && e.getclickcount () = =2) {//Your mouse has no double-click Try{//Save the good photos .Robot r =NewRobot ();FinalBufferedImage image = R. createscreencapture (NewRectangle (x +1, Y +1, W-1, H-1));//Imageio.write (image, "JPEG", New File ("c:/a.jpg"));Transferable trans =NewTransferable () { PublicDataflavor[] Gettransferdataflavors () {return NewDataflavor[] {Dataflavor.imageflavor}; }Public   boolean isdataflavorsupported(dataflavor flavor) {returnDataFlavor.imageFlavor.equals (flavor); }  public Object gettransferdata(dataflavor flavor) throws Unsupportedflavorexception, IOException{if(isdataflavorsupported (flavor))returnImage throw new unsupportedflavorexception(flavor) ;
                }

                }; Toolkit.getdefaulttoolkit (). Getsystemclipboard (). setcontents (trans,NULL); System.exit (0);//Close your software}Catch(Exception E2) {//Todo:handle exception}
        }

    }@OverridePublic   void mouseentered(MouseEvent e) {//TODO auto-generated method stub}@Override Public   void mouseexited(MouseEvent e) {//TODO auto-generated method stub}

}

Java Authoring screen Software (can also be saved to the clipboard)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.