Package com.ael

Source Code of com.ael.Page

package com.ael;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;

public class Page extends Canvas implements CommandListener
{
 
    private int _pageNumber, _maxPages, _width, _height;
    private boolean _draw;
    private QuranMobile _quranMobile;
    private Command _cmdMenu;
    private Command _cmdBookmark;


    public Page(QuranMobile _quranMobile)
    {
        super();
        this._quranMobile = _quranMobile;
        _pageNumber = 1;
        _maxPages = 3;
        setFullScreenMode(true);
        _width = getWidth();
        _height = getHeight();
        _draw = true;
        _cmdMenu = new Command("Menu",Command.SCREEN, 1);
        _cmdBookmark = new Command("Bookmark",Command.ITEM, 1);
        addCommand(_cmdMenu);
        addCommand(_cmdBookmark);
        setCommandListener(this);
    }
    boolean getDraw()
    {
        return _draw;
    }
    void setDraw(boolean _draw)
    {
        this._draw = _draw;
    }
    protected void paint(Graphics g)
    {

        if(getDraw() == false)
        {
            return;
        }
        Image image = Utilities.getImageFromPage(_pageNumber);
        Image thumbnail = Utilities.getAdjustedImage(image, _width, _height);
        g.drawImage(thumbnail, 0, 0, Graphics.TOP | Graphics.LEFT);

        setDraw(false);

    }

    protected void keyPressed(int keyCode)
    {
        if(keyCode == KEY_NUM6 || keyCode == RIGHT)
        {
            gotoNextPage();
        }

        else if(keyCode == KEY_NUM4|| keyCode == LEFT)
        {
            gotoPreviousPage();
        }

        else
        {
            _quranMobile.gotoMainMenu();
        }

    }

    public void gotoNextPage()
    {
        if(_pageNumber < _maxPages)
        {
                ++_pageNumber;
        }
        gotoPage(_pageNumber);
    }
    public void gotoPreviousPage()
    {
        if(_pageNumber > 1)
        {
            --_pageNumber;
        }
        gotoPage(_pageNumber);
    }
    public void gotoPage(int page)
    {
        _pageNumber = page;
        setFullScreenMode(true);
        setDraw(true);
        repaint();
    }
   
    public void commandAction(Command c, Displayable d)
    {
        if(c == _cmdMenu)
        {
            _quranMobile.gotoMainMenu();
        }
        else if(c == _cmdBookmark)
        {
            Utilities.setBookmark(_pageNumber);
        }
    }

}
TOP

Related Classes of com.ael.Page

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.