2010-06-04 6 views
0

J'espère que tout ira bien. En fait, je viens de faire une application dans laquelle trois choses se passentComment régler les conditions de démarrage et d'arrêt de l'animation dans votre application mobile - java me

  1. Connection fait par Http, puis le résultat est à venir dans votre région de texte d'application 2.ENVOI SMS
  2. Recevoir des SMS dans votre application textarea

Maintenant, je veux faire de l'animation. Je suis débutant mais j'aime beaucoup l'animation. Maintenant, je veux que lorsque vous cliquez sur le bouton d'envoi, une animation commence, montrant la connexion (quel que soit l'arrondi du cercle ou l'écran de démarrage) et quand le résultat est arrivé, l'animation s'arrête et votre formulaire s'affiche. En fait, ma demande se compose de trois formes, au premier formulaire, vous avez le choix de choisir de sms ou d'Internet. Si vous choisissez internet alors form2 show qui ont deux zones de texte. Dans un textArea vous tapez du texte et puis cliquez sur le bouton Envoyer sur le bouton d'envoi j'ai écrit l'écouteur dans lequel la connexion est faite via http, puis le résultat s'affiche dans le deuxième texte Zone. Maintenant, je veux que lorsque vous cliquez sur le bouton envoyer une animation démarre et exécute jusqu'à ce que le résultat ne soit pas affiché dans le second textArea montrant la connexion est en train de faire.

similairement si vous choisissez sms puis affichage Form3 ayant la même mise en page que mon form2

Comment puis-je le faire. Comment puis-je définir la condition que lorsque la commande d'envoi clique puis que la visée commence et que le résultat arrive, alors l'animation s'arrête.

De même lorsque vous envoyez un sms, une animation démarre jusqu'à ce que le message ne disparaisse pas et s'arrête lorsque le message est parti. Comment puis-je définir condtion pour cela.

De même une animation commence lorsque le message arrive dans votre application et arrête quand le résultat est indiqué dans la deuxième zone de texte

aussi me dire comment puis-je créer des animations :). J'utilise LWUIT1.3, Netbeans 6.8 Merci.

Répondre

0

Je l'ai fait. C'est très simple. En fait, pour l'animation en LWUIT, vous devez créer une classe qui a fait de l'animation. Ensuite, vous devez l'enregistrer. J'ai trouvé l'exemple d'animation forme LWUIT 1.1 pour java me developer. Donc je l'ai utilisé tel quel. Voici le code pour cette classe

[code]

class HelloForm extends Form 

{private String helloString = "Bonjour!"; // chaîne à afficher index private int = -1; // index d'accès caractères de la chaîne // private HelloMIDlet midlet; privé midlet Mobilang; private Label textLabel;

//create new instance 
//public HelloForm(HelloMIDlet m, String helloText) 
    public HelloForm(Mobilang m, String helloText) 
{ 
    super("Loading..."); 
    midlet = m; 
    helloText = helloText.trim(); 
    if(!(helloText.equals(""))) 
    { 
     helloString = helloText; 
    } 

    setLayout(new BorderLayout()); 

    //font for writing on textLabel 
    Font font = Font.createSystemFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font.SIZE_LARGE); 

    // Create textLabel and set attributes 
    textLabel = new Label(" "); 
    textLabel.setAlignment(Label.CENTER); 
    textLabel.getStyle().setBorder(Border.createBevelRaised()); 
    textLabel.getStyle().setBgColor(0xcccc99); 
    textLabel.getStyle().setFgColor(0x000000); 
    textLabel.getStyle().setFont(font); 

    addComponent(BorderLayout.NORTH, textLabel); 
} 

//reset the index to start a new cycle 
//and erase text 
public void resetIndex() 
{ 
    index = -1; 
    textLabel.setText(""); 
} 

public void updateText() 
{ 

     System.out.println("index in HelloForm updatText() is: " + index); 
     System.out.println("helloString.length() in HelloForm updatText() is: " + helloString.length()); 
    if(index == helloString.length() -2) 
      //if(txtArea2.) 
    { 
     //only one more character left 
     //display entire message 
     //textLabel.setText(helloString); 

     //and stop animation 

     // midlet.stopAnimation(); 
        // form2.show(); 
        // timer.cancel(); 

        // helloForm.removeAll(); 
    } 
    else 
    { 
     //whole string not yet written 
     //update text and restart animation on anim_label 
     //textLabel.setText(getUpdatedText()); 
        textLabel.setText("Please wait..."); 
     midlet.restartAnimation(); 
    } 
} 

//called to get the next substring of helloString 
//if the next character is a space then the substring 
//keeps expanding until a non-space character is found 
private String getUpdatedText() 
{ 
     System.out.println("index in HelloForm getUpdatText() before index ++ is: " + index); 
    index++; 

    //if index points to space character 
    //recurse until non-space character is found 
    if(helloString.charAt(index) == ' ') 
    { 
     return getUpdatedText(); 
    } 

    return helloString.substring(0, index+1); 
} 
} //HelloForm 

class HelloLabel extends Label 

{// décide quel cercle doit être établi Etat int public;

//time when previous repaint was done 
public long prevTime; 

public boolean done; 
public boolean initialized; 

//nominal interval between two successive repaints 
public final int interval = 150; 

//width of the label 
public int width; 

//height of the label 
public int height; 

//radius of first circle 
public int rad1 = 10; 

//radii of other three circles 
public int rad2, rad3, rad4; 

//top left corners of bounding rectangles - smallest to largest 
public int x1, y1, x2, y2, x3, y3, x4, y4; 

//create a new HelloLabel 
public HelloLabel() 
{ 
    super(); 
} 

//if this object is registered for animation 
//then this method will be called once for every frame 
public boolean animate() 
{ 

     System.out.println("initialized in HelloLabel animate is: " + initialized); 
    //painting parameters not set up 
    //so don't repaint 
    if(!initialized) 
    { 
     return false; 
    } 

    //get current time 
    long currentTime = System.currentTimeMillis(); 
      System.out.println("currentTime in HelloLabel animate is: " + currentTime); 

    //check if it's 'interval' milliseconds or more since last repaint 
    //also see if all circles have been drawn 
      System.out.println("prevTime in HelloLabel animate is: " + prevTime); 
       System.out.println("done in HelloLabel animate is: " + done); 
    if (!done && (currentTime - prevTime> interval)) 
    { 
     //it's more than 'interval' milliseconds 
     //so save current time for next check 
     prevTime = currentTime; 

     //increment state to draw next larger circle 
        System.out.println("state in HelloLabel animate is: " + state); 
        System.out.println(); 
     state++; 

     //check if all circles drawn 
     if (state == 5) 
     { 
      //all finished so set done flag 
      done = true; 

      //and ask for string display to be updated 
      ((HelloForm)getComponentForm()).updateText(); 
          // new HelloForm(null, msgReceived).updateText(); 
     } 

     //request repaint 
     return true; 
    } 

    //either too soon for next repaint 
    //or all circles drawn 
    //no repaint to be done 
    return false; 
} 

//reinitialize to start animation for next (non-space) character 
public void resumeAnimation() 
{ 
    state = 0; 
    done = false; 
} 

//will be called whenever 'animate' method returns true 
public void paint(Graphics g) 
{ 
    //save the present color 
    int color = g.getColor(); 

    //set color for drawing circles 
    //g.setColor(0xff8040); 
      g.setColor(0xFFFFFF); 

    //act as per state value 
    switch(state) 
    { 
     //draw smallest circle 
     case 1: 
      //translate to draw relative to label origin 
      g.translate(getX(), getY()); 

      //paint the circle 
      g.fillArc(x1, y1, 2*rad1, 2*rad1, 0, 360); 

      //restore original co-ordinate settings 
      g.translate(-getX(), -getY()); 
      break; 

     //draw next larger circle 
     case 2: 
      g.translate(getX(), getY()); 
      g.fillArc(x2, y2, 2*rad2, 2*rad2, 0, 360); 
      g.translate(-getX(), -getY()); 
      break; 

     //draw next larger cirle 
     case 3: 
      g.translate(getX(), getY()); 
      g.fillArc(x3, y3, 2*rad3, 2*rad3, 0, 360); 
      g.translate(-getX(), -getY()); 
      break; 

     //draw largest circle 
     case 4: 
      g.translate(getX(), getY()); 
      g.fillArc(x4, y4, 2*rad4, 2*rad4, 0, 360); 
      g.translate(-getX(), -getY()); 
    } 

    //restore color 
    g.setColor(color); 
} 

public void initialize() 
{ 
    //get dimensions of label 
    width = getWidth(); 
    height = getHeight(); 

      System.out.println("width in initialize is: " + width); 
      System.out.println("height in initialize is: " + height); 

    //size of largest circle to be determined by 
    //the shorter of the two dimensions 
    int side = width < height? width : height; 

      System.out.println("side in initialize is: " + side); 

    //find the center of the circle 
    int centerX = width/2; 
    int centerY = height/2; 

      System.out.println("CenterX in initialize is: " + centerX); 
      System.out.println("CenterY in initialize is: " + centerY); 

    //radius of largest circle 
    //5 less than than half the shorter side 
    rad4 = side/2 - 5; 

      System.out.println("rad4 in initialize is: " + rad4); 
      System.out.println("rad1 in initialize is: " + rad1); 

    //difference between successive radii 
    int radStep = (rad4 - rad1)/3; 
      System.out.println("radStep in initialize is: " + radStep); 

    //radii of second and third circles 
    rad2 = rad1 + radStep; 
      System.out.println("rad2 in initialize is: " + rad2); 
    rad3 = rad2 + radStep; 
      System.out.println("rad3 in initialize is: " + rad3); 

    //top left corners of the four bounding rectangles 
    x1 = centerX - rad1; 
    y1 = centerY - rad1; 

    x2 = centerX - rad2; 
    y2 = centerY - rad2; 

    x3 = centerX - rad3; 
    y3 = centerY - rad3; 

    x4 = centerX - rad4; 
    y4 = centerY - rad4; 

    initialized = true; 
} 
} //HelloLabel 

[/ code]

Ensuite, vous devez vous enregistrer dans votre midlet comme celui-ci

[code] helloForm = new HelloForm (this, "S'il vous plaît attendre ..."); helloForm.addCommand (cmdStop); helloForm.addCommandListener (this);

 //set form background image 

// helloForm.getContentPane() getStyle() setBgTransparency ((octet) 0)..; // try { // helloForm.getStyle(). SetBgImage (Image.createImage ("/ sdsym2.png")); . //} catch (java.io.IOException IOE) {//}

//font for title and menu bars 
Font font = Font.createSystemFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_LARGE); 

//set title bar background and foreground 

// helloForm.getTitleStyle() setBgTransparency (0); // helloForm.getTitleStyle(). SetFgColor (0x99cc00); // helloForm.getTitleStyle(). SetFont (police);

//set menu bar background and foreground 

//// Style s = new Style(); //// s.setBgTransparency (25); //// s.setBgColor (0x663366); //// s.setFgColor (0x99cc00); //// s.setFont (police); //// helloForm.setSoftButtonStyle (s);

//Create animLabel and set attributes 
animLabel = new HelloLabel(); 
animLabel.getStyle().setBgColor(0xd5d5d5); 
animLabel.getStyle().setBgTransparency(0); 

//add label to form 
helloForm.addComponent(BorderLayout.CENTER, animLabel); 
    helloForm.setTransitionInAnimator(CommonTransitions.createFade(1)); 

[/ code]

Maintenant, la chose est de savoir comment l'utiliser avec votre événement. Donc, cliquez sur le bouton envoyer, j'ai démarré un thread qui appelle cette classe et après un délai de 3 secondes (pour cela j'utilise timre) je commence à faire la connexion à l'url. Ainsi, lorsque vous cliquez sur Envoyer, l'animation commence et lorsque le résultat arrive, je remplace simplement ce formulaire par mon formulaire de résultat et j'arrête l'animation. Il en va de même pour la partie sms. Actaully je reçois des sms dans ma demande donc je remplace le formulaire d'animation quand le résultat vient à mon application. Merci

Questions connexes