ユーザが用紙のサイズと向きを選択できるようにするには、ページ設定ダイアログを表示します。 そのためには、Toolkit.setupPage を呼び出します。 この例では、次の処理が行われています。
- NumberPainter で Printable インタフェースを実装し、各ページにページ番号を描画する
- PageFormatPrint は SimplePrint と同じである。 ただし、setupPage を呼び出してページ設定ダイアログを表示し、ページの書式を設定している
import java.lang.*;
import java.awt.*;
import java.awt.print.*;
public class PageFormatPrint {
public static void main(String[] args) {
Toolkit tk = Toolkit.getDefaultToolkit();
// Create a new book
Book book = new Book();
// Create a PageFormat and display the Page Setup dialog
PageFormat pageFormat = tk.setupPage(new PageFormat());
// Add two pages to the book that use the same page format and
// painter
book.append(pageFormat, new NumberPainter(), 2);
/* Get a print job from the graphics environment and
* tell it to print our book of three pages.
*/
PrintJob job = GraphicsEnvironment.getLocalGraphicsEnvironment().getPrintJob();
if(job.setupJob(book) == true){
job.print(book);
}
System.exit(0);
}
}
目次 | 前の項目 | 次の項目
Copyright © 1997-2001 Sun Microsystems, Inc. All Rights Reserved.