WaveLinkMenu Samples

The following sample code demonstrates the implementation and capabilities of the Class WaveLinkMenu and its associated methods.

Java Samples

/*****************************************************

/*****************************************************

* MenuSample.java - This sample describes the usage of the WaveLinkMenu, WaveLinkTone, WaveLinkIO, and WaveLinkTerminal

* objects. This source code is for demonstration purposes only and should be treated as such.

*

*/

package samplecode;

import com.wavelink.clientui.*;

import java.io.*;

import java.util.*;

public class MenuSample extends WaveLinkApplication {

// Member variables

WaveLinkIO ioIface;

WaveLinkMenu mnIface;

WaveLinkTone tnIface;

WaveLinkTerminal tmIface;

public MenuSample () {}

public void initialize() throws WaveLinkError{

// Initialize WaveLink objects for use

ioIface = new WaveLinkIO ();

mnIface = new WaveLinkMenu ();

tnIface = new WaveLinkTone ();

tmIface = new WaveLinkTerminal ();

// Store menu definition

mnIface.AddTitleLine (" Menu Sample");

mnIface.AddTitleLine ("------------------");

mnIface.AddOption ("Play Music");

mnIface.AddOption ("Show Corners");

mnIface.AddOption ("Terminal ID");

mnIface.AddOption ("WaveLink Version");

mnIface.AddOption ("Send 100 Pings");

mnIface.AddOption ("Exit Sample");

mnIface.StoreMenu ("MNSAMPLE");

for ( int lcv = 1; lcv <= 5; ++lcv )

tnIface.AddTone (lcv * 200, 200);

// Store tone definition

tnIface.StoreTone ("MNSAMPLE");

} // End of initialize

/**

* DisplayWelcomeScreen - Displays a welcome message to the user.

*/

private void DisplayWelcomeScreen () throws WaveLinkError

{

// Send the welcome message to the device ...

ioIface.RFPrint (0, 0, " Welcome to the ", WaveLinkIO.WLCLEAR | WaveLinkIO.WLREVERSE);

ioIface.RFPrint (0, 1, "WaveLink Menu Sample", WaveLinkIO.WLREVERSE);

ioIface.RFPrint (0, 2, " Application! ", WaveLinkIO.WLREVERSE);

ioIface.RFPrint (0, 7, "Hit A Key To Proceed", WaveLinkIO.WLREVERSE);

// ... and wait for a key stroke.

ioIface.GetEvent ();

} // End of DisplayWelcomeScreen

/**

* DisplayPromptScreen - Prompts the user for input. Note the use of PushScreen and RestoreScreen to minimize radio traffic.

*/

private int DisplayPromptScreen () throws WaveLinkError

{

return mnIface.DoMenu ("MNSAMPLE");

} // End of DisplayPromptScreen

/**

* EvaluateInput - Processes the user's input by performing the functionality specified by the menu option.

*/

private boolean EvaluateInput (int menuChoice)

throws WaveLinkError

{

StringBuffer tmpStr = new StringBuffer ();

switch ( menuChoice ) {

case 1: // Play Music

tnIface.PlayTone ("MNSAMPLE");

break;

case 2: // Show Corners

ioIface.RFPrint (0, 0, "(0,0)", WaveLinkIO.WLREVERSE | WaveLinkIO.WLCLEAR);

ioIface.RFPrint (0, tmIface.TerminalHeight () - 1, "(0," + Integer.toString() - 1) + ")",

WaveLinkIO.WLREVERSE);

tmpStr.append ("(").append (Integer.toString (tmIface.TerminalWidth () - 1)).append(",0)");

ioIface.RFPrint (tmIface.TerminalWidth ()

- tmpStr.length (), 0, tmpStr.toString (), WaveLinkIO.WLREVERSE);

tmpStr.setLength (0);

tmpStr.append ("(").append (Integer.toString

(tmIface.TerminalWidth () - 1)).append

(",").append (Integer.toString

(tmIface.TerminalHeight () - 1)).append(")");

ioIface.RFPrint (tmIface.TerminalWidth ()

- tmpStr.length (), tmIface.TerminalHeight ()

- 1, tmpStr.toString (), WaveLinkIO.WLREVERSE);

ioIface.GetEvent ();

break;

case 3: // Terminal ID

ioIface.RFPrint (0, 0, " Terminal ID: ", WaveLinkIO.WLREVERSE | WaveLinkIO.WLCLEAR);

ioIface.RFPrint (0, 1, tmIface.TerminalID (), WaveLinkIO.WLNORMAL);

ioIface.GetEvent ();

break;

case 4: // WaveLink Version

ioIface.RFPrint (0, 0, " WaveLink Version: ", WaveLinkIO.WLREVERSE | WaveLinkIO.WLCLEAR);

ioIface.RFPrint (0, 1, tmIface.WaveLinkVersion (), WaveLinkIO.WLNORMAL);

ioIface.GetEvent ();

break;

case 5: { // 100 Pings

ioIface.RFPrint (0, 0, "Execute 100 Pings - ", WaveLinkIO.WLREVERSE | WaveLinkIO.WLCLEAR | WaveLinkIO.WLFLUSHOUTPUT);

Date startTime = new Date ();

tmIface.Ping ("PING", 100);

Date endTime = new Date ();

ioIface.RFPrint(0,2,"TotalTime: " + String.valueOf(endTime.getTime
() - startTime.getTime ()), WaveLinkIO.WLNORMAL);

ioIface.RFPrint(0,3,"Time Per Ping: " + String.valueOf((endTime.getTime () - startTime.getTime ()) / 100), WaveLinkIO.WLNORMAL);

ioIface.RFPrint (0, 5, "(in milliseconds)", WaveLinkIO.WLNORMAL);

ioIface.GetEvent ();

break;

} //case 5:

case -1: // Ctrl + X

case -2: // Error

case 6: // Exit

return false;

} // switch (menuChoice)

return true;

} // End of EvaluateInput

public void WaveLinkMain( String arg[] ) {

try {

MenuSample localObj = new MenuSample ();

localObj.initialize();

localObj.DisplayWelcomeScreen ();

while ( true ) {

if ( localObj.EvaluateInput

(localObj.DisplayPromptScreen()) == false )

break;

} // while (true)

localObj.mnIface.DeleteMenu ("MNSAMPLE");

localObj.tnIface.DeleteToneFile ("MNSAMPLE");

}//try

catch ( WaveLinkError wlErr ) {

} // catch (WaveLinkError wlErr)

}

}

 


Was this article useful?    

The topic was:

Inaccurate

Incomplete

Not what I expected

Other

Privacy and Legal