Implementing the DecryptScreen class

This screen displays the decrypted plaintext message.

To create the class:

  1. Assign the class to the package satsa and import the required classes.

    package satsa;
    
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.StringItem;
  2. Create the class by extending Form and implementing CommandListener.

    class DecryptScreen
      extends Form
      implements CommandListener
    {
      private final SATSAMIDlet midlet;
      private final Command commandBack =
        new Command("Back", Command.BACK, 1);
      private int index;
      private String decryptedMessage;
    
      DecryptScreen(SATSAMIDlet midlet)
      {
        super(null);
    
        this.midlet = midlet;
        createForm();
      }
    
      public void commandAction(Command c, Displayable d)
      {
        if (c==commandBack)
        {
          midlet.showEncryptedMessage(index);
        }
      }
      
      void setIndex(int index)
      {
        this.index = index;
      }
    
      void setMessage(String decryptedMessage)
      {
        this.decryptedMessage = decryptedMessage.trim();
        createForm();
      }
    
      private void createForm()
      {
        deleteAll();
        setTitle("Decrypted Message ");
        StringItem messageItem = new StringItem(null, decryptedMessage);
        append(messageItem);
        addCommand(commandBack);
        setCommandListener(this);
      }
    }