Home Discussion Discuss: J2ME Canvas KeyPressed

  • how to handle Display.GAME_UP message in j2meashutosh March 20, 2011 at 6:59 PM

    i m using htmlcomponent... i overridded the keyPressed menthod and handled the msgs Dislay.GAME_LEFT,Dislay.GAME_RIGHT but due to this my scrollbar in htmlComponent is not working what to do? how to move scrollbar down on Dislay.GAME_DOWN message

  • keypressed() in j2meadelard June 1, 2012 at 3:01 PM

    i'm having a problem in using the keypressed() function.i want if i pressed a key(KEY_NUM1),an integer a increment.this integer is displayed on a label. here are my codes: import javax.microedition.midlet.*; import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; import com.sun.lwuit.*; import com.sun.lwuit.events.*; import com.sun.lwuit.layouts.BorderLayout; import com.sun.lwuit.layouts.GridLayout; import com.sun.lwuit.Container; import com.sun.lwuit.Form; import com.sun.lwuit.Label; import com.sun.lwuit.Command; import com.sun.lwuit.events.ActionListener; import com.sun.lwuit.animations.CommonTransitions; import com.sun.lwuit.animations.Transition3D; import com.sun.lwuit.util.Resources; import com.sun.lwuit.plaf.UIManager; public class TESTMidlet extends MIDlet implements ActionListener { private Form Main, Main2 ,f; int a = 0; int b = 0; // static int c = 0; // static int d = 0; // static int e = 0; // static int g = 0; // static int h = 0; // static int i = 0; // static int j = 0; // static int k = 0; // static int l = 0; // static int m = 0; // static int n = 0; // static int o = 0; public void startApp() { Display.init(this); try { Resources r = Resources.open("/a.res"); UIManager.getInstance().setThemeProps(r.getTheme(r.getThemeResourceNames()[0])); } catch (java.io.IOException ioe) { // Do something here. } f= new Form("instruction!!!!"); f.addCommand(new Command("BACK",2)); f.setCommandListener(this); f.setLayout(new BorderLayout()); Container formContainer3 = new Container(new BorderLayout()); Label instructionLabel = new Label("instuctions will be here"); formContainer3.addComponent(BorderLayout.CENTER, instructionLabel); f.addComponent(BorderLayout.CENTER, formContainer3); f.show(); //SECOND FORM Main2 = new Form("MOBSCOB VERSION 1"); Main2.addCommand(new Command("BACK",2)); Main2.setCommandListener(this); Main2.setLayout(new GridLayout(8,3)); Label home1 = new Label("Home"); Label home2 = new Label(); Label home3 = new Label("Away"); Label home4 = new Label(""); home4.setText(Integer.toString(a)); Label home5 = new Label("Q1"); Label home6 = new Label(""); home6.setText(Integer.toString(b)); Label home7 = new Label(""); home7.setText(Integer.toString(a)); Label home8 = new Label("Q2"); Label home9 = new Label(""); home9.setText(Integer.toString(b)); Label home10 = new Label(""); home10.setText(Integer.toString(a)); Label home11 = new Label("Q3"); Label home12 = new Label(""); home12.setText(Integer.toString(b)); Label home13 = new Label(""); home13.setText(Integer.toString(a)); Label home14 = new Label("Q4"); Label home15 = new Label(""); home15.setText(Integer.toString(b)); Label home16 = new Label(""); home16.setText(Integer.toString(a)); Label home17 = new Label("OT1"); Label home18 = new Label(""); home18.setText(Integer.toString(b)); Label home19 = new Label(""); home19.setText(Integer.toString(a)); Label home20 = new Label("OT2"); Label home21 = new Label(""); home21.setText(Integer.toString(b)); Label home22 = new Label(""); home22.setText(Integer.toString(a)); Label home23 = new Label("FS"); Label home24 = new Label(""); home24.setText(Integer.toString(b)); Main2.addComponent( home1); Main2.addComponent( home2); Main2.addComponent( home3); Main2.addComponent( home4); Main2.addComponent( home5); Main2.addComponent( home6); Main2.addComponent( home7); Main2.addComponent( home8); Main2.addComponent( home9); Main2.addComponent( home10); Main2.addComponent( home11); Main2.addComponent( home12); Main2.addComponent( home13); Main2.addComponent( home14); Main2.addComponent( home15); Main2.addComponent( home16); Main2.addComponent( home17); Main2.addComponent( home18); Main2.addComponent( home19); Main2.addComponent( home20); Main2.addComponent( home21); Main2.addComponent( home22); Main2.addComponent( home23); Main2.addComponent( home24); Main2.show(); //COMMANDS FOR FORM2 Command QUATER1_CMD = new Command("Q1",6); Command QUATER2_CMD = new Command("Q2",4); Command QUATER3_CMD = new Command("Q3",5); Command QUATER4_CMD = new Command("Q4"); Command OT1_CMD = new Command("OT1"); Command OT2_CMD = new Command("OT2"); Main2.addCommand(OT2_CMD); Main2.addCommand(OT1_CMD); Main2.addCommand(QUATER4_CMD); Main2.addCommand(QUATER3_CMD); Main2.addCommand(QUATER2_CMD); Main2.addCommand(QUATER1_CMD); Main2.addCommandListener(this); Main2.setTransitionOutAnimator( CommonTransitions.createSlide( CommonTransitions.SLIDE_HORIZONTAL, false, 500)); //FIRST FORM Main = new Form("MOBSCOB VERSION 1"); Main.show(); Main.addCommand(new Command("Exit", 0)); Main.setCommandListener(this); Main.setLayout(new BorderLayout()); Container formContainer = new Container(new BorderLayout()); Label welcome = new Label("Welcome to MOBSCOB version 1 "); formContainer.addComponent(BorderLayout.CENTER, welcome); Main.addComponent(BorderLayout.CENTER, formContainer); Command PLAY_CMD = new Command("BEGIN",1); Command INSTRUCTIONS_CMD = new Command("INSTRUCTIONS",3); Main.addCommand(INSTRUCTIONS_CMD); Main.addCommand(PLAY_CMD); Main.addCommandListener(this); Button button = new Button("Push me!"); Main.setTransitionOutAnimator(Transition3D.createRotation(500, true)); //exercise on output } public void pauseApp(){} public void destroyApp(boolean unconditional) {} public void actionPerformed(ActionEvent ae) { Command cmd = ae.getCommand(); switch (cmd.getId()) { //'Exit' command case 0: notifyDestroyed(); break; case 1: Main2.show(); break; case 2: Main.show(); break; case 3: f.show(); break; case 6: Main2.show(); break; } } class canvas extends Canvas implements Runnable{ public void keypressed(int keyCode){ int key = getKeyCode(keyCode); if(key == KEY_NUM1) { a=a+1; } } protected void paint() { } public void run() { } protected void paint(Graphics g) { throw new UnsupportedOperationException("Not supported yet."); } } } i need some help!!!thank you!!!

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
J2EE-Tutorials

