import java.awt.Graphics;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.PrintJob;
import java.awt.Robot;
public class test extends Frame
{
public test()
{
super("Test");
this.setSize(200,200);
this.setResizable(false);
this.setLocationRelativeTo(null);
java.awt.Button but = new java.awt.Button("Druck");
this.add(but);
but.addActionListener(new ActionListener(){
/**
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e) {
doPrint();
}
});
this.show();
}
private void doPrint()
{
PrintJob prJob = this.getToolkit().getPrintJob(this,"Seitendruck",null);
Graphics pg = prJob.getGraphics();
try{
Robot robi = new Robot(this.getGraphicsConfiguration().getDevice());
pg.drawImage(robi.createScreenCapture(this.getBounds()),5,5,this.getWidth(),this.getHeight(),this);
pg.dispose();
prJob.end();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
public static void main(String args[])
{
new test();
}
}