1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.PrintJob;
import java.awt.event.ActionListener;
import java.util.Properties;
import java.awt.BorderLayout;
public class consultation extends javax.swing.JFrame {
public consultation () {
initComponents();
add(imprimer, BorderLayout.SOUTH);
imprimer.addActionListener((ActionListener) this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
private void imprimerActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Properties props = new Properties();
props.setProperty("awt.print.paperSize", "a4");
props.setProperty("awt.print.destination", "printer");
PrintJob demandeDImpression = getToolkit().getPrintJob(this, "Impression", props);
if (demandeDImpression != null) {
Graphics gImpr = demandeDImpression.getGraphics();
if (imprimer.isSelected()) printAll(gImpr);
gImpr.dispose();
demandeDImpression.end();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new consultation().setVisible(true);
}
});
} |
Partager