Skip to content

Instantly share code, notes, and snippets.

@resarahadian
Created May 15, 2012 00:25
Show Gist options
  • Save resarahadian/2698266 to your computer and use it in GitHub Desktop.
Save resarahadian/2698266 to your computer and use it in GitHub Desktop.
Program Java Ireport dengan Parameter
/**
*
* @author Resa C.R
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.sql.*;
import java.util.HashMap;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.util.*;
import net.sf.jasperreports.view.*;
public class IReport extends JFrame
{
Container konten = getContentPane();
private JLabel lblJudul = new JLabel("Cetak Laporan Data Mahasiswa");
private JLabel lblNIM = new JLabel("Masukkan NIM : ");
private JTextField txtNIM = new JTextField();
private JButton btnCetak = new JButton("Cetak");
private JButton btnBatal = new JButton("Batal");
//Konstruktor
public IReport()
{
setTitle("Laporan Data Mahasiswa");
setSize(700,600);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
konten.setLayout(null);
lblJudul.setBounds(200,30,300,25);
konten.add(lblJudul);
lblNIM.setBounds(160,100,200,25);
konten.add(lblNIM);
txtNIM.setBounds(320,100,280,25);
konten.add(txtNIM);
btnCetak.setBounds(200,200,100,25);
konten.add(btnCetak);
btnBatal.setBounds(400,200,100,25);
konten.add(btnBatal);
btnCetak.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent act)
{
try
{
String NamaFile = "src/ireport/Laporan Data Mahasiswa.jasper";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection koneksi = DriverManager.getConnection("jdbc:mysql://localhost/Data","root","root");
HashMap hash = new HashMap();
//Mengambil parameter dari ireport
hash.put("nim",txtNIM.getText());
File file = new File(NamaFile);
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(file.getPath());
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, hash,koneksi);
JasperViewer.viewReport(jasperPrint);
}
catch(Exception ex)
{
System.out.println(ex);
}
}
});
}//Akhir Konstruktor
public static void main(String[] ar)
{
//Look and Feel dengan JTattoo
try {
com.jtattoo.plaf.mcwin.McWinLookAndFeel.setTheme("Giant-Font", "Laporan Data Mahasiswa", "iReport");
UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
new IReport();
} catch (Exception ex)
{
ex.printStackTrace();
}
}
}
@bayhaqi75
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment