A question about j2me game

I want to make a programme with this function:
a small dot in the middle, if I click one button "draw",it will draw the line, if I click the "move", it will move without the line
but now , what I can do is the dot just can move , I don't know how it can draw the line...
Can anyone help me?
Ps: here is the code
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class main extends MIDlet implements CommandListener
     Display display;
     MyCanvas myCanvas;
     public main(){
          display = Display.getDisplay(this);
          myCanvas = new MyCanvas();
     public void startApp(){
          myCanvas = new MyCanvas();
          display.setCurrent(myCanvas);
          myCanvas.start();
          myCanvas.setCommandListener(this);
     public void pauseApp(){}
     public void destroyApp(boolean unconditional){}
     public void commandAction(Command c, Displayable d){
          if (c == myCanvas.exitCmd)
               destroyApp(true);
               notifyDestroyed();
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import com.nokia.mid.ui.*;
import java.util.Random;
class MyCanvas extends Canvas implements Runnable
     int gameAction;
     Command exitCmd;
     int status = release;
     int k;
     int getKeyCode;
     final static int press = 1;
     final static int release = 2;
     private CommandListener listener;
     int Width = getWidth();
     int Height = getHeight();
     public int x = getWidth()/2;
     public int y = 0;
     public int x_auto;
     public int y_auto;
     int ok;
     int r;
     Random rnd = new Random();
     Image image;
     public MyCanvas(){
          exitCmd = new Command("Exit",Command.EXIT,1);
          addCommand(exitCmd);
          ok = Math.abs(rnd.nextInt()) % 10;
          r = Math.abs(rnd.nextInt()) % 6;
     public void paint(Graphics g){
          g.setColor(0xff8080);
          g.drawRect(2,2,Width-4,Height-4);
          g.setColor(0x000000);
          g.fillArc(x,y+4,2,2,0,360);
          g.fillArc(x+x_auto,Height-4+y_auto,3,3,0,360);
     public void keyPressed(int keyCode){
          getKeyCode = keyCode;
          status=press;
     public void keyReleased(int keyCode){
          status=release;
     public void run(){
          while (true)
               try{
                    Thread.sleep(30);
                    if (getKeyCode == -1 && status == press && y > 2)
                         y--;
                    if (getKeyCode == -2 && status == press && y < Height - 4)
                         y++;
                    if (getKeyCode == -3 && status == press && x >2)
                         x--;
                    if (getKeyCode == -4 && status == press && x < Width - 4)
                         x++;
                    repaint();
               }catch(Exception ex){}
     public void start(){
          Thread runner = new Thread(this);
          runner.start();
     public void setCommandListener(CommandListener l) {
          super.setCommandListener(l);
          listener = l;

Try making the main loop change x_auto and y_auto rather than x and y. At the moment x_auto and y_auto are never initialised, so they're always 0.

Similar Messages

  • Question about deals games

    Hello Again, I have a question about deal games at PlayStation plus Does this full games that I purchase (that cost less) expire as the free games that you download at play station plus if you don't renew the PS+ subscription or I will be able to use them(forever) even If I don’t renew my play station plus subscription?

    Yes, you own them forever at the discounted price 

  • New site about J2ME game programming and optimization

    Hello!
    I just wanted to tell you about a new J2ME development site
    SupremeJ2ME found at
    http://supremej2me.bambalam.se
    It has a lot of useful guides and tips about mobile J2ME game development and optimization, a forum and information about the best J2ME tools.
    Check it out!
    cheers,
    Cranky

    J2ME Polish have licensing costs associated with it:
    http://www.j2mepolish.org/licenses.html
    As for Canvas VS GameCanvas:
    GameCanvas is MIDP 2.0 and up, so depending which devices your app supports you might want to stick with Canvas. GameCanvas eases graphics flushing, but double buffering can be implemented on Canvas like so:
    Image offscreen = isDoubleBuffered () ? null :
               Image.createImage (getWidth (), getHeight ());See http://www.developer.com/java/j2me/article.php/10934_1561591_8
    section: Avoiding Flickering

  • Strategic question about J2ME program

    I'm quite new to J2ME and am just working through trying to get a small program working between two phones - they communicate fine but I seem to be stuck more on a conceptual overview of some things I don't quite understand yet. Mainly because event driven seems to not sit well with me yet I don't think.
    I have 2 phones and I have them basically enter an insult to each other in challenge before they move into a series of rounds (small game). They do this part fine. What does happen though is the moment the insult is sent from phone A then it goes directly to the next display on phone A- and the same with phone B. The messages are sent but they both need to be able to view each other's insult / challenge before moving to the next displayable.
    I'm really just wondering in general terms how I go about creating stages where each phone has to complete something - a round in a game for example. I know it sounds kind of dumb but I'm just looking for some advice.

    http://www.jcp.org/aboutJava/communityprocess/final/jsr082/
    found this :) I think it's the answer to my problems.

  • A Question about Windows games with boot camp and system requirements

    I don't plan to play many games on my Mac, but after seeing what can be done with it, I've been entertaining the idea of picking up a Windows game or 2 to play in Boot Camp (considering picking up a XP PRO with SP2 for this).
    My question is about the listed systed system requirements and how they might apply to my Mac Pro. I have a dual 2.26.
    As a specific example, I was looking at the game Fallout 3. The box lists a 2.4ghz processor required but I've read on this forum about people running it great with less on their Mac.
    So I was wondering what I would need to consider when looking at those requirements or if games in that range do indeed run well...

    Thanks Kap, you're always helpful.
    That's exactly what I was wondering. How the requirement on the box applied to having an 8 core at a lower clock speed.
    I was looking at XP home at amazon and newegg, but haven't been able to tell if they are 64 or 32 (unless that means just install that version from the disc).
    It's nothing pressing, just something I was entertaining for now.

  • Question about j2me bluetooth lack of documentation!

    I don't know if I am searching in the wrong places. I am coding a simple (at least for now) java application that communicates through bluetooth.
    I have been using the j2me api available at http://java.sun.com/javame/reference/apis/jsr082/
    But it lacks all sort of information! The API is there... the class and methods are there but nothing is explained....
    For example, if you follow the link above to the api, then click in the DiscoveryAgent, then go to the definition of the method searchServices, this is what it tells you:
    public int searchServices(int[] attrSet, UUID[] uuidSet, RemoteDevice btDev, DiscoveryListener discListener) throws BluetoothStateException
    I can see the declaration, I even deduce what each argument is supposed to be, but..... attrSet???? what is this.... there is a complete lack of information on everything, I find myself googling for everything and finding magic numbers that sometimes make things work. Is there any online resources for bluetooth j2me programming?
    By the way... this thing about the attrSet is my latest doubt... if you know what values can be used in there please let me know:)
    But my problem is not about this particular method... is about all of the documentation.
    If anyone can point me into some place where a good specification can be found i would much appreciate it

    http://www.jcp.org/aboutJava/communityprocess/final/jsr082/
    found this :) I think it's the answer to my problems.

  • Question about MyVegas games continually spinning out of control

    Windows 7
    flashplayer version 16,0,0,235
    Google Chrome
    MyVegas games will not stop spinning most of the time. Checked updates etc. all else works fine. Anyone else having same problem? All posts greatly appreciated.

    Please ask your question on a forum for the Flash Player

  • Question about Nexuiz game? Sorry if this is wrong forum.

    If any here has played nexuiz, please tell me how to get past the bot games. Maybe I downloaded the wrong version or game but I can't seem to get to anything other bot matches. I want the regular doom or quake type of game and not the bots. I don't have many resources and my internet is very expensive. I work on a ship. The alien traps forum won't let me register to ask my questions there.
    Thanks

    I have been to the game developer forum and they are not accepting new registrations at this time. So with nowhere else to turn I came here hoping to here from the person who suggested nexuiz in the first place.
    Didn't mean to upset anyone. I will be needing your knowledge in the future. Don't want to burn bridges.
    Thanks

  • I have a question about video game preorder 10$ certificate

    i work at bestbuy  and  normally use my employee discount for video games i was wondering if i preorder lets say elder scrolls online and i use my employee discount  i know i cant get reward zone points but  am i still eligible for the  10$ certificate u get for preordering the game aswell or no? thanks

    Hello JavierSanchez,
    Thank you for visiting our forum!  I can answer your question today.
    As My Best Buy accounts cannot be used in conjunction with employee purchases, an employee purchase is not eligible to receive our Get $10 offer.
    Have a great day!
    Mike|Social Media Specialist | Best Buy® Corporate
     Private Message

  • Question about downloading games on macbook?

    I'm trying to download specifically quake and doom games. I get the message that stuffit cannot open the files. I need to install from the original installer. Don't understand as I have downloaded stuffit from the site.

    It seems to be a problem with the actual program that you're using, not something of Apple's. You should contact the developer instead, if you can. You'll get a much better answer that way.

  • A question about video game and drivers for Nvidia

    I have recently bought the parallels program and installed Win 7 on my Mac. So far so good. Then I installed a game called Champions Online (PC based). The problem is that when I load the game, it crashes with an error message saying basically that my drivers are not working properly (that's the interpretation from the support team at Champions). They suggested that I delete and reload my drivers for the Nvidia card. How do I do that? If that doesn't work, does anyone have any suggestions as to the solution to my problem?

    Parallels and other virtual environments are not meant for games and 3D intensive applications. Run Windows through Boot Camp if you want to play games.

  • Some questions about running games under Win7 on my MBP 15`

    Hello everyone,
    I bought my MBP right after the publish of Snow Leopard last September with a updated CPU and Hard drive. I didn't think of playing games on it at first, but I can't resists the COD6MW2 and installed Win7. It worked pretty well and everything went fine, except for the unbearable heat, which really made me worry. I already knew that it was normal to have a high temperature while running Windows on Macs, but I had no idea whether that heat would eventually burn down my graphic card or something, as happened on many other brands of computers. (I knew a poor kid who played COH on his Dell and got his graphic card burnt down, like the early versions of Xbox360) In fact, my hard drive broke last week and I suspected that it was due to my playing games. Can anyone help me with this?
    Thank you!

    I don't know if your problem is still actual, if it is, here is what I did:
    1. Install smcFanControl in OSX (http://www.eidac.de/)
    2. Launch it. A little icon will appear in the menu bar. Click it and choose "preferences". In the Drop-Down-Menu, select "Higher RPM" and then push the sliders all the way up to 6000. Click save.
    3. You should now hear your fans. Quit all applications and reboot into Windows (you really need to reboot, this way the fans will stay on, otherwise they turn off). Now the temperature stays a little lower. I played MW 2 for several hours and didn't have any problems.
    4. If you're done playing, reboot into OSX, launch smcFanControl and turn the fans down again.

  • A question about j2me Canvas?

    I want to draw a n-point ploygon, and fill some color in this ploygon, please help me, I cannot get a way to solve this problem?

    Hi , I hava download jmicropolygon_midp2-1.0.jar.
    and use
    private int[] xpoint = { 10, 100, 100, 50, 50, 30, 30, 10,10 };
    private int[] ypoint = { 10, 10, 70, 70, 40, 40, 100, 100,10 };
    g.setColor(255, 255, 255);
         g.fillRect(0, 0, getWidth(), getHeight());
         g.setColor(255,0,0);
         PolygonGraphics.drawPolygon(g,xpoint,ypoint);
    but it doesn't work.
    can you tell me how to use it?
    Thanks!!

  • Looking for J2ME Game Tutorial

    Hi,
    I really want to start writing J2ME Game, however, at least, I need some source codes before doing anything. Is there any moving Hello World Game? Joking.
    Would u please suggest me where can I find more about J2ME Game, especially source code. I need them in urgent. THx.

    When you download the WTK 2.0 (from this site), you get example applications. Included are 3 (I think) nifty games. I also know that the Nokia SDK also comes with an example of a J2ME game.
    I think that if you are familiar with Java you don't need much than that to start writing your own games.
    shmoove

  • HT5262 Hi, I have a question about iCloud. I have an ipod 4th generation and im getting a 5th generation. i have lots of games such as subway surfers and temple run 2. I worked and played really hard on earning stuff and have also made in app purchases. D

    Hi, I have a question about iCloud. I have an ipod 4th generation and im getting a 5th generation. i have lots of games such as subway surfers and temple run 2. I worked and played really hard on earning stuff and have also made in app purchases. Does iCloud save that kind of stuff?

    See:
    iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device
    However, not all in-app purchases will transfer to another device. For which ones ill not see:
    iTunes Store: About In-App Purchases

Maybe you are looking for