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 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() {

  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// these codes use for select image from local machine       
JFileChooser fchoser=new JFileChooser();
        File f=fchoser.getSelectedFile();
        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; ( !=-1;)
            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();
        //id number generate
        String year= birthday.substring(2, 4);
       // JOptionPane.showMessageDialog(rootPane, year);
        int genvalue=0;
        if(gender.equals("Male")) // 
        String gen = String.valueOf(genvalue);
        String las = String.valueOf(lvalue);
        String nic= year+gen+las+"V";

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();
        } 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);
         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

Download source codes of id card generator project


Check more projects>>

Be the first to comment

Leave a Reply

Your email address will not be published.