tailieunhanh - Java 6 Platform Revealed phần 6
Tham khảo tài liệu 'java 6 platform revealed phần 6', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 92 CHAPTER 4 AWT AND SWING UPDATES you were responsible for pagination and the like. Now it s all done for you you just need to call one of the new print methods of which there are three. The simplest way to print the contents of a text component is to call its no-argument print method. Figure 4-24 shows what the initial program looks like and Figure 4-25 shows the standard printer dialog. The program in Listing 4-11 simply shows a JTextArea pastes the current clipboard contents into it and offers a Print button for printing the content. Figure 4-24. Printing the contents of a text component Figure 4-25. The printer dialog CHAPTER 4 AWT AND SWING UPDATES 93 Listing 4-11. Printing Text Components import . import . import . import . public class TextPrint public static void main final String args Runnable runner new Runnable public void run JFrame frame new JFrame Text Print final JTextArea textArea new JTextArea JScrollPane pane new JScrollPane textArea pane JButton button new JButton Print button ActionListener listener new ActionListener public void actionPerformed ActionEvent e try catch PrinterException pe Unable to print. listener 250 150 true runner 94 CHAPTER 4 AWT AND SWING UPDATES The print method is itself kind of generic. While it does offer you the interactive printer-selection dialog you don t get a footer or header on each page. In order to do this you need to use the second variety of the method print MessageFormat header MessageFormat footer . The most interesting of all the print methods is the full-featured one public boolean print MessageFormat headerFormat MessageFormat footerFormat boolean showPrintDialog PrintService service PrintRequestAttributeSet attributes .
đang nạp các trang xem trước