javauis/tsrc/fute/lcdui/Midp_Graphics_01/src/CanvasTests_01.java
changeset 78 71ad690e91f5
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 import javax.microedition.lcdui.*;
       
    19 import javax.microedition.midlet.*;
       
    20 
       
    21 /**
       
    22  * This class tests fillArc() method functionality.
       
    23  */
       
    24 
       
    25 public class CanvasTests_01 extends Canvas implements CommandListener
       
    26 {
       
    27 
       
    28     // Reference to MIDlet
       
    29     private MIDlet parent = null;
       
    30     // Commands for the canvas
       
    31     private Command cmdReset = new Command("Reset values", Command.SCREEN, 1);
       
    32     private Command cmdSize = new Command("Toggle size", Command.SCREEN, 1);
       
    33     private Command cmdExit = new Command("Exit", Command.EXIT, 1);
       
    34 
       
    35     private int startAngle = 0;
       
    36     private int arcAngle = 0;
       
    37     private int size = 30;
       
    38 
       
    39     /**
       
    40      *
       
    41      * @param parent The parent MIDlet
       
    42      */
       
    43     public CanvasTests_01(MIDlet parent)
       
    44     {
       
    45         this.parent = parent;
       
    46         addCommand(cmdReset);
       
    47         addCommand(cmdSize);
       
    48         addCommand(cmdExit);
       
    49         setCommandListener(this);
       
    50 
       
    51         setFullScreenMode(true);
       
    52         Display.getDisplay(parent).setCurrent(this);
       
    53     }
       
    54 
       
    55     protected void paint(Graphics g)
       
    56     {
       
    57         g.setGrayScale(255);
       
    58         g.fillRect(0, 0, getWidth(), getHeight());
       
    59         int height = g.getFont().getHeight();
       
    60 
       
    61         g.setGrayScale(0);
       
    62         g.drawString("fillArc function test", 0, 0, Graphics.TOP|Graphics.LEFT);
       
    63 
       
    64         g.drawString("fillArc(30,60," + size + "," + size + "," + startAngle + "," + arcAngle + ")", 0, 30, Graphics.TOP|Graphics.LEFT);
       
    65         g.fillArc(30, 60, size, size, startAngle, arcAngle);
       
    66     }
       
    67 
       
    68     public void commandAction(Command c, Displayable s)
       
    69     {
       
    70         if(c == cmdReset)
       
    71         {
       
    72             startAngle = 0;
       
    73             arcAngle = 0;
       
    74             size = 30;
       
    75         }
       
    76         else if(c == cmdSize)
       
    77         {
       
    78             size += 10;
       
    79             if(size > 300)
       
    80                 size = 10;
       
    81         }
       
    82         else if(c == cmdExit)
       
    83         {
       
    84             parent.notifyDestroyed();
       
    85         }
       
    86     }
       
    87 
       
    88     protected void keyPressed(int kyCode)
       
    89     {
       
    90         handleKeyPress(kyCode);
       
    91     }
       
    92 
       
    93     protected void keyRepeated(int kyCode)
       
    94     {
       
    95         handleKeyPress(kyCode);
       
    96     }
       
    97 
       
    98     protected void handleKeyPress(int kyCode)
       
    99     {
       
   100         if(getGameAction(kyCode) == Canvas.UP)
       
   101         {
       
   102             startAngle++;
       
   103         }
       
   104         else if(getGameAction(kyCode) == Canvas.DOWN)
       
   105         {
       
   106             startAngle--;
       
   107         }
       
   108         else if(getGameAction(kyCode) == Canvas.LEFT)
       
   109         {
       
   110             arcAngle--;
       
   111         }
       
   112         else if(getGameAction(kyCode) == Canvas.RIGHT)
       
   113         {
       
   114             arcAngle++;
       
   115         }
       
   116         else if(getGameAction(kyCode) == Canvas.GAME_A)
       
   117         {
       
   118             size += 10;
       
   119             if(size > 300)
       
   120                 size = 10;
       
   121         }
       
   122         repaint();
       
   123         serviceRepaints();
       
   124     }
       
   125 }