You Are Here:

Community: Developer Discussion Boards

#1 Old going back and forth between form & full screen canvas - 2008-09-23, 21:51

Join Date: Nov 2007
Posts: 42
soofika
Offline
Registered User
Experts...Please take a look at this code. This snippet is the full screen canvas which display an image. I would like to press keycode -7 and go back to the "form" where it came from. The code displays the image OK, but does not want to go back. There are no errors or crashes, just as if keypress event never happens.. Any ideas, what I am doing wrong !!!

public class iCanvas extends FullCanvas {

trackGolf tg; // My midlet, calls this full screen canvas
Image image;

iCanvas(trackGolf aThis) {

}

protected void paint(Graphics g) {
g.drawImage(image, 0, 0, 0);
}

public void createImage(Image s) {
image = s;
}
public void keypressed(int keycode) {
tg = new trackGolf();
if (keycode == -7) {
tg.switchDisplayable(null, tg.getForm());
}
}

}
Reply With Quote

#2 Old Re: going back and forth between form & full screen canvas - 2008-09-24, 00:06

Join Date: Apr 2003
Posts: 6,408
Location: USA, CA
hartti's Avatar
hartti
Offline
Nokia Expert
What are you doing in the switchDisplayable() method?

Also if the trackGolf class is extending MIDlet class, you should not try to use new with it...

Hartti
Reply With Quote

#3 Old Re: going back and forth between form & full screen canvas - 2008-09-24, 00:13

Join Date: Nov 2007
Posts: 42
soofika
Offline
Registered User
Quote:
Originally Posted by hartti View Post
What are you doing in the switchDisplayable() method?

Also if the trackGolf class is extending MIDlet class, you should not try to use new with it...

Hartti
Here is the code for switchDisplayable...

public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
// write pre-switch user code here
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}
// write post-switch user code here
}
Reply With Quote

#4 Old Re: going back and forth between form & full screen canvas - 2008-09-24, 00:18

Join Date: Apr 2003
Posts: 6,408
Location: USA, CA
hartti's Avatar
hartti
Offline
Nokia Expert
Ok, that seems correct, which brings us to my second point.

You should not try to create another MIDlet in your MIDlet. Without seeing your code it is hard to say what changes you would need to do, but basically you need to either store the reference to your MIDlet somehow for all the classes (it that is really needed) or then you could pass the reference to your MIDLet class as an parameter to all relevant classes.

Hartti
Reply With Quote

#5 Old Re: going back and forth between form & full screen canvas - 2008-09-24, 00:21

Join Date: Nov 2007
Posts: 42
soofika
Offline
Registered User
I tried following, removing the "new" from trackGolf, but still the same problem.

public class iCanvas extends FullCanvas {

Image image;
Display disp;
Displayable form;
trackGolf tg;

iCanvas(trackGolf aThis) {
disp = aThis.getDisplay();
form = aThis.getForm();
}

protected void paint(Graphics g) {
g.drawImage(image, 0, 0, 0);
}

public void createImage(Image s) {
image = s;
}
public void keypressed(int keycode) {
if (keycode == -7) {
tg.switchDisplayable(null, form);
}
}
Reply With Quote

#6 Old Re: going back and forth between form & full screen canvas - 2008-09-24, 00:26

Join Date: Apr 2003
Posts: 6,408
Location: USA, CA
hartti's Avatar
hartti
Offline
Nokia Expert
Now the variable tg is null in the keypressed method. - Please read my answer above

Also the method should be keyPressed not keypressed.
http://developers.sun.com/mobility/midp/articles/event/

Hartti
Reply With Quote

#7 Old Re: going back and forth between form & full screen canvas - 2008-09-24, 00:34

Join Date: Nov 2007
Posts: 42
soofika
Offline
Registered User
OK Problem solved.. I think I got on the track because of typo that you finally caught keyPressed instead of keypressed. That in combination with the my original midlet was never assigned a value (a null, as you pointed out)... Many thanks for your help... Following code works...

public class iCanvas extends FullCanvas {

Image image;
Display disp;
Displayable form;
trackGolf tg;

iCanvas(trackGolf aThis) {
disp = aThis.getDisplay();
form = aThis.getForm();
tg = aThis;
}

protected void paint(Graphics g) {
g.drawImage(image, 0, 0, 0);
}

public void createImage(Image s) {
image = s;
}
public void keyPressed(int keycode) {
if (keycode == -7) {
tg.switchDisplayable(null, form);
}
}
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d134434X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