Fri Feb 01, 2013 12:26 am
package ReportGen;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JFrame;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
/**
*
* @author sami
*/
/**
*
* @author user
*/
public class ReportPanel extends JFrame {
/** Creates a new instance of BorrowBookPanel */
public ReportPanel(Connection connection,JFrame myMother)
{
setTitle("Reports");
myconn=connection;
setSize(500,500);
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
BBew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BorrBReport();
}
}); BS.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BookSReport();
}
});
Me.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MemberReport();
}
});
setLayout(new FlowLayout());
add(BBew);
add(BS);
add(Me);
add(cancel);
}
public void BorrBReport()
{
String reportSource = "./reports/BorrowedBooks.jrxml";
String reportDest = "./reports/BorrowedBooks.html";
Map<String, Object> params = new HashMap<String, Object>();
params.put("reportTitle", "Borrowed Books");
params.put("author", "Casper");
params.put("startDate", (new java.util.Date()).toString());
try
{
JasperReport jasperReport =
JasperCompileManager.compileReport(reportSource);
// Make the driver class available.
JasperPrint jasperPrint =
JasperFillManager.fillReport(
jasperReport, params, myconn);
JasperExportManager.exportReportToHtmlFile(
jasperPrint, reportDest);
JasperViewer.viewReport(jasperPrint);
}
catch (JRException ex)
{
ex.printStackTrace();
}
}
public void MemberReport()
{
String reportSource = "./reports/Member.jrxml";
String reportDest = "./reports/Member.html";
Map<String, Object> params = new HashMap<String, Object>();
params.put("reportTitle", "Members");
params.put("author", "Casper");
params.put("startDate", (new java.util.Date()).toString());
try
{
JasperReport jasperReport =
JasperCompileManager.compileReport(reportSource);
// Make the driver class available.
JasperPrint jasperPrint =
JasperFillManager.fillReport(
jasperReport, params, myconn);
JasperExportManager.exportReportToHtmlFile(
jasperPrint, reportDest);
JasperViewer.viewReport(jasperPrint);
}
catch (JRException ex)
{
ex.printStackTrace();
}
}
public void BookSReport()
{
String reportSource = "./reports/BookStore.jrxml";
String reportDest = "./reports/BookStore.html";
Map<String, Object> params = new HashMap<String, Object>();
params.put("reportTitle", "Book Store");
params.put("author", "Casper");
params.put("startDate", (new java.util.Date()).toString());
try
{
JasperReport jasperReport =
JasperCompileManager.compileReport(reportSource);
// Make the driver class available.
JasperPrint jasperPrint =
JasperFillManager.fillReport(
jasperReport, params, myconn);
JasperExportManager.exportReportToHtmlFile(
jasperPrint, reportDest);
JasperViewer.viewReport(jasperPrint);
}
catch (JRException ex)
{
ex.printStackTrace();
}
}
private JButton BBew=new JButton("Borrowed Book");
private JButton BS=new JButton("Book Store");
private JButton Me=new JButton("Members ");
private JButton cancel=new JButton("Cancel");
private Connection myconn;
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.