zxing qr code generator java example C H A P T ER 7 in Java

Printing QR Code in Java C H A P T ER 7

C H A P T ER 7
QR-Code Drawer In Java
Using Barcode maker for Java Control to generate, create QR Code image in Java applications.
www.OnBarcode.com
Decoding QR Code In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
CONNECTING TO THE INTERNET
Print EAN / UCC - 14 In Java
Using Barcode creator for Java Control to generate, create GS1-128 image in Java applications.
www.OnBarcode.com
Generating Code 128A In Java
Using Barcode generator for Java Control to generate, create Code 128 Code Set B image in Java applications.
www.OnBarcode.com
displayMngr.setCurrent(symbolAlert, entryForm); } } } } }; entryForm.setItemStateListener(itemListener); entryForm.setCommandListener(commandListener); } private void displayEntryForm () { if (entryForm == null) { entryForm = new EntryForm("ObtainQuote"); } initListener(); displayMngr.setCurrent(entryForm); } private void displayPrice(String quoteString) { if (resultsAlert == null) { resultsAlert = new Alert("Quote Price", null, null, AlertType.CONFIRMATION); resultsAlert.setTicker(adTicker); resultsAlert.setTimeout(Alert.FOREVER); } resultsAlert.setString(quoteString); displayMngr.setCurrent(resultsAlert, entryForm); }
Draw ANSI/AIM Code 39 In Java
Using Barcode maker for Java Control to generate, create Code 3 of 9 image in Java applications.
www.OnBarcode.com
Paint GS1 - 13 In Java
Using Barcode generation for Java Control to generate, create EAN-13 image in Java applications.
www.OnBarcode.com
private void storePrice(String symbol, int[] price) { String newRecord = symbol + ";" + price[0] + ";" + price[1]; byte[] byteRec; try { RecordStore anRMS = RecordStore.openRecordStore("Quotes" , true); RecordFilter rf = new QuoteFilter(symbol); RecordEnumeration rEnum = anRMS.enumerateRecords(rf,null,false); if (rEnum.hasNextElement()) { int recId = rEnum.nextRecordId(); newRecord += ';' + getLastPrice(anRMS.getRecord(recId)); byteRec = newRecord.getBytes(); anRMS.setRecord(recId,byteRec,0,byteRec.length); } else { byteRec = newRecord.getBytes(); anRMS.addRecord(byteRec,0,byteRec.length); } rEnum.destroy(); anRMS.closeRecordStore(); } catch (RecordStoreFullException fullStore) { //handle a full record store problem } catch (RecordStoreNotFoundException notFoundException) { //handle store not found which should not happen with the } catch (RecordStoreException recordStoreException) { //handling record store problems
Barcode Generator In Java
Using Barcode creator for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
Draw Leitcode In Java
Using Barcode creator for Java Control to generate, create Leitcode image in Java applications.
www.OnBarcode.com
IMPLEMENTING THE INTERNET INVESTMENT QUOTE SERVICE
QR Maker In Objective-C
Using Barcode generator for iPad Control to generate, create QR Code image in iPad applications.
www.OnBarcode.com
Paint QR Code ISO/IEC18004 In VS .NET
Using Barcode generator for ASP.NET Control to generate, create Quick Response Code image in ASP.NET applications.
www.OnBarcode.com
} } private int[] parsePrices(byte[] quoteRec) { String rec = new String(quoteRec); int dollar1Pos = rec.indexOf(';'); int cent1Pos = rec.indexOf(';',dollar1Pos+1); int dollar2Pos = rec.indexOf(';',cent1Pos + 1); if (dollar2Pos > 0) { //had a historical price int cent2Pos = rec.indexOf(';',dollar2Pos + 1); int currentDollars = Integer.parseInt(rec.substring(dollar1Pos + 1,cent1Pos)); int currentCents = Integer.parseInt(rec.substring(cent1Pos + 1,dollar2Pos)); int historicalDollars = Integer.parseInt(rec.substring(dollar2Pos + 1,cent2Pos)); int historicalCents = Integer.parseInt(rec.substring(cent2Pos + 1)); int[] returnPrices = {currentDollars, currentCents, historicalDollars, historicalCents}; return returnPrices; } else { //no previous historical price int currentDollars = Integer.parseInt(rec.substring(dollar1Pos + 1, cent1Pos)); int currentCents = Integer.parseInt(rec.substring(cent1Pos + 1)); int[] returnPrices = {currentDollars, currentCents}; return returnPrices; } } private String getLastPrice(byte[] rec) { String recString = new String(rec); int dollarPos = recString.indexOf(';'); int centPos = recString.indexOf(';',dollarPos+1); int centEnd = recString.indexOf(';',centPos + 1); if (centEnd > 0) //had a historical price return recString.substring(dollarPos+1,centEnd); else //no previous historical price return recString.substring(dollarPos+1); } protected void startApp() { displayMngr = Display.getDisplay(this); displayEntryForm(); } protected void pauseApp() { } protected void destroyApp(boolean unconditional) { notifyDestroyed(); } public void commandAction(Command c, Displayable s) { } }
Generate EAN / UCC - 13 In .NET
Using Barcode creation for Reporting Service Control to generate, create European Article Number 13 image in Reporting Service applications.
www.OnBarcode.com
Printing Data Matrix ECC200 In VS .NET
Using Barcode creation for Reporting Service Control to generate, create Data Matrix image in Reporting Service applications.
www.OnBarcode.com
C H A P T ER 7
UPC-A Supplement 5 Decoder In None
Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Barcode Printer In .NET
Using Barcode generator for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
CONNECTING TO THE INTERNET
Paint UCC - 12 In None
Using Barcode printer for Microsoft Excel Control to generate, create GS1 128 image in Office Excel applications.
www.OnBarcode.com
Code 128A Scanner In C#.NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Listing 7.6
Encode Barcode In Visual C#
Using Barcode encoder for VS .NET Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
QR Code Printer In Java
Using Barcode generation for BIRT Control to generate, create QR Code ISO/IEC18004 image in Eclipse BIRT applications.
www.OnBarcode.com
QuoteService.java
ANSI/AIM Code 39 Scanner In VB.NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Encoding Barcode In Visual C#.NET
Using Barcode generation for Visual Studio .NET Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
import javax.microedition.io.*; import java.io.*; public class QuoteService { public static int[] getPrice(String symbolString, int type) { String quotePage = getQuotePage(symbolString, type); if (quotePage.length() > 0) return parseQuote(quotePage, type); else return null; } private static int[] parseQuote(String aQuotePage, int type){ String skip; String dollarsEnd; String quoteEnd; String quoteDollars = null; String quoteCents = null; int[] dollarsCents = new int[2]; if (type == 0) { skip = "$ "; dollarsEnd = "."; quoteEnd = "</b>"; } else { skip = "$"; dollarsEnd = "."; quoteEnd = "</b>"; } try { int generalPos = aQuotePage.indexOf(skip); int dollarStop = aQuotePage.indexOf(dollarsEnd, generalPos); int quoteStop = aQuotePage.indexOf(quoteEnd, dollarStop); quoteDollars = aQuotePage.substring(generalPos + (skip.length()), dollarStop); dollarsCents[0] = Integer.parseInt(quoteDollars); quoteCents = aQuotePage.substring(dollarStop + 1, quoteStop); dollarsCents[1] = Integer.parseInt(quoteCents); return dollarsCents; } catch (Exception e){ System.out.println("Error attempting to parse quote from " + "source page. Improper Symbol "); return null; } } private static String getQuotePage(String symbolString, int type) { char marker = '$'; int readLength = 20; StringBuffer quotePage = new StringBuffer(); try { String protocol = "http://";
IMPLEMENTING THE INTERNET INVESTMENT QUOTE SERVICE
String stockURL = "quotes.nasdaq.com/Quote.dll " + "page=multi&page=++&mode=stock&symbol="; String fundURL = "www.nasdaq.com/asp/quotes_mutual.asp " + "page=++&mode=fund&symbol="; InputStreamReader in; if (type == 0) { in = new InputStreamReader(Connector.openInputStream(protocol + stockURL + symbolString)); } else { in = new InputStreamReader(Connector.openInputStream(protocol + fundURL + symbolString)); } int ch; while ((ch = in.read()) > 0 ) { if (((char) ch) == marker) { char[] end = new char[readLength]; in.read(end,0,readLength); quotePage.append(new String(end)); break; } } in.close(); } catch (IOException ex) { System.out.println("Exception reading quote from HTTP Connection " + ex.getMessage()); } return quotePage.toString(); } }
SUMMARY
In this chapter, we have taken a short glance at the Generic Connection Framework and networking with the javax.microedition.io API. More details on GCF and networking are forthcoming in chapter 13. We also examine the greatly reduced but still recognizable version of java.io in J2ME. Together, we used the tools available in these two J2ME packages to connect our MIDP application to the Internet, completing our MIDP tutorial application.
Copyright © OnBarcode.com . All rights reserved.