Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mastan
awt swings
2 Answer(s)      6 years and a month ago
Posted in : Swing AWT



Advertisement
View Answers

December 17, 2008 at 7:03 AM


Hi friend,

This code will be captured your image. Please implement this code.


import javax.swing.*;
import javax.imageio.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;

public class Screenshot {


public Screenshot(){
JFrame frame = new JFrame("Screen Shot Frame.");
JButton button = new JButton("Capture Screen Shot");
button.addActionListener(new MyAction());
JPanel panel = new JPanel();
panel.add(button);
frame.add(panel, BorderLayout.CENTER);
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

public class MyAction implements ActionListener{
public void actionPerformed(ActionEvent ae){
try{
String fileName = JOptionPane.showInputDialog(null, "Enter file name : ", "Roseindia.net",1);
if (!fileName.toLowerCase().endsWith(".gif")){
JOptionPane.showMessageDialog(null, "Error: file name must end with \".gif\".","Roseindia.net", 1);
}
else{
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(new Rectangle(
Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(image, "gif", new File(fileName));
JOptionPane.showMessageDialog(null, "Screen captured successfully.", "Roseindia.net", 1);
}
}
catch(Exception e){}
}
}
public static void main(String[] args) throws Exception {
Screenshot ss = new Screenshot();
}
}

------------------------------------------

Thanks.


December 17, 2008 at 11:18 PM


thank you very much sir ...


Related Tutorials/Questions & Answers:
Swings/awt - Swing AWT
Swings/awt  Hi, how to write action listeners to the Buttons in RichTextEditor tool bar.. thanks in advance...it's Urgent... i am very much new to Swings
AWT-swings tutorial - Swing AWT
AWT-swings tutorial  hello sir, i am learnings swings and applets.. i want some tutorials and some examples related to swings.. thank you sir..waiting for your answer.  Hi friend, I am sending you a link
Advertisements
awt swings - Swing AWT
awt swings  hello sir, My requirement is to insert captured image from cam onto a frame and from that place i hve to save it in the database(MySql).its urgent sir.it is a part of my project..if code is available
another frame by using awt or swings
another frame by using awt or swings  how to connect one frame to another frame by using awt or swings
Java Swings-awt - Swing AWT
Java Swings-awt  Hi, Thanks for posting the Answer... I need to design a tool Bar which looks like a Formating toolbar in MS-Office Winword(Standard & Formating) tool Bar. Please help me... Thanks in Advance
SWINGS - Swing AWT
more information,Examples and Tutorials on Swing,AWT visit to : http://www.roseindia.net/java/example/java/awt/ http://www.roseindia.net/java/example/java
java swings - Swing AWT
java swings  I am doing a project for my company. I need a to show the performance of the employees by using bar bharts. Please give me how can we write the code for bar charts using java swings.  Hi friend, I am
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
Java Swings problem - Swing AWT
Java Swings problem  Sir, I am facing a problem in JSplitPane. I want the divider in the splitpane to be customized. I have a splitpane with Horizontal orientation and here, there lies the divider between left component and right
Swings JTable numberic sorting - Swing AWT
Swings JTable numberic sorting  Hi , i am using jdk1.6 for my project and jdk1.6 is providing by default sorting of text column in JTable or suggestion for sorting of numberic column in JTable of Swings...Swings JTable numberic
How to set the border in header and footer from login page using swings/awt
How to set the border in header and footer from login page using swings/awt  Hi, How to set the border in header and footer from login page using swings/awt
How to put the logo in login form using swings/awt?
How to put the logo in login form using swings/awt?  Hi, How to put the logo in login form using swings/awt? I write the login form is working but i want to put the logo in login form plz help   Here is an example
Display data from xml file to Swings - Swing AWT
Display data from xml file to Swings  Hi, We are Preparing a stand alone application. Where the Swings is the front end. There will be only... clicking the buttons in swings it has to display 20 record in one shot in table
plz help me to write a snake game using swings - Swing AWT
plz help me to write a snake game using swings  write snake game program using swings
virtual onscreen keyboard project using java and swings - Swing AWT
virtual onscreen keyboard project using java and swings  Im doing virtual on screen keyboard as my project. i didnt get the method to performthe backspace and space operation using swings in java.can please help me  Hi
AWT
AWT  How to set size of button in awt
awt
Java AWT Applet example  how to display data using JDBC in awt/applet
awt
JDBC and AWT to display data  how to display data using JDBC in awt/applet
awt
JDBC in awt applet  how to display data using JDBC in awt/applet
awt
JDBC in awt  how to display data using JDBC in awt/applet
JSP & Swings
JSP & Swings  How to integrate jsp and swings
swings question
swings question  how to change the background color with the help of color values by using swings
awt - Java Interview Questions
awt  what is the difference between awt and swings  Hi friend, These are basically the main differences between awt and swing. 1.swing components sits on the top of AWT components and do the wiork. 2.AWT
 

 

 

DMCA.com