com.java4less.qrcode
Class QRCode

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by com.java4less.qrcode.QRCode
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class QRCode
extends java.awt.Canvas

This class creates QR Code symbols. Since it is a subclass of java.awt.Canvas it can be added to any Java container.
Image files can be created with the following code:

QRCode barcode=new QRCode();
barcode.setCode("ABC");
barcode.setSize(300,300);
ImageEncoder be= new ImageEncoder(barcode,"JPEG","barcode.jpg");


If you want to create gif or png files you will need to download the encoders:
- gif encoder from http://www.acme.com/resources/classes/Acme.tar.gz
- png encoder http://users.boone.net/wbrameld/pngencoder


The barcode can also be painted in a external graphic context, for example an image:

java.awt.image.BufferedImage im=new java.awt.image.BufferedImage(barcode.getWidth(),barcode.getHeight(),java.awt.image.BufferedImage.TYPE_INT_RGB);
Graphics g2=im.createGraphics();
barcode.paint(g2);

See Also:
Serialized Form

Field Summary
static int CORRECTION_LEVEL_H
           
static int CORRECTION_LEVEL_L
           
static int CORRECTION_LEVEL_M
           
static int CORRECTION_LEVEL_Q
           
static int ENC_ALPHA
           
static int ENC_AUTO
           
static int ENC_BYTE
           
static int ENC_KANJI
           
static int ENC_NUMERIC
           
static int FNC1_MODE_FIRST
           
static int FNC1_MODE_NO
           
static int FNC1_MODE_SECOND
           
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
QRCode()
           
 
Method Summary
 byte getApplicationIndicator()
          application indicator if Fnc1Mode is FNC1_MODE_SECOND
 boolean getAutoConfigurate()
          allow automatic selection of a larger configuration (than the preferred) if code is too large.
 java.awt.Color getBackColor()
          background color.
 java.awt.Color getBarColor()
          color of the bars.
 java.lang.String getCode()
          text to be painted as barcode.
 int[] getCodeBinary()
          bytes to be painted as barcode.
 int getCurrentX()
          get last X possition.
 int getCurrentY()
          get last Y possition.
 int getECI()
          Extended Channel Interpretation.
 int getEncoding()
           Encoding mode (default is AUTO).
 int getErrorCorrectionLevel()
           Error correction level.
 int getFnc1Mode()
          get FNC1 mode (FNC1_MODE_NO, FNC1_MODE_FIRST or FNC1_MODE_SECOND)
 int getMargin()
          margin of the barcode (also know as quite zone).
 double getModuleSize()
          size (width) of the bars (module).
 java.lang.String getName()
          Returns "QRCode".
 int getPreferredVersion()
          use this configuration if possible.
 boolean getProcessTilde()
          process tilde.
 boolean getRedraw()
          Redraw symbol
 boolean getStructuredAppend()
          activate structured append
 int getStructuredAppendCounter()
          number of symbols in structured append (value 1 to 16)
 int getStructuredAppendIndex()
          current symbol in structured append (value 1 to 16)
 void paint(java.awt.Graphics g)
          paints the symbol.
 void setApplicationIndicator(byte b)
          application indicator if Fnc1Mode is FNC1_MODE_SECOND
 void setAutoConfigurate(boolean pt)
          allow automatic selection of a larger configuration (than the preferred) if code is too large.
 void setBackColor(java.awt.Color c)
          background color.
 void setBarColor(java.awt.Color c)
          color of the bars.
 void setCode(int[] c)
          bytes to be painted as barcode.
 void setCode(java.lang.String c)
          text to be painted as barcode.
 void setECI(int v)
          Extended Channel Interpretation.
 void setEncoding(int d)
           Encoding mode (default is AUTO).
 void setErrorCorrectionLevel(int d)
           Error correction level.
 void setFnc1Mode(int mode)
          sets the FNC1 mode (FNC1_MODE_NO, FNC1_MODE_FIRST or FNC1_MODE_SECOND)
 void setMargin(int d)
          margin of the barcode (also know as quite zone).
 void setModuleSize(int d)
          size (width) of the bars (module).
 void setPreferredVersion(int r)
          use this configuration if possible.
 void setProcessTilde(boolean pt)
          process tilde.
 void setRedraw(boolean b)
          Redraw symbol.
 void setStructuredAppend(boolean b)
          activate structured append
 void setStructuredAppendCounter(int i)
          number of symbols in structured append (value 1 to 16)
 void setStructuredAppendIndex(int i)
          current symbol in structured append (value 1 to 16)
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ENC_ALPHA

public static final int ENC_ALPHA
See Also:
Constant Field Values

ENC_BYTE

public static final int ENC_BYTE
See Also:
Constant Field Values

ENC_NUMERIC

public static final int ENC_NUMERIC
See Also:
Constant Field Values

ENC_KANJI

public static final int ENC_KANJI
See Also:
Constant Field Values

ENC_AUTO

public static final int ENC_AUTO
See Also:
Constant Field Values

FNC1_MODE_NO

public static final int FNC1_MODE_NO
See Also:
Constant Field Values

FNC1_MODE_FIRST

public static final int FNC1_MODE_FIRST
See Also:
Constant Field Values

FNC1_MODE_SECOND

public static final int FNC1_MODE_SECOND
See Also:
Constant Field Values

CORRECTION_LEVEL_L

public static int CORRECTION_LEVEL_L

CORRECTION_LEVEL_M

public static int CORRECTION_LEVEL_M

CORRECTION_LEVEL_Q

public static int CORRECTION_LEVEL_Q

CORRECTION_LEVEL_H

