VERY URGENT! Please help, print function

Hello,

I really urgently need your help because i have got to get this done by today. My probelm is that i'm not sure how to implement a print button.

I have devolped an application using a awt application now this application prints a report generated from the database my problem is i'm not sure on how to implement this print function my basic idea was when i click the button the dialong box for printing the application would come out is it somthing like this...

printButton.addActionListener (

new ActionListener() {

public void actionPerformed(ActionEvent e)

{

PrinterJob = PrinterJob.getPrinterJob();//get a printing object

printJob.setPageble(theApp.getView());//the view is the page source

if (printJob.printDialog());//display print dialog

{//if true is returned

}

}

);

is this it...

Thanks in advance!

your help is Greatly appreaciated

pal

[972 byte] By [palv] at [2007-9-26 2:21:47]
# 1

Hi everyone,

okie i have one error in implementing this print button which is type expected );

line 135

i've check through all the braces but there is nothing wrong with it

my codes are as below:

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import Jdbc;

class VrecPanel extends Panel

{

//Start of function

private static final int BUTTON_WIDTH = 100;

private static final int BUTTON_HEIGHT = 30;

Button cancelButton;

public VrecPanel ()

{

//Set GUI for VrecPanel

setBackground(Color.white);

setLayout(null);

setBounds(new Rectangle (300,200,500,400));

Label l3 = new Label("Tree Code:");

l3.setBounds(0,50,150,25);

add(l3);

final TextField tf = new TextField("",60);

tf.setBounds(160,50,150,25);

add(tf);

Label l4 = new Label("Tree Name:");

l4.setBounds(0,100,150,25);

add(l4);

Choice c = new Choice();

c.add("Select The Tree");

c.add("Mahogany");

c.add("Ebony");

c.add("Rosewood");

c.add("Teak");

c.setBounds(160,100,200,25);

add(c);

Label l5 = new Label("Height:");

l5.setBounds(0,150,150,25);

add(l5);

Label l8 = new Label("m");

l8.setBounds(260,150,150,25);

add(l8);

final TextField tf2 = new TextField("",10);

tf2.setBounds(161,150,100,25);

add(tf2);

Label l6 = new Label("Diameter:");

l6.setBounds(0,200,150,25);

add(l6);

Label l9 = new Label("cm");

l9.setBounds(261,200,150,25);

add(l9);

final TextField tf3 = new TextField("",10);

tf3.setBounds(160,200,100,25);

add(tf3);

Label l7 = new Label("Cycle Life:");

l7.setBounds(0,250,150,25);

add(l7);

final TextField tf4 = new TextField("",10);

tf4.setBounds(160,250,100,25);

add(tf4);

//The implementation of buttons

Button find = new Button("Find!!");

find.setBounds(301,50,80,25);

add(find);

Button pe = new Button("PREVIOUS");

pe.setBounds(120,330,BUTTON_WIDTH, BUTTON_HEIGHT);

add(pe);

Button nx = new Button("NEXT");

nx.setBounds(270,330,BUTTON_WIDTH, BUTTON_HEIGHT);

add(nx);

Button b1 = new Button("DELETE");

b1.setBounds(50,370,BUTTON_WIDTH, BUTTON_HEIGHT);

add(b1);

Button b2 = new Button("PRINT");

b2.setBounds(190,370,BUTTON_WIDTH, BUTTON_HEIGHT);

add(b2);

cancelButton = new Button("BACK");

cancelButton.setBounds(320,370, BUTTON_WIDTH, BUTTON_HEIGHT);

add(cancelButton);

//The implementation of ActionListener

cancelButton.addActionListener (

new ActionListener() {

public void actionPerformed(ActionEvent e)

{

RecordTFrame rc = MainFrame.TRecord;

rc.show();

RecordPanel.vr.dispose();

}

}

);

b2.addActionListener(

new ActionListener(){

public void actionPerformed (ActionEvent e)

{

PrinterJob = PrinterJob.getPrinterJob();//get a printing object

printJob.setPageble(theApp.getView());//the view is the page source

if (printJob.printDialog());//display print dialog

{//if true is returned

try

{

printJob.print();

}

catch(PrinterException pe)

{

System.out.println(pe);

JOptionPane.showMessageDialog(VrecPanel.this,

"Error printing a sketch.",

"Printer Error",

JOptionPane.ERROR_MESSAGE);

}

}

}

);

}

}//End of function

Thanks in advance

pal

palv at 2007-6-29 9:27:29 > top of Java-index,Archived Forums,Java Programming...
# 2
Hello,At the end of your code either this should not be there {//if true is returned or the ; should not be there and a } should be added for your if statement. cheers
nhanlon at 2007-6-29 9:27:29 > top of Java-index,Archived Forums,Java Programming...
# 3
Hey Nick,Thanks for the replay. I have tried it out but i would still get the same error. I just can fathome this error.Is there any other why i could actually eleminate this errorThanks again!pal
palv at 2007-6-29 9:27:29 > top of Java-index,Archived Forums,Java Programming...
# 4

At the end of your code, the last 7 lines are currently like this:JOptionPane.ERROR_MESSAGE);

}

}

}

);

}

}//End of function

You need to add another closing curly brace before the ");", ie:JOptionPane.ERROR_MESSAGE);

}

}

}

//ADD ANOTHER BRACE HERE:

}

//

);

}

}//End of function

artntek at 2007-6-29 9:27:29 > top of Java-index,Archived Forums,Java Programming...
# 5

Hi there,

Thanks for the info, i'm but i still do have a problem i'll get a whole bunch of errors on my declaration of my print button an cannot resove symbol on line 116,117,118,123,125 regarding the printer and set Pageble

my question is how do i print decarale this methods

using my source codes abave.

Thank you so much!

your help is GREATLY appreaciated!

Pal

palv at 2007-6-29 9:27:29 > top of Java-index,Archived Forums,Java Programming...