Showing posts with label print. Show all posts
Showing posts with label print. Show all posts
Java print pi value
Java print screen
Complete source code below will show you, how to implement print screen or capture screen image in java. Program below will capture screen during it's executing time and after that, it will paint the image on a canvas before add it into a JFrame to display it's result.
*************************************************************
COMPLETE SOURCE CODE FOR : CaptureScreen.java
*************************************************************
*************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************
*************************************************************
COMPLETE SOURCE CODE FOR : CaptureScreen.java
*************************************************************
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class CaptureScreen extends Canvas
{
Rectangle screenRectangle=new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
Robot myRobot;
BufferedImage screenImage;
public CaptureScreen()
{
try
{
myRobot=new Robot();
}
catch(Exception exception)
{
exception.printStackTrace();
}
screenImage=myRobot.createScreenCapture(screenRectangle);
JFrame myFrame=new JFrame("Capture Screen");
myFrame.add(this);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(Toolkit.getDefaultToolkit().getScreenSize().width,Toolkit.getDefaultToolkit().getScreenSize().height);
myFrame.setVisible(true);
}
public void paint(Graphics g)
{
g.drawImage(screenImage,0,0,this);
}
public static void main(String[]args)
{
CaptureScreen cs=new CaptureScreen();
}
}
*************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************
Java source code to determine when application exit by print a line of text on command prompt
*************************************************************
COMPLETE SOURCE CODE FOR : DetermineWhenApplicationExit.java
*************************************************************
*************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************
COMPLETE SOURCE CODE FOR : DetermineWhenApplicationExit.java
*************************************************************
public class DetermineWhenApplicationExit
{
public static void main(String[]args)
{
Runtime.getRuntime().addShutdownHook(new Thread()
{
public void run()
{
//Application will print "BYE" when it close
System.out.println("BYE");
}
});
//Make this application terminate
System.exit(0);
}
}
*************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************
Subscribe to:
Posts (Atom)