0% found this document useful (0 votes)
45 views

Codingan Cetak

This Java code defines a class called Akademik that extends JFrame. It creates a GUI with labels, text fields, and buttons to print a report on student data from a MySQL database. When the "Cetak" button is clicked, it calls the cetak() method, which loads a JasperReport file, fills it with data from the database using JasperFillManager, and displays it using JasperViewer. The main method sets the LookAndFeel and creates an instance of Akademik to display the GUI.

Uploaded by

Talimatun Najiha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Codingan Cetak

This Java code defines a class called Akademik that extends JFrame. It creates a GUI with labels, text fields, and buttons to print a report on student data from a MySQL database. When the "Cetak" button is clicked, it calls the cetak() method, which loads a JasperReport file, fills it with data from the database using JasperFillManager, and displays it using JasperViewer. The main method sets the LookAndFeel and creates an instance of Akademik to display the GUI.

Uploaded by

Talimatun Najiha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

/*

* @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();

You might also like