Coders Packet

GUI based Profile QR code Generator using Java

By Kirti Sandip Phegade

In order to Develop the GUI-based QR code generator we use Java programming language and some swing components like JLabel, JButton,JFiled, and JTextfiled.

A QR code is nothing but the style of barcode which will browse simply by a digital device and that stores data as a series of pixels in the square-shaped grid. This code is used when we want to store some important information and links in a small square-shaped grid in the form of pixels.

Program to generate QR code in Java

To develop a QR code generator in java programming we need to all some external libraries which are listed below.
1) qrgen -1.0
2) zxing-core-1.7
3) zxing-j2se-1.7

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType; public class Main_Qr_Genarator extends JFrame { JButton submitdata, Qrdata; JTextField textID, textname, textemail; JTextArea area; Main_Qr_Genarator() { setBounds(500,100,450,650); //getContentPane().setBackground(Color.WHITE); JLabel mainheading = new JLabel("QR Generator"); mainheading.setBounds(150,20,200,50); mainheading.setFont(new Font("Rockwell Extra Bold",Font.PLAIN,23)); add(mainheading); JLabel entername = new JLabel("Name:-"); entername.setBounds(30,98,150,50); entername.setFont(new Font("Charcoal CY",Font.PLAIN,18)); add(entername); JLabel enterphone = new JLabel("ID number:-"); enterphone.setBounds(30,150,120,30); enterphone.setFont(new Font("Charcoal CY",Font.PLAIN,18)); add(enterphone); JLabel enteremail = new JLabel("Email ID:-"); enteremail.setBounds(30,200,120,30); enteremail.setFont(new Font("Charcoal CY",Font.PLAIN,18)); add(enteremail); textname = new JTextField(); textname.setBounds(150,100,220,30); textname.setFont(new Font("Charcoal CY",Font.PLAIN,18)); add(textname); textID = new JTextField(); textID.setBounds(150,150,220,30); textID.setFont(new Font("Charcoal CY",Font.PLAIN,18)); add(textID); textemail = new JTextField(); textemail.setBounds(150,200,220,30); textemail.setFont(new Font("Charcoal CY",Font.PLAIN,18)); add(textemail); submitdata = new JButton("Submit Data"); submitdata.setBounds(150,250,200,30); submitdata.setFocusable(false); submitdata.setFont(new Font("Mongolian Baiti",Font.BOLD,16)); submitdata.setBackground(; submitdata.setForeground(Color.WHITE); add(submitdata); submitdata.addActionListener(this::submit_Button_Action); area = new JTextArea("\tProfile Data\n"); area.setBounds(60,320,300,200); area.setFont(new Font("Charcoal CY",Font.PLAIN,18)); add(area); Qrdata = new JButton("Generate QR Code"); Qrdata.setBounds(120,550,200,30); Qrdata.setFocusable(false); Qrdata.setFont(new Font("Mongolian Baiti",Font.BOLD,16)); Qrdata.setBackground(; Qrdata.setForeground(Color.WHITE); add(Qrdata); Qrdata.addActionListener(this::Generate_Button_Action); setLayout(null); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } private void Generate_Button_Action(ActionEvent actionEvent) { try{ File file1 = new File("src/QR_Code_Image/QRcodeimg.png"); String data = String.format(area.getText()); ByteArrayOutputStream out = QRCode.from(data).withSize(250, 250).to(ImageType.PNG).stream(); FileOutputStream fos = new FileOutputStream(file1); out.writeTo(fos); out.flush(); fos.close(); System.out.println("Done"); } catch(Exception e){ System.out.println(e); } } private void submit_Button_Action(ActionEvent actionEvent) { if (textname.getText().isEmpty() && textID.getText().isEmpty()) { JOptionPane.showMessageDialog(null, "Please Enter Details","Getting Error", JOptionPane.ERROR_MESSAGE); } else { String name = String.format(textname.getText()); String phone = String.format(textID.getText()); String email = String.format(textemail.getText()); area.append("\n Name:- " + name + "\n Phone Number:- " + phone+ "\n Email ID:- "+ email); } } public static void main(String[] args) { new Main_Qr_Genarator(); } }

We use QRCode.from() static method in this method where we pass some arguments the Profile data and then we configure the necessary configurations like width and height as well as image type, etc. Then, we call the stream() method. This returns a ByteArrayOutputStream with the corresponding generated QR Code. This Generated QR code we store in the QR_Code_Image folder in the form of .png

OutPut Of Program

1) provide Input:- 

GUI of QR code generator

In this Profile QR code generator project we provide some data as input. then by clicking on submit data button All profile data is display in JTextarea. now click on Generate QR Code button to generate QR code. this will Generate QR code in .png format.

 QR code

2) Scan QR Code:-

read QR code

When we scan QR code then all Profile data is displayed

Download project

Reviews Report

Submitted by Kirti Sandip Phegade (KirtiPhegade)

Download packets of source code on Coders Packet