NetBeans Java Library Walkthrough

With the NetBeans walkthrough we are going to be making a very simple Java applications demonstrating the usage of the TIBADO Pocket library.

What you need

Step 1 - Create a new Java application project using the IDE of your choice.

To create a new project with NetBeans:

- 'File'-> 'New Project'-> 'Java' Category -> 'Java Application'
- Enter your project name and location and click 'finish'

Step 2- Download the required libraries:

Tibado Pocket Libraries - tibado_libs.zip

JSON in Java Library - JSON In Java

Apache Commons Codec - Apache Commons Codec

Project Dependencies

To add the libraries to a NetBeans project:

Project Properties-> 'Libraries' Category-> 'Compile' Tab-> 'Add JAR/Folder'

To add the libraries to an Eclipse project:

Project Properties-> 'Java Build Path' Category-> 'Libraries' Tab-> 'Add JARs...' or 'Add External JARs...'

Project Files

- /src
- /libs
- /nbproject
- build.xml
- manifest.mf

Creating an Empty Pocket File

The TIBADO Pocket library can create new pocket files with zero value.

This empty pocket can be merged with a Coin to increase in value:

  File pocketFile = new File("funds.pocket");  Pocket.createEmptyPocketFile(pocketFile);

Example Pocket file:

{
      "name": "funds.pocket",
      "valueText":"AAEAAQAAAAAAAAAAAAHrUwAAAAEAAAFoHiEuBQAAA4LwUL/MG+vpeQAhrQV2XCvOXVxhLakDy+p9U3ht8KhJGA==",
      "transactionCount": 0
} 

Initialise Your Pocket

Your local pocket file must first be initialised using the Pocket library:

 Pocket pocket = new Pocket (pocketFile);

Transaction Logs

Your pocket can also have a corresponding transactions log file.

The log files are stored in JSON format.

Simply provide the log file path and the file will be automatically created for you if it does not exist.


 File pocketLogFile   = new File("funds.pocketLog");
 JsonPocketLogger pocketLogger = new JsonPocketLogger(logFile);
 pocket.setLogger(pocketLogger);

Example transaction log file:

{
 "logEntries": [
{
     "dateTime": "2016-01-08T09:51:06.604+0000", 
     "valueText":"AAEAAQFAAAAAAAAAAAHrsAAAAAEAAAABAAAAAAAAAABP7bGMcp3I/zKFsqmiaBKjHUc4kw5t8HR0eYksRcUyuw==",
     "type": "DEBIT"
},
{
     "dateTime": "2016-01-08T09:51:56.598+0000", 
     "valueText":"AAEAAQEAAAAAAAAAAAHrsgAAAAEAAAAIAAAAAAAAAABhkuUApXVEf3ZR 3J0YwDJtFtzAOFYK2kt7t/Ba5H6JnA==",
     "type": "DEBIT"
},
{
     "dateTime": "2016-01-08T10:02:07.801+0000",
     "valueText":"AAEAAQCAAAAAAAAAAAHrtQAAAAEAAAABAAAAAAAAAACxIJK1FG/A/eHnDli8KWq9BdNTcBDVx0Dr92rEmBDz1g==",
     "type": "DEBIT"
}
],
 "name": "funds.pocketLog",
 "transactionCount": 5
}

Transaction Count

Both the pocket file and pocket log file have a transaction count.

This counter is essentially the Pockets file revision number, which is incremented for both files following a transaction.

The transaction count can be used for backing up and syncing Pocket files.

TIBADO Pocket Operations

To increase a pockets value, a coin can be stored within the pocket.

To take value out of the pocket, you can get coins out of the pocket.

- The pocket API can get a coin from a pocket.

 Int amountInCents = 1;
 Coin coin = pocket.getCoin(amountInCents);
 String valueText = coin.getBase64Context();

- The pocket API can store a coin into a pocket.

 String valueText = "AAEAAQCAAAAAAAAAAAHrtQAAAAEAAAABAAAAAAAAAACxIJK1FG/A/eHnDli8KWq9BdNTcBDVx0Dr92rEmBDz1g==";
 Coin coin = new TextCoin(valueText);
 pocket.storeCoin (coin);

Running the Sample

Use your IDE to add necessary Java imports.

Finally handle the exceptions by surrounding with try-catch or add a throws signature to main.

Your sample is now complete.

 

Contact Us

If you are researching or planning a project or just need some information please get in touch and we will get right back to you.

captcha

Our Address

TIBADO Ltd.
Gratwicke House
10 East Street, Littlehampton
West Sussex, BN17 6AW

t: +44 (0)1903 721 668
e: This email address is being protected from spambots. You need JavaScript enabled to view it.

Connect With Us