UNKNwYSHSA wrote: ↑Fri Sep 11, 2015 11:33 pm
I have a test to create an javacard applet use
JCIDE.
1 (Optional step), unzip the jar to %JCKIT_INSTALL_DIR%\SDK\Tools\JCIDE\apis\jc222, this is for the code auto-complete;
2 JCIDE main menu -> Build -> Property -> Local
JCKit configurations:
A Add sim.jar to the -classpath item in "java.exe option";
set-classpath.png
B Add stk export file dir path to -exportpath item in "
JCKit Option";
set-export-path.png
3 I found the hello world code in the ToolkitInterface.java; Copy the code as my helloStk code; Code as following:
Code: Select all
package helloStk;
import javacard.framework.*;
import sim.toolkit.*;
//
// The HelloWorld class is a simple Toolkit applet, which may be used as an
// example to show how such an applet will be installed and registered and
// how it will be triggered.
//
public class helloStk extends Applet implements ToolkitInterface,ToolkitConstants {
// data fields
private static final byte CMD_QUALIFIER = (byte)0x80;
private byte[] menuEntry = {'S','e','r','v','i','c','e','1'};
private byte[] textBuf = {'H','e','l','l','o',' ','w','o','r','l','d',' ','!'};
private ToolkitRegistry reg;
//
// Constructor of applet
//
public helloStk() {
// get a Registry object...
// ...and initialize it according to the applet characteristics
reg.initMenuEntry(menuEntry, (short)0, (short)menuEntry.length, PRO_CMD_DISPLAY_TEXT, false, (byte) 0, (short) 0);
}
//
// Install method
// *param bArray the array containing installation parameters
// *param bOffset the starting offset in bArray
// *param bLength the length in bytes of the parameter data in bArray
//
public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException {
// create and register applet
helloStk HelloWorldApplet = new helloStk();
HelloWorldApplet.register();
}
//
// Process toolkit events
// *param event the type of event to be processed
// *exception ToolkitException
//
public void processToolkit(byte event) throws ToolkitException {
// get the ProactiveHandler system instance
ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();
if (event == EVENT_MENU_SELECTION) {
// prepare a Display Text command
proHdlr.init((byte) PRO_CMD_DISPLAY_TEXT, (byte)CMD_QUALIFIER, (byte)0x02);
proHdlr.appendTLV((byte)(TAG_TEXT_STRING | TAG_SET_CR), textBuf,
(short)0, (short)textBuf.length);
proHdlr.send();
}
}
@Override
public void process(APDU apdu) throws ISOException {
// TODO Auto-generated method stub
}
}
4 Build the project, that's OK.
You can have a test of this applet on your card, it's run normal or not? Wait your message.