|
||
|
||
Examples
|
||
|
||
|
In the JTC-API is in the directory /samples a collection of Java source code samples.
For the call of the samples you should have a JRE in the version 1.2 or more highly.
Install the JTC-API in your JRE (see installation).
For executing the examples you call the Java interpreter java.exe with the
appropriate file name of the example without extension.
Here are the necessary steps:
|
||
|
||
|
How the name already says, it goes with these section API around the manipulation from Java arrays.
It serves for the supplement of still missing functions in the class java.util.Arrays.
Mixing cards, as they occur in a computer game, enables the method elementsMix.
import softhema.system.toolkits.ToolkitArray;
...
String[] as = new String[5];
as[0] = "red";
as[1] = "yellow";
as[2] = "blue";
as[3] = "orange";
as[4] = "white";
//mix it
ToolkitArray.elementsMix( as );
for( int i = 0 ; i < 5 ; i++ )
System.out.println( as[ i ] );
|
||
|
||
|
The AWT is not dead yet.
For the programming of applet it recommends to still use the AWT instead of Swing.
This is justified with the fact that there are still many Webbrowser with a JRE in the version 1.1 in the Internet.
In this version Swing was not yet fixed constituent of the Java core class library.
The class ToolkitAWT contains useful supplements for the AWT.
The example presented here enables to modify the text of a selected item of a Choice control.
void choiceSelect_itemStateChanged(ItemEvent e)
{
txtSelect.setText( choiceSelect.getSelectedItem() );
}
void txtSelect_textValueChanged(TextEvent e)
{
ToolkitAWT.ChoiceItemReplace( choiceSelect,
choiceSelect.getSelectedIndex(),
txtSelect.getText(),
true
);
}
Applet example for the method ChoiceItemReplace in the class ToolkitAWT Applet example for the methods ListItemsSelectedMoveUp and ListItemsSelectedMoveDown in the class ToolkitAWT
|
||
|
||
The class ToolkitCollection contains extensions for the Java Collection Framework.
Also the predecessor "java.util.Vector" of the Java Collection Framework is supported.
import softhema.system.toolkits.ToolkitCollection;
...
try
{
Vector vec = new Vector();
vec.addElement( "red" );
vec.addElement( "yellow" );
vec.addElement( "blue" );
vec.addElement( "orange" );
vec.addElement( "white" );
//mix it
ToolkitCollection.listReverseOrder( vec );
//print new order
ToolkitIO.printf("\nnew order:\n%s\n%s\n%s\n%s\n%s\n", vec);
}
catch( IOException e )
{
e.printStackTrace();
}
|
||
|
||
|
The method listFiles of the class java.io.File lists
only the files and sub directories of the next level.
In order to determine all files of a directory,
a recursive algorithm is necessary.
The method listFilesRecursive from the section API ToolkitFile returns
to you an array of file objects, which contains all subordinated files.
Vector v = new Vector();
ToolkitIO.printf("%s", "Input a directory:");
ToolkitIO.scanf("%ls", v);
String sDirectory = (String) v.elementAt(0);
File dir = new File( sDirectory );
File[] aFilesAndSubDirs = ToolkitFile.listFilesRecursive( dir, true );
File[] aFilesOnly = ToolkitFile.listFilesRecursive( dir, false );
int countFiles = aFilesOnly.length;
int countDirs = aFilesAndSubDirs.length - countFiles;
ToolkitIO.printf("In the directory \"%s\" are %i files and %i subdirectories.\n",
sDirectory, new Integer(countFiles), new Integer(countDirs) );
|
||
|
||
|
In this Toolkit are functions for input or output operations.
Inputs are gotten by System.in. Outputs are written after System.out.
Conversion from Fahrenheit to Celsius:
import softhema.system.toolkits.ToolkitIO;
...
try
{
Vector v = new Vector();
ToolkitIO.printf("\n%s", "Input the temperature in Fahrenheit:");
ToolkitIO.scanf("%f", v );
float fahrenheit = ( (Number) v.elementAt(0) ).floatValue();
float celsius = (5.0f / 9.0f) * (fahrenheit - 32);
v.addElement( new Float( celsius ) );
ToolkitIO.printf("%.2f Fahrenheit is %.2f Celsius", v);
}
catch( IOException e )
{
e.printStackTrace();
}
|
||
|
||
|
ToolkitString supplies additional functions to you to the analysis
and to the manipulation of a string.
The method sprintf writes its output not on the display, but into a string.
A string-comparison with Wildcards can be executed over the method strLike.
ToolkitIO.printf("\nInput a password:");
String pwd = ToolkitIO.readStringLine();
if( ToolkitString.strLike( pwd, "*s*s*" ) )
{
//The password must contains two s-characters.
ToolkitIO.printf("\nThe password %s is correct.", pwd);
}
else
{
ToolkitIO.printf("\nThe password %s is not correct.", pwd);
}
|
||
|
||
|
With Swing efficient user interfaces can be created.
Nevertheless some functionalities are still connected in Swing with an enormous expenditure.
The Toolkit API contains functions for extension of the control members contained in Swing.
Additionally some auxiliary functions are contained.
void jBtnMoveUp_actionPerformed(ActionEvent e)
{
ToolkitSwing.ListItemsSelectedMoveUp( jList );
}
void jBtnMoveDown_actionPerformed(ActionEvent e)
{
ToolkitSwing.ListItemsSelectedMoveDown( jList );
}
|
||
|