id card generator project in java with source code

In this tutorial guide you, how to develop a simple id card generator project using java programming language. Here I used two conditions to generate the different numbers of ID cards. Further, you can print the front and back end of this ID card. Follow these steps to develop this application.

Step 01: Start a new java project.

Step 02: Design project interface like this image.

ID card front and back end design in the same panel and that panel should be separate from other components of the interface. Because of that panel used for the printing process. A label uses to store the image.

Step 03: Used these source codes of id card generator project

The source codes definition have added as comments


package idcardgeneratingsystem;
//import these libraries
import java.awt.Graphics;
import java.awt.Image;
import java.awt.PrintJob;
import java.awt.Toolkit;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextField;


public class Home extends javax.swing.JFrame {

    /**
     * Creates new form Home
     */
    private ImageIcon format=null;
    String fname=null;
    int s=0;
    byte[] pimage=null;
    int lvalue = 1000;
    
    public Home() {
        initComponents();
    }

  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// these codes use for select image from local machine       
JFileChooser fchoser=new JFileChooser();
        fchoser.showOpenDialog(null);
        File f=fchoser.getSelectedFile();
        fname=f.getAbsolutePath();
        ImageIcon micon=new ImageIcon(fname);        
        try {
            File image=new File(fname);
            FileInputStream fis=new FileInputStream(image);
            ByteArrayOutputStream baos=new ByteArrayOutputStream();
            byte[] buf=new byte[1024];
            for(int readnum; (readnum=fis.read(buf)) !=-1;)
            {            
                baos.write(buf,0,readnum);                
            }
            pimage=baos.toByteArray();
            lblimage.setIcon(resizeImage(fname, buf));
        } catch (Exception e) {
        }   
    }  



 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// Thse codes use for set details on printing panel        
String cou=txtcountry.getText();
        String date=((JTextField)idate.getDateEditor().getUiComponent()).getText();
        String birthday=((JTextField)bdate.getDateEditor().getUiComponent()).getText();
        String name= txtname.getText();
        String adress= txtadress.getText();
        String gender = cmbgender.getSelectedItem().toString();
        String info = txtinfo.getText();
        
        
        
        lblcountry.setText(cou);
        lbldate.setText(date);
        lblbcountry.setText(cou);
        lblname.setText(name);
        lblbday.setText(birthday);
        lbladress.setText(adress);
        lblgender.setText(gender);
        lblinfor.setText(info);
        
        //id number generate
        String year= birthday.substring(2, 4);
       // JOptionPane.showMessageDialog(rootPane, year);
        int genvalue=0;
        if(gender.equals("Male")) // 
        {
            genvalue=100;
        }
        else{
            genvalue=500;
        }
        
        lvalue++;
        
        String gen = String.valueOf(genvalue);
        String las = String.valueOf(lvalue);
        String nic= year+gen+las+"V";
        
        lblnic.setText(nic);
        
        
        
        
        
    }                                        

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// these codes use to print panel       
  try {
            Toolkit tkp = panelid.getToolkit();
    PrintJob pjp = tkp.getPrintJob(this, null, null);
    Graphics g = pjp.getGraphics();
    panelid.print(g);
    g.dispose();
    pjp.end();
            
        } catch (Exception e) {
        }
    }       

This method use to resize image to fit lable
 public ImageIcon resizeImage(String imagePath, byte[] pic){
          
        ImageIcon myImage=null;
        if(imagePath !=null)
        {
        myImage=new ImageIcon(imagePath);
        
        }else{
         myImage=new ImageIcon(pic);
        }
                
        Image img=myImage.getImage();
        Image img2=img.getScaledInstance(lblimage.getHeight(), lblimage.getWidth(),  Image.SCALE_SMOOTH);
        ImageIcon image=new ImageIcon(img2);
        return image;
    } 

Running interface of id card generator project.

id card generator project - java project

The technologies used in id card generator project.

  • Java: All codes have been written using the java programming language.
  • MySql: MySql has used as a database for this project.
  • Netbeans: This project has developed inside of the Netbeans IDE.

How to use this
You can download the complete project file and database using the below link.

The goals of providing this project:

  • To provide an example for students to develop their own projects.
  • helping people create their projects.
  • sharing knowledge and codes for educational purpose.

This project is not for:

  • You cannot use this project or project source codes for commercial purposes
  • You cannot re-upload this project or project source code to web internet or any kind of space.

Copyright © codeguid

Do you need help to remotely set up my any project on your machine or customize any project with your requirement please contact  syntech1994@gmail.com

Download source codes of id card generator project

875 Downloads

Check more projects>>

Be the first to comment

Leave a Reply

Your email address will not be published.


*