Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Convert Java Program to Java ME code

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Convert Java Program to Java ME code

    I'm just new to programming, and I want to try Mobile Applications. I have a code here that I want to convert to be a sample of mobile app. I don't know where and how to start. Hope you can help me. I'm using netbeans 6.7.1.

    Here's my code to be converted to a sample mobile app.

    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import java.awt.event.*;

    public class Shapes extends JFrame
    {

    public double max=2;
    public double min=1;
    public boolean test;
    public double size;
    Thread th;
    public Shapes()
    {
    super("Drawing 2d Shapes");
    size=min;
    mouseHandler mHand = new mouseHandler();
    addMouseListener(mHand);
    keyHandler kHand=new keyHandler();
    addKeyListener(kHand);
    getContentPane().setBackground(Color.green);
    setSize(400,400);


    setVisible(true);
    }
    public void paint(Graphics g)
    {
    super.paint(g);

    int xPoints[]={55,67,109,73,83,55,27,37,1,43};
    int yPoints[]={0,36,36,54,96,72,96,54,36,36};
    Graphics2D g2d=(Graphics2D)g;
    GeneralPath star= new GeneralPath();
    star.moveTo(xPoints[0]*size, yPoints[0]*size);
    for(int count=1;count<xPoints.length;count++){
    star.lineTo(xPoints[count]*size, yPoints[count]*size);
    }
    star.closePath();
    g2d.translate(200,200);
    for(int count=1; count<=20 ;count++){
    g2d.rotate(Math.PI/10.0);
    g2d.setColor(new Color(
    (int)(Math.random()*256),
    (int)(Math.random()*256),
    (int)(Math.random()*256)));
    g2d.fill(star);
    }
    }
    public class mouseHandler implements MouseListener{

    public void mouseReleased(MouseEvent e){
    th=new Thread(new RunnableObject());
    th.start();
    }
    public void mouseClicked(MouseEvent e){
    th=new Thread(new RunnableObject());
    th.start();
    }
    public void mousePressed(MouseEvent e){
    if(test){
    test=false;
    }else{
    test=true;
    }
    }
    public void mouseEntered(MouseEvent e){
    }
    public void mouseExited(MouseEvent e){
    }
    }
    public class keyHandler implements KeyListener{
    public void keyReleased(KeyEvent e){
    if(e.getKeyText(e.getKeyCode()).equalsIgnoreCase(" Up")){
    size+=.2;
    if(size>max){
    size=max;
    }
    }else if(e.getKeyText(e.getKeyCode()).equalsIgnoreCase(" Down")){
    size-=.2;
    if(size<min){
    size=min;
    }
    }
    repaint();
    }
    public void keyTyped(KeyEvent e){
    }
    public void keyPressed(KeyEvent e){
    }
    }
    public class RunnableObject implements Runnable{
    public void run(){
    while(test){
    try{
    th.sleep(100);
    }catch(InterruptedException e){
    }
    repaint();
    }
    }
    }
    public static void main(String args[]){
    Shapes s=new Shapes();
    s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    }
    Thanks in advance.


  2. #2
    Junior Member
    Join Date
    Oct 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Convert Java Program to Java ME code

    Hi rinchan11
    I think you should start it at begin.

    In a J2ME program, you must make a class extends MIDlet class, and implement methods which describ for the MIDlet cycle.
    In your program, you used mouse event that it don't have on mobile. If you want to write application for touch screen mobiles, that event will be seen as pointerPress, pointerRelease event.

    Thanks for your attentions,
    Tien

Similar Threads

  1. Java Code Help - Calling Method
    By KevinGreen in forum Object Oriented Programming
    Replies: 5
    Last Post: September 18th, 2009, 01:55 AM
  2. Replies: 5
    Last Post: September 6th, 2009, 05:39 AM