Skip to content

Instantly share code, notes, and snippets.

@resarahadian
Created April 26, 2012 17:23
Show Gist options
  • Save resarahadian/2501100 to your computer and use it in GitHub Desktop.
Save resarahadian/2501100 to your computer and use it in GitHub Desktop.
Java dan iReport 1
/*
* @author Resa C.R
*/
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.util.*;
import net.sf.jasperreports.view.*;
import java.util.*;
import java.io.*;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Akademik extends JFrame
{
Container konten = getContentPane();
private JLabel lblCetak = new JLabel("Cetak Laporan Data Mahasiswa",SwingConstants.CENTER);
private JLabel lblNIM = new JLabel("NIM : ");
private JTextField txtNIM = new JTextField();
private JButton btnCetak = new JButton("Cetak");
//Konstruktor
public Akademik()
{
super("iReport");
setSize(700,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
konten.setLayout(null);
lblCetak.setBounds(200,30,300,25);
konten.add(lblCetak);
btnCetak.setBounds(230,170,240,70);
konten.add(btnCetak);
btnCetak.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent act)
{
// TODO Auto-generated method stub
cetak();
}
});
}//Akhir Konstruktor
public void cetak()
{
try
{
String namaFile = "src/ireport/aplikasi/iReport/Laporan Mahasiswa.jasper";
String Driver = "com.mysql.jdbc.Driver";
String koneksi = "jdbc:mysql://localhost/akademik";
String user = "root";
String password = "root";
HashMap hash = new HashMap();
Class.forName(Driver);
Connection con = DriverManager.getConnection(koneksi,user,password);
File file = new File(namaFile);
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(file.getPath());
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, hash, con);
JasperViewer.viewReport(jasperPrint,false);
}
catch(Exception ex)
{
System.out.println(ex);
}
}
public static void main(String[] ar)
{
//Look and Feel Java
try
{
UIManager.setLookAndFeel("com.easynth.lookandfeel.EaSynthLookAndFeel");
}
catch (Exception e)
{
e.printStackTrace();
}
new Akademik();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment