Action Listener for sending info to the printer
Hey Folks
I have the code below which is compling with one error
G:\Print1.java:79: <identifier> expected
jButton14.addActionListener(listener);
I have another version of this code which is working correct, so i know its not the code, its a problem i'm having with the actionlistener, if any body can help me with this i'd be in your debt, its giving me an headache
Thanking You
Ambrose
import javax.print.*;
import javax.print.event.*;
import javax.print.attribute.*;
import java.awt.print.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
publicclass Print1extends JFrameimplements Printable
{
private JButton jButton14;
private JTextArea jTextArea1;
Document document1;
public Print1(String str)
{
super(str);
Container c = getContentPane();
c.setLayout(null);
setSize(480,400);
setLocationRelativeTo(null);
//construct components
jButton14 =new JButton ("print");
jTextArea1 =new JTextArea (5, 5);
String msg ="Hello, Printer";
//adjust size and set layout
setPreferredSize (new Dimension (496, 371));
setLayout (null);
//add components
c.add (jButton14);
c.add (jTextArea1);
//set component bounds (only needed by Absolute Positioning)
jButton14.setBounds (210, 245, 100, 20);
jTextArea1.setBounds (25, 55, 435, 160);
}
ActionListener listener =new ActionListener()
{
publicvoid actionPerformed(ActionEvent e)
{
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintService printService =
PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = printService.createPrintJob();
PrintJobListener pjlistener =new PrintJobAdapter(){
publicvoid printDataTransferCompleted(PrintJobEvent e){
System.out.println("Good-bye");
System.exit(0);
}
};
job.addPrintJobListener(pjlistener);
PrintRequestAttributeSet pras =
new HashPrintRequestAttributeSet();
DocAttributeSet das =new HashDocAttributeSet();
Doc doc =new SimpleDoc(printIt, flavor, das);
try
{
job.print(doc, pras);
}catch (PrintException pe)
{
pe.printStackTrace();
}
}
};
jButton14.addActionListener(listener);
publicstaticvoid main (String[] args)throws Exception{
Print1 fr =new Print1("User Welcome");
//Test.setDefaultLookAndFeelDecorated(true);
fr.show();
}
}

