Here's classic CLDC1.1/MIDP2.x MIDlet that draws Elliptic Curves

given by an equation: y2 = x3 + p*x + q

Also it does search for small integer points on elliptic curve.

EllipticMIDlet employs Canvas as a base class for two of its

Displayable objects - EllipticCanvas and HelpCanvas.

Singleton design pattern is used for EllipticCanvas to retain

its state after switching to/from HelpCanvas and DataForm.

package se.matveev;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ECMIDlet extends MIDlet implements CommandListener
{
  protected EllipticCanvas ellcanvas;
  protected HelpCanvas	helpcanvas;
  protected DataForm dform;
  protected Display display;

  // UI components reused by data form/canvas
  protected static Command drawCmd = new Command("drawLine/Rect", Command.SCREEN, 1);
  protected static Command pointsCmd = new Command("Points", Command.SCREEN, 1);
  protected static Command helpCmd = new Command("Help", Command.SCREEN, 1);
  protected static Command exitCmd = new Command("Exit", Command.EXIT, 1);
  protected static Command backCmd = new Command("Back", Command.BACK, 1);

  // instance of ECMIDlet used by Data/Help forms
  protected static ECMIDlet inst = null;

  protected static int p = -31, q = 34;
  // this is used to monitor change of (p,q)
  // and re-calculate points on DataForm
  // initial value is true since points are not calculated yet
  protected static boolean newpq = true;

  public ECMIDlet()
  {
    getEllCanvas();
    inst = this;
  }

  // Singleton design pattern 
  protected EllipticCanvas getEllCanvas()
  {
	if(ellcanvas == null)
	{
	  ellcanvas = new EllipticCanvas(p, q);
	  ellcanvas.addCommand(pointsCmd);
	  ellcanvas.addCommand(drawCmd);
	  ellcanvas.addCommand(helpCmd);
	  ellcanvas.addCommand(exitCmd);
	}
	return ellcanvas;
  }

EllipticCanvas implements Runnable interface to be able to calculate

integer points on a curve in a separate thread without freezing the UI

as soon as curve's coefficients (p,q) changed by user via device keys:

public EllipticCanvas(int pcoeff, int qcoeff)
{
	super();
	p = pcoeff;
	q = qcoeff;
	width = getWidth();
	height = getHeight();
	x0 = width/2;
	y0 = height/2 + 20;

	t = new Thread(this);
	buildInfo();
}


Here's how EllipticMIDlet draws curve:

DataForm is used to display small integer points (if there are any).

To avoid overflow of integer when calculating right hand side of

an elliptic equation the check is introduced, so x coordinate is

limited by about 1291.

package se.matveev;

import javax.microedition.lcdui.*;
import java.io.*;
import java.util.Vector;

public class DataForm extends Form implements CommandListener
{
  protected DataForm dform;
  protected Vector points;
  protected StringBuffer sb;
  private StringItem si;
  private int x = EllipticCanvas.xmin;

  protected DataForm()
  {
    super("Integer Points");
    this.addCommand(ECMIDlet.backCmd);
    this.addCommand(ECMIDlet.exitCmd);
    this.setCommandListener(this);
    this.addPoints();
  }


Here's how integer points found on a curve are displayed on DataForm:


HelpCanvas is there to display help regarding which key's

to be used to change curve's coefficients p and q, as well as

switch between two Graphics drawing methods - fillRect() and drawLine().


You can download archive with Elliptic Curve MIDlet's jar and jad files from here.