Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8077561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:30:27+00:00 2026-06-05T15:30:27+00:00

On a canvas there is an image and on touch at certain part of

  • 0

On a canvas there is an image and on touch at certain part of the image, I am looking to launch a new Canvas from within pointerPressed() method.

Is it possible? So far I have done the following:

   protected void pointerPressed(int x, int y){          
        if ((x>=164 && x<=173)&&(y>=24 && y<=36)){               
            disp.setCurrent(new elementDetails());
        }
    }

and the class is as follows:

//class to show detailed information of elements
class elementDetails extends Canvas{
    private Image elmDtlImg;
    public elementDetails(){
        try{
            elmDtlImg = Image.createImage("/details.jpg");
        }
        catch(IOException e){
            System.out.println("Couldn't load Detailed Info image" + e.getMessage());
        }               
    }

    public void paint(Graphics g){
        //set the drawing color to white
        g.setGrayScale(255);
        //draw a big white rectangle over the whole screen (over the previous screen)
        g.fillRect(0, 0, getWidth(), getHeight());
        g.drawImage(elmDtlImg, 0, 0, 20);
    }
}

When I run the above code nothing happens. I mean to say that the current image does not change to the new one which I am trying to show in the canvas.

My application keeps on running after the pointer pressed event. It does not crashes. It shows me the coords of other parts of the image correctly. What I am trying to achieve is that; when I click/touch at some particular points of the image it should load a new canvas in place of the old one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:30:29+00:00Added an answer on June 5, 2026 at 3:30 pm

    A canvas is made visible by calling the Display.setCurrent() method.You would to retrieve Display from your MIDlet and pass it to your canvas,then use it.I hope this snippet code help you:

    //MIDlet:

    public class MyMIDlet extends MIDlet{
        ...
        final Canvas1 c1;
        final elementDetails c2;
        ...
        public MyMIDlet(){
            c1 = new Canvas1(this);
            c2 = new elementDetails();
        }
        ...
    }
    

    //canvas1:

    public class Canvas1 extends Canvas{
        MyMIDlet myMidlet;
        Display disp;
    
    ...
    /**
    *constructor
    */
    public Canvas1(MyMIDlet myMidlet){
        this.MyMIDlet = myMidlet;
        disp = myMidlet.getDisplay();
    }
    ...
    public void paint(Graphics g){
        g.setColor(255,255,255);
        g.drawString("canvas1", 0, 0, 0);
    }
    ...
    
    protected void pointerPressed(int x, int y){          
        if ((x>=164 && x<=173)&&(y>=24 && y<=36)){               
            disp.setCurrent(myMidlet.c2);
    }
    }
    

    //class to show detailed information of elements

    class elementDetails extends Canvas{
        private Image elmDtlImg;
        public elementDetails(){
            try{
                elmDtlImg = Image.createImage("/details.jpg");
            }
            catch(IOException e){
                System.out.println("Couldn't load Detailed Info image" + e.getMessage());
            }               
        }
    public void paint(Graphics g){
        //set the drawing color to white
        g.setGrayScale(255);
        //draw a big white rectangle over the whole screen (over the previous screen)
        g.fillRect(0, 0, getWidth(), getHeight());
        g.drawImage(elmDtlImg, 0, 0, 20);
    }
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use a part of a image in my canvas. Is there
To detect when 1 image is within range of another image on the canvas
I'm drawing an image to a canvas (using the cityTexture method in http://haldean.github.com/citycanvas/city.js )
If I try to get image data from a canvas that has an image
Is there possible to create effect like Safari new tab http://images.marketingtechblog.com/uploads/2009/06/safari-new-tab.png using HTML5 canvas?
Is it possible to 'fill' a shape on an HTML5 canvas with an image
There are two layers (Image control with PNG bitmap) inside Grid (or Canvas): one
So I need to save image data drawn on a <canvas> element. And there
I want to use canvas to make an image to grayscale. There are a
How to save the content of the canvas to an image object? Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.