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

  • SEARCH
  • Home
  • 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 7712621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:40:41+00:00 2026-06-01T01:40:41+00:00

I am trying to create a midlet with which I can draw anything using

  • 0

I am trying to create a midlet with which I can draw anything using my cursor keys. I have used drawLine method. But I want to create a line then change direction keeping the previous line but the line keeps rotating.

Basically I should be able to draw anything in any direction.

This is my code:

public class Pacer extends MIDlet{
public void startApp() {
Displayable d = new PacerCanvas();

d.addCommand(new Command("Exit", Command.EXIT, 0));
d.setCommandListener(new CommandListener() {
  public void commandAction(Command c, Displayable s) {
    notifyDestroyed();
  }
} );

Display.getDisplay(this).setCurrent(d);
 }

public void pauseApp() { }

public void destroyApp(boolean unconditional) { }
}
/**
*
* @author Rumman
*/
import javax.microedition.lcdui.*;

public class PacerCanvas extends Canvas {

private String name;
private int w,h,x1,y1,x2,y2;

public PacerCanvas(){
w = getWidth();
h = getHeight();
x1 =  w/2 ;
y1 = h/2 ;
x2 = x1 ;
y2 = y1 ;
}

protected void keyPressed(int key){
    name = getKeyName(key);
    if(name.equals("Right") || name.equals("6")){
    x2++;
    }
    else if(name.equals("Left") || name.equals("4")){
    x2--;
    }
    else if(name.equals("Up") || name.equals("2")){
    y2--;
    }
    else if(name.equals("Down") || name.equals("8")){
    y2++;
    }
    else if(name.equals("1")){
        x2--;
        y2++;
    }
    else if(name.equals("3")){
        x2++;
        y2++;
    }
    else if(name.equals("7")){

    }
    else if(name.equals("9")){
    }
    repaint();  
}

public void paint(Graphics g) {

g.setColor(0xffffff);
g.fillRect(0, 0, w, h);

g.setColor(0x000000);
g.drawLine(x1, y1, x2, y2);
}
}
  • 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-01T01:40:42+00:00Added an answer on June 1, 2026 at 1:40 am
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    
    /**
    *
    * @author Rumman
    */
    import javax.microedition.lcdui.*;
    
    public class PacerCanvas extends Canvas {
    
    private String name;
    private int w,h,x1,y1,x2,y2;
    private Image image;
    private Graphics ig;
    public PacerCanvas(){
    w = getWidth();
    h = getHeight();
    x1 =  w/2 ;
    y1 = h/2 ;
    x2 = x1 ;
    y2 = y1 ;
    image = Image.createImage(w,h);
    
    ig = image.getGraphics();
    
    ig.setColor(255, 255, 255);
    ig.fillRect(0, 0, w, h);
    
    }
    protected void keyRepeated(int key){
    keyPressed(key);
    keyPressed(key);// I used this method multiple times as it makes it faster 
    keyPressed(key);
    keyPressed(key);
    keyPressed(key);
    keyPressed(key);
    keyPressed(key);
    keyPressed(key);
    }
    protected void keyPressed(int key){
        name = getKeyName(key);
        if(name.equals("Right") || name.equals("6")){
        x2++;
        }
        else if(name.equals("Left") || name.equals("4")){
        x2--;
        }
        else if(name.equals("Up") || name.equals("2")){
        y2--;
        }
        else if(name.equals("Down") || name.equals("8")){
        y2++;
        }
        else if(name.equals("1")){
            x2--;
            y2--;
        }
        else if(name.equals("3")){
            x2++;
            y2--;
        }
        else if(name.equals("7")){
            x2--;
            y2++;
        }
        else if(name.equals("9")){
            x2++;
            y2++;
        }
        repaint();  
    }
    
    public void paint(Graphics g) {
    
    
    ig.setColor(0x000000);
    ig.drawLine(x1, y1, x2, y2);
    g.drawImage(image, 0, 0, Graphics.TOP|Graphics.LEFT);
    x1=x2;
    y1=y2;
    
    
    }
    
    public void draw(Image i) {
    Graphics ig = i.getGraphics();
    Pacer p = new Pacer();
    // p.Display.getDisplay(this).setCurrent(i);
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I'm trying create a RCP Application with Eclipse, but I can't get past the
I am trying create a data.frame from which to create a graph. I have
I am trying create alert dailog using glade,but its not working .am i doing
I am trying create system in which I can login from php and then
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5
Trying to create a user account in a test. But getting a Object reference
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different

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.