import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.text.*;
public class DruckD2 extends Frame
{
public int count=0;
public static void main( String[] args )
{
DruckD2 wnd = new DruckD2( "Test-Druck" );
wnd.setSize( 200, 100 );
wnd.show();
}
public DruckD2( String sFensterTitel )
{
super( sFensterTitel );
Button bttn = new Button( "Testseite drucken" );
add( BorderLayout.CENTER, bttn );
bttn.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent ev ) {
druckeTestseite(); } } );
addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent ev ) {
dispose();
System.exit( 0 ); } } );
}
void druckeTestseite()
{
Toolkit tk = Toolkit.getDefaultToolkit();
PrintJob prjob = tk.getPrintJob( new Frame(), "", null );
if( null != prjob )
{
Calendar cal = new GregorianCalendar( TimeZone.getTimeZone("ECT") );
SimpleDateFormat formater = new SimpleDateFormat();
final int iScreenResol = getToolkit().getScreenResolution();
final int iPageResol = prjob.getPageResolution();
final Dimension dimScreenSize = getToolkit().getScreenSize();
final Dimension dimPageDimension = prjob.getPageDimension();
Graphics pg = prjob.getGraphics();
if( null != pg && 0 < iPageResol )
{
int iAddY = 20;
int iRand = (int)Math.round( iPageResol * 2. / 2.54 )/2; // 2 cm Rand
int iPosX = iRand + iRand/4; // Textposition
int iPosY = iPosX - iAddY/2;
int iWdth = (dimPageDimension.width - iRand * 2)/2; // innere Breite
int iMidY = (dimPageDimension.height )/ 2;
pg.setFont( new Font( "SansSerif", Font.PLAIN, iAddY*2/3 ) );
pg.setColor(Color.BLACK);
pg.drawString("Testseite von: "+formater.format(cal.getTime()),iPosX, iPosY+=iAddY );
pg.setColor(Color.GREEN);
pg.drawRect( iRand, iRand, iWdth, dimPageDimension.height - iRand * 2 );
pg.setColor(Color.RED);
pg.drawLine( iRand, iMidY + iWdth/50, dimPageDimension.width - iRand, iMidY - iWdth/50 );
pg.drawLine( iRand, iMidY - iWdth/50, dimPageDimension.width - iRand, iMidY + iWdth/50 );
iWdth -= 4;
pg.setColor(Color.BLUE);
pg.drawOval( iRand + 2, dimPageDimension.height - iRand - iWdth - 2, iWdth, iWdth );
pg.dispose();
}
prjob.end();
}
}
}