J2ME Canvas KeyPressed
J2ME Canvas KeyPressed       This tutorial is going to show you how to handle keypressed event in J2ME using canvas class. After going through the given example, you will be able 

J2ME

J2ME Canvas Repaint
J2ME Canvas Repaint       In J2ME repaint is the method of the canvas class, and is used to repaint the entire canvas class. To define the repaint method in you midlet follow 

Swing AWT

Canvas placing problem
Canvas placing problem  how to place a canvas in swt under a toolbar 

General

Canvas
 

J2ME

J2ME Canvas Example
J2ME Canvas Example       A J2ME Game Canvas Example This example illustrates how to create...):- This is also the void type method, it is used to paint the canvas.  Other 

Mobile Applications Questions

Adding customitem in canvas in J2ME?
Adding customitem in canvas in J2ME?  In J2ME how should we add... for customitem.The key event handling is allowed in canvas not in form.So i try to use canvas instead of form 

Java Beginners

Canvas won't draw on composite (SWT)
Canvas won't draw on composite (SWT)  I can't get a canvas to draw... but the canvas won't draw the image. Please help me and bare with me because I'm...); shell.setText("Canvas in Composite"); Composite comp = new Composite(shell 

Adobe Flex

Canvas Layout Container
Canvas Layout Container       Canvas container is one of the commonly used container in flex. It defines a rectangular placeholder where its child components can be placed. Canvas 

JPA

Image Icon Using Canvas Example
Image Icon Using Canvas Example     ... location using Canvas class. In this example to create the image we are using...;extends Canvas{   private Image image1, image2 

J2EE

Simple Line Canvas Example
Simple Line Canvas Example       This is a simple example of drawing lines using canvas class in J2ME. In this example we are creating three different lines at different 

J2ME

J2ME Key Codes Example
key pressed on the canvas. In this application we are using the keyPressed... J2ME Key Codes Example      ...;keyPressed(int keyCode){      keyValue = getKeyName 

J2ME

Creating Canvas Form Example
Creating Canvas Form Example       This example shows that how to use the Canvas Class in a Form... and result will display on a Canvas circle. The Following methods are used 

Programming Tutorials

Canvas Layout Container in Flex4
Canvas Layout Container in Flex4: The Canvas layout Container is used... or controls. The Canvas layout Container is a MX component. There is no spark component... of Canvas Layout Container is <mx:Canvas>. In this example the colored area 

J2ME

Line Canvas MIDlet Example
Line Canvas MIDlet Example     ... to each other on the center of the mobile window using Canvas class. "CanvasCrossLine" class created by us extends the Canvas class to draw both 

J2ME

Image Icon Using Canvas Example
Image Icon Using Canvas Example   ... location using Canvas class. In this example to create the image we are using...;notifyDestroyed();   } } class ImageCanvas extends Canvas 

J2ME

Immutable Image using Canvas Class
Immutable Image using Canvas Class   ... to create the immutable image using canvas. In this example ImageCanvas class extends the Canvas class to create the immutable image. In the constructor 

J2ME

J2ME Timer Animation
J2ME Timer Animation      ... and implement it in the canvas class. In this Tutorial we have given you a good example, which helps you to understand using of timer class for drawing the canvas 

Mobile Applications Questions

problem in scrolling SVG drawing in canvas - MobileApplications
 

J2ME

Draw Font Using Canvas Example
Draw Font Using Canvas Example     ... Canvas class. The following line of code is used to show the different style...(){} } class FontCanvas extends Canvas{    

General

Creating Menu Using Canvas Class
Creating Menu Using Canvas Class   ... the canvas class to show the toggle message. The Toggle message will appear when... on Canvas form. The application look like as follows:   Source Code 

J2ME

Draw String Using Canvas
Draw String Using Canvas       This example is used to draw string on different location which...(){} } class TextCanvas extends Canvas{   public  

J2ME

Rectangle Canvas MIDlet Example
Rectangle Canvas MIDlet Example   ... of rectangle in J2ME. We have created CanvasRectangle class in this example that extends to the Canvas class to draw the given types of rectangle. In this figure 

J2ME

Draw Clip Area Using Canvas
Draw Clip Area Using Canvas       This Example is going to draw a clip with SOLID line...(){} } class ClipCanvas extends Canvas{   public  

J2EE

Image Item Using Canvas Example
Image Item Using Canvas Example       This example is will show you how to create the image at the top center of the screen. The following are the methods used 

General

Scrollpane in Java Swing
;  Use Canvas with ScrollPane in swing. In this section, you will study how to scroll the drawing on canvas. For this, we have used class Canvas... to draw a circle. Following code adds a scrollpane on canvas 

J2EE

J2ME Draw Triangle
J2ME Draw Triangle       As you already aware of the canvas class and it's use in J2ME application, we are using canvas class to draw the triangle on the screen. In this example 

General

Text Example in J2ME
Text Example in J2ME       In J2ME programming language canvas class is used to paint and draw... a canvas class to draw such kind of graphics in the J2ME application. J2ME Source 

Blog

Sitemap J2ME Tutorial
Button in J2ME | J2ME List Image | List in J2ME | J2ME Canvas Class | Creating Canvas Form J2ME | Creating Menu Using Canvas Class J2ME | Creating... Line in J2ME | Draw Rectangle in J2ME | Draw Font Using Canvas Class J2ME 

J2ME

J2ME Image Example
J2ME Image Example       In this application we are going to simply create an image using canvas... in the class. When the run() method is invoke, which repaint  the canvas 

J2ME

Mutable Image
image using canvas class. In this example the ImageCanvas1 class extends the Canvas...; private ImageCanvas1 canvas;   public ...;protected void startApp(){   display.setCurrent(canvas 

DMCA.com