Created
September 2, 2013 08:47
-
-
Save resarahadian/6410681 to your computer and use it in GitHub Desktop.
Print Screen Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.awt.image.BufferedImage; | |
import java.awt.EventQueue; | |
import java.awt.Rectangle; | |
import java.awt.Dimension; | |
import java.awt.Toolkit; | |
import java.awt.Robot; | |
import java.io.File; | |
import javax.imageio.ImageIO; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
import javax.swing.UIManager; | |
import javax.swing.border.EmptyBorder; | |
import javax.swing.JLabel; | |
import javax.swing.ImageIcon; | |
@SuppressWarnings("serial") | |
public class framePrintScreen extends JFrame | |
{ | |
private JPanel contentPane; | |
private JButton btnPrintScreen; | |
private JLabel lblWall; | |
private JLabel lblIcon; | |
/** | |
* Create the frame. | |
*/ | |
public framePrintScreen() | |
{ | |
super("Print Screen Desktop [JPrintScreen]"); | |
setResizable(false); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setBounds(100, 100, 450, 300); | |
contentPane = new JPanel(); | |
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); | |
setContentPane(contentPane); | |
contentPane.setLayout(null); | |
btnPrintScreen = new JButton("Print Screen"); | |
btnPrintScreen.setIcon(new ImageIcon("/home/resa/resa/Aplikasi Java/SwingComponents/src/Gambar/PSImage/ok.png")); | |
btnPrintScreen.addActionListener(new ActionListener() | |
{ | |
public void actionPerformed(ActionEvent act) | |
{ | |
dispose(); | |
try | |
{ | |
Toolkit tk = Toolkit.getDefaultToolkit(); | |
Dimension dimensi = tk.getScreenSize(); | |
Rectangle rect = new Rectangle(dimensi); | |
Robot rbt = new Robot(); | |
Thread.sleep(2000); | |
File file = new File("/home/resa/resa/Downloads/Screenshot1.png"); | |
BufferedImage bi = rbt.createScreenCapture(rect); | |
ImageIO.write(bi,"png",file); | |
tk.beep(); | |
} | |
catch (Exception ex) | |
{ | |
// TODO Auto-generated catch block | |
ex.printStackTrace(); | |
} | |
} | |
}); | |
btnPrintScreen.setBounds(131, 162, 180, 57); | |
contentPane.add(btnPrintScreen); | |
lblIcon = new JLabel(""); | |
lblIcon.setIcon(new ImageIcon("/home/resa/resa/Aplikasi Java/SwingComponents/src/Gambar/PSImage/kamera.png")); | |
lblIcon.setBounds(145, 6, 147, 121); | |
contentPane.add(lblIcon); | |
lblWall = new JLabel(""); | |
lblWall.setIcon(new ImageIcon("/home/resa/resa/Aplikasi Java/SwingComponents/src/Gambar/PSImage/putihBlur.png")); | |
lblWall.setBounds(0, 0, 448, 277); | |
contentPane.add(lblWall); | |
setLocationRelativeTo(null); | |
} | |
/** | |
* Launch the application. | |
*/ | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
try | |
{ | |
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); | |
framePrintScreen frame = new framePrintScreen(); | |
frame.setVisible(true); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment