Munculkan Kotak Dialog Printer Dengan Java

sesuai permintaan mas gilang pada commentar Contoh Code Java Sederhana berikut saya sertakan source code dari bahasa java untuk menampilkan Kotak Dialog Printer Dengan Bahasa Java moga bermanfaat dan silahkan di kembangkan sendiri, semangat…😀

import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;
public class PrintDialog extends Panel implements Printable, ActionListener {
public PrintDialog() {
//memberi background dan membuat tombol
JButton tombol = new JButton(“Print Dialog”);
setBackground(Color.gray);
tombol.addActionListener(this);
add(tombol);
}

public void actionPerformed(ActionEvent e) {
//untuk pemanggilan printer dialog beserta penanganan error
PrinterJob printJob = PrinterJob.getPrinterJob();
if(printJob.printDialog()){
try { printJob.print(); } catch (Exception PrintException) { }
}
}

public int print(Graphics g, PageFormat pf, int pi){
//untuk eksekusi printer
if (pi >= 1) {
return Printable.NO_SUCH_PAGE;
}
Font  f = new Font(“Monospaced”,Font.PLAIN,12);
g.setFont (f);
paint (g);
return Printable.PAGE_EXISTS;
}

public static void main(String s[]){
//memanggil dan menyesuaikan frame serta tombol
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
};
Frame f = new Frame(“Print Dialog”);
f.addWindowListener(l);
f.add(“Center”, new PrintDialog());
f.pack();
f.setSize(new Dimension(400,300));
f.show();
}
}

berikut tampilkan prigramnya :

berikut tampilan setelah tombol di klik :

referensi : defeloper.sun

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s