print af billede i java
Hej jeg har et problem med at printe et billede ud i denne dialogboks, hvorfor og hvad skal der gøres/*
* JDialog.java
*
* Created on 18. april 2001, 22:14
*/
/**
*
* @author lord x
* @version
*/
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.print.*;
import java.awt.event.*;
import java.awt.Frame;
public class ScaleViewer extends javax.swing.JDialog implements Printable {
/** Creates new form JDialog */
public ScaleViewer(java.awt.Frame parent,boolean modal) {
super (parent, modal);
initComponents ();
setSize(1000,300);
}
/** This method is called fromw within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
jButton1 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
}
);
jButton1.setText(\"Make it\");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
}
);
jPanel1.add(jButton1);
jPanel1.setBorder(new javax.swing.border.TitledBorder(\"Scale viewer\"));
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
}//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// Add your handling code here:
/** Closes the dialog */
PrinterJob job = PrinterJob.getPrinterJob();
// Specify the Printable is an instance of SimplePrint
job.setPrintable(new SimplePrint());
// Put up the dialog box
if (job.printDialog()) {
// Print the job if the user didn\'t cancel printing
try { job.print(); }
catch (Exception e) { /* should handle */ }
}
System.exit(0);
}
public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException {
// pageIndex 0 to 4 corresponds to page numbers 1 to 5.
if (pageIndex >= 2) return Printable.NO_SUCH_PAGE;
g.drawImage(fret1.getFretboard(),10,10,950,200,this);
return Printable.PAGE_EXISTS;
}
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
setVisible (false);
dispose ();
}//GEN-LAST:event_closeDialog
/**
* @param args the command line arguments
*/
/*public static void main (String args[]) {
new ScaleViewer (new javax.swing.JFrame (), true).show ();
}
*/
public void paint(Graphics g)
{
BufferedImage s = (BufferedImage)fret1.getFretboard();
g.drawImage(s,10,10,950,200,this);
}
public static void setFretboard(Fretboard i) {
fret1 = i;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel jPanel1;
private static Fretboard fret1;
private Scale s;
private javax.swing.JButton jButton1;
private Canvas canvas;
// End of variables declaration//GEN-END:variables
}