public static int CORRECTION_LEVEL_H
Constructor Detail

QRCode

public QRCode()
Method Detail

getPreferredVersion

public int getPreferredVersion()
use this configuration if possible. Valid values are 1 to 40.


setPreferredVersion

public void setPreferredVersion(int r)
use this configuration if possible. Valid values are 1 to 40.


getCode

public java.lang.String getCode()
text to be painted as barcode.


setCode

public void setCode(java.lang.String c)
text to be painted as barcode.


getECI

public int getECI()
Extended Channel Interpretation. The default value is -1 (disabled).


setECI

public void setECI(int v)
Extended Channel Interpretation. The default value is -1 (disabled).


getCodeBinary

public int[] getCodeBinary()
bytes to be painted as barcode.


setCode

public void setCode(int[] c)
bytes to be painted as barcode.


getMargin

public int getMargin()
margin of the barcode (also know as quite zone). The default is 20 pixels.


setMargin

public void setMargin(int d)
margin of the barcode (also know as quite zone). The default is 20 pixels.


getEncoding

public int getEncoding()
 Encoding mode (default is AUTO). Valid values are:
      
  • AUTO: Automatic selecting of the encoding method.
  • ALPHA: encode alpahnumeric characters only (upper case letter plus 9 additional characters).
  • NUMERIC: encode alpahnumeric digits only.
  • BYTE: use this mode to encode binary data.
  • KANJI: encodes Kanji characters only.


setEncoding

public void setEncoding(int d)
 Encoding mode (default is AUTO). Valid values are:
      
  • AUTO: Automatic selecting of the encoding method.
  • ALPHA: encode alpahnumeric characters only (upper case letter plus 9 additional characters).
  • NUMERIC: encode alpahnumeric digits only.
  • BYTE: use this mode to encode binary data.
  • KANJI: encodes Kanji characters only.


getBackColor

public java.awt.Color getBackColor()
background color.


setBackColor

public void setBackColor(java.awt.Color c)
background color.


getBarColor

public java.awt.Color getBarColor()
color of the bars.


setBarColor

public void setBarColor(java.awt.Color c)
color of the bars.


getName

public java.lang.String getName()
Returns "QRCode".

Overrides:
getName in class java.awt.Component

getModuleSize

public double getModuleSize()
size (width) of the bars (module). The default value is 4.


setModuleSize

public void setModuleSize(int d)
size (width) of the bars (module). The default value is 4.


getErrorCorrectionLevel

public int getErrorCorrectionLevel()
 Error correction level. Valid values are:
         
  • CORRECTION_LEVEL_L (default). About 7% recovery capacity.
  • CORRECTION_LEVEL_M: About 15% recovery capacity.
  • CORRECTION_LEVEL_Q: About 25% recovery capacity.
  • CORRECTION_LEVEL_H: About 30% recovery capacity.


setErrorCorrectionLevel

public void setErrorCorrectionLevel(int d)
 Error correction level. Valid values are:
         
  • CORRECTION_LEVEL_L (default). About 7% recovery capacity.
  • CORRECTION_LEVEL_M: About 15% recovery capacity.
  • CORRECTION_LEVEL_Q: About 25% recovery capacity.
  • CORRECTION_LEVEL_H: About 30% recovery capacity.


getProcessTilde

public boolean getProcessTilde()
process tilde.


setProcessTilde

public void setProcessTilde(boolean pt)
process tilde. if true (default) the tilde character (~) will be processed like this:

~~: will be replaced with ~
~dxxx: will be replaced by the character whose ascii code is xxx. For example ~d065 will be replaced with A.


getRedraw

public boolean getRedraw()
Redraw symbol


setRedraw

public void setRedraw(boolean b)
Redraw symbol. Set this property to true if you change any property of the barcode and you want to rebuild it.


getFnc1Mode

public int getFnc1Mode()
get FNC1 mode (FNC1_MODE_NO, FNC1_MODE_FIRST or FNC1_MODE_SECOND)


setFnc1Mode

public void setFnc1Mode(int mode)
sets the FNC1 mode (FNC1_MODE_NO, FNC1_MODE_FIRST or FNC1_MODE_SECOND)


getApplicationIndicator

public byte getApplicationIndicator()
application indicator if Fnc1Mode is FNC1_MODE_SECOND


setApplicationIndicator

public void setApplicationIndicator(byte b)
application indicator if Fnc1Mode is FNC1_MODE_SECOND


getAutoConfigurate

public boolean getAutoConfigurate()
allow automatic selection of a larger configuration (than the preferred) if code is too large.


setAutoConfigurate

public void setAutoConfigurate(boolean pt)
allow automatic selection of a larger configuration (than the preferred) if code is too large.


setStructuredAppend

public void setStructuredAppend(boolean b)
activate structured append


getStructuredAppend

public boolean getStructuredAppend()
activate structured append


setStructuredAppendCounter

public void setStructuredAppendCounter(int i)
number of symbols in structured append (value 1 to 16)


getStructuredAppendCounter

public int getStructuredAppendCounter()
number of symbols in structured append (value 1 to 16)


setStructuredAppendIndex

public void setStructuredAppendIndex(int i)
current symbol in structured append (value 1 to 16)


getStructuredAppendIndex

public int getStructuredAppendIndex()
current symbol in structured append (value 1 to 16)


paint

public void paint(java.awt.Graphics g)
paints the symbol.

Overrides:
paint in class java.awt.Canvas

getCurrentX

public int getCurrentX()
get last X possition. Use this property to find out the size in pixels of the barcode.


getCurrentY

public int getCurrentY()
get last Y possition. Use this property to find out the size in pixels of the barcode.