Game apps for smartphones and tablets

Research project PHBern  
HomeStart online editorAndroid TurtlegraphicsPrintJava-Online

Drawing in the graph window

The class GGPanel that is included in the class library JDroidLib, provides a graph window with problem adapted coordinates (decimals) and many elemental graphical methods. With GGPanel , easy graphs as well as complicated applications can be programd. The graph methods of the class GGPanel largely correspond to the methods of the class GPanel. Therewith, GPanel applications can be reprogramd easily to Android apps.


Example 1: Linienschar when using a for-loop

Run this example (connect smartphone first or start emulator)

Edit this example in the Online Editor

Program code:
// GGPanelEx1.java

package app.gex1;

import ch.aplu.android.*;

public class GGPanelEx1 extends GameGrid
{
  public void main()
  {
    GGPanel = getPanel(0, 40, 0, 40);
    for (int = 2; i < 39; i++)
       p.line(i, 2, 38, i);
  }
}

 

 
Explanations to the program code:
extends GameGrid The graph window is at the same time a GameGrid window
GGPanel p = getPanel(0, 40, 0, 40); Determines the coordinates of the graph window
p.line(x1, y1, x2, y2); Draws a line with the starting point (x1, y1) und endpoint (x2, y2)


Example 2: Using colors

Run this example

Edit this example in the Online Editor

Program code:
// GGPanelEx2.java

package app.gex2;

import ch.aplu.android.*;

public class GGPanelEx2 extends GameGrid
{
  public void main()
  {
    GGPanel = getPanel(-20, 20, -20, 20);
    for (int = -20; i <= 20; i++)
    {
      if (i < 0) 
        p.setPaintColor(GREEN);
      else
       p.setPaintColor(RED);
      p.line(i, -20, 0, 20); 
    }  
  }
}

 

 
Explanations to the program code:
import android.graphics.Color Instead of using "import java.awt.Color" there has to be imported "android.graphics.Color" for Android applications that use colors
p.setPaintColor(Color.GREEN) Sets the characters color to green