y***e 发帖数: 39 | 1 okay, what you need to do is extending button class:
///////////////////////////////////////////////////////
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
public class printbutton extends Panel implements
ActionListener {
public printbutton() {
setBackground(Color.white);
MyButton b = new MyButton();
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e) {
System.out.println("action");
PrinterJob | y***e 发帖数: 39 | 2 /////////JDK1.2 case
static class MyButton extends JButton
implements Printable {
public MyButton() {
super("MyButton");
}
public int print(Graphics g, PageFormat pf, int pi)
throws PrinterException {
System.out.println("mybutton print");
if (pi >= 1) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) g;
g2.translate(pf.getImageableX(), pf.getImageableY());
Font f = new Font("Monospaced",Font |
|