  | 
              
	              
	                
 
  
    |   | 
   
  
    
        
        Java - ถามเกี่ยวกับ JasperReport ครับ ถ้าต้องการ Input ข้อมูล โดยไม่ยุ่งกับ Database มีวิธีเขียนแบบไหนมั่งครับ ??     | 
   
  
    |   | 
   
 
 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ใช้พวก List ได้ครับ เช่น 
 
Code (Java) 
 private class R{
  private String name;
  private String addr;
  public R(String name, String addr) {
   super();
   this.name = name;
   this.addr = addr;
  }
  public String getName() {
   return name;
  }
  public void setName(String name) {
   this.name = name;
  }
  public String getAddr() {
   return addr;
  }
  public void setAddr(String addr) {
   this.addr = addr;
  }
 }
 
 
Code (Java) 
   List<R> list = new ArrayList<R>(5);
   Map parameters = new HashMap();
   list.add(new R("a1" ,"a2"));
   list.add(new R("b1" ,"b2"));
   list.add(new R("c1" ,"c2"));
 
 
Code (Java) 
JasperPrint print = JasperFillManager.fillReport( fileName, parameters, new JRBeanCollectionDataSource(list));
                         
               
               | 
             
            
              
			  			  
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-01-23 10:19:32 | 
                        By :
                            mr.win | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 เขียนไว้แบบไหนบ้างครับ                        
               
               | 
             
            
              
			  			  
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-01-23 19:41:43 | 
                        By :
                            mr.win | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Code ทั้งหมดก็ตามนี้อะครับ 
 
Code 
package Report.Array;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.swing.JRViewer;
import net.sf.jasperreports.view.JasperViewer;
public class MyForm extends JFrame {
	private class R {
		private String CustomerID;
		private String FName;
		private String LName;
		private int Ages;
		private int Salary;
		public R(String CustomerID, String FName, String LName, int Ages,
				int Salary) {
			super();
			this.CustomerID = CustomerID;
			this.FName = FName;
			this.LName = LName;
			this.Ages = Ages;
			this.Salary = Salary;
		}
		public String getCustomerID() {
			return CustomerID;
		}
		public void setCustomerID(String customerID) {
			CustomerID = customerID;
		}
		public String getFName() {
			return FName;
		}
		public void setFName(String fName) {
			FName = fName;
		}
		public String getLName() {
			return LName;
		}
		public void setLName(String lName) {
			LName = lName;
		}
		public int getAges() {
			return Ages;
		}
		public void setAges(int ages) {
			Ages = ages;
		}
		public int getSalary() {
			return Salary;
		}
		public void setSalary(int salary) {
			Salary = salary;
		}
	}
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				MyForm frame = new MyForm();
				frame.setVisible(true);
			}
		});
	}
	/**
	 * Create the frame.
	 */
	public MyForm() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 431, 286);
		setTitle("Chose Report");
		getContentPane().setLayout(null);
		// Button Report
		JButton btnOpenReport = new JButton("Open Report");
		btnOpenReport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Connection connect = null;
				// try {
				// Class.forName("com.mysql.jdbc.Driver");
				// connect =
				// DriverManager.getConnection("jdbc:mysql://localhost/databasenull"
				// +
				// "?user=root&password=root");
				// } catch (ClassNotFoundException e1) {
				// TODO Auto-generated catch block
				// e1.printStackTrace();
				// } catch (SQLException e) {
				// TODO Auto-generated catch block
				// e.printStackTrace();
				// }
				// Application path
				String report = null;
				try {
					report = new File(".").getCanonicalPath()
							+ "\\nullReport.jrxml";
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				try {
					List<R> list = new ArrayList<R>(5);
					Map parameters = new HashMap();
					list.add(new R("C002", "Hang", "Over", 25, 24000));
					list.add(new R("C003", "Ying", "Leee", 23, 43000));
					// Report Viewer
					JasperReport ir = JasperCompileManager
							.compileReport(report);
					JasperPrint print = JasperFillManager.fillReport(ir,
							parameters, new JRBeanCollectionDataSource(list));
					JFrame frame = new JFrame();
					frame.setTitle("ShowReport");
					frame.setBounds(100, 100, 800, 600);
					frame.getContentPane().add(new JRViewer(print));
					frame.setVisible(true);
				} catch (JRException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				try {
					connect.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		btnOpenReport.setBounds(137, 98, 146, 23);
		getContentPane().add(btnOpenReport);
		setResizable(false);
	}
}
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-01-23 22:39:52 | 
                        By :
                            13laZzE12 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
      		  
	
     | 
   
 
                 |