Skip to main content

Animated drop down-help needed

4 replies [Last post]
ashnee
Offline
Joined: 2009-07-20
Points: 0

Can anyone help me, I have a requirement that when I press the firekey on a button, an animated dropdown effect should be created which contains 2 labels or buttons "View" and "download".
I have a code which I had modified a bit from Shai's blog post. It is nt working as i had expected. can anyone tell me what modifications do i have to do.

<br />
class FocusAnimation extends Form {<br />
   private Component futureFocus;<br />
   private Motion focusMotionX;<br />
   private Motion focusMotionY;<br />
   private Motion focusMotionWidth;<br />
   private Motion focusMotionHeight;<br />
   private boolean fireFlag=false;<br />
   final Button b1;<br />
   MidletAnim midletObj;<br />
   public FocusAnimation(final MidletAnim midletObj) {</p>
<p>       super("Focus Animation");<br />
       this.midletObj=midletObj;<br />
       System.out.println("constructor called");<br />
       b1=new Button("Button1")<br />
       {<br />
           public void keyPressed(int code)<br />
           {<br />
               if((Display.getInstance().getGameAction(code)==Canvas.LEFT)||(Display.getInstance().getGameAction(code)==Canvas.RIGHT))<br />
               {<br />
                   System.out.println("left or right key is pressed");<br />
                   refreshTheme();<br />
                  show();</p>
<p>               }<br />
               if(Display.getInstance().getGameAction(code)==Canvas.FIRE)<br />
               {<br />
                   System.out.println("fire key is pressed");<br />
                   b1.repaint();<br />
                   fireFlag=true;<br />
                   repaint();<br />
               }<br />
           }</p>
<p>           public void keyReleased(int code)<br />
           {<br />
               System.out.println("keyReleased called");<br />
           }<br />
       };<br />
       Button b2=new Button("Button2");</p>
<p>       addComponent(b1);<br />
       addComponent(b2);</p>
<p>   }</p>
<p>   public void setFocused(Component c) {<br />
       Component current = getFocused();<br />
       if(fireFlag) {<br />
           futureFocus = c;<br />
           focusMotionX = Motion.createSplineMotion(current.getAbsoluteX(), current.getAbsoluteX(), 800);<br />
           focusMotionY = Motion.createSplineMotion(current.getAbsoluteY()-20, current.getAbsoluteY(), 800);<br />
           focusMotionWidth = Motion.createSplineMotion(current.getWidth(), current.getWidth(), 400);<br />
           focusMotionHeight = Motion.createSplineMotion(current.getHeight()-20, current.getHeight(), 800);<br />
           focusMotionX.start();<br />
           focusMotionY.start();<br />
           focusMotionWidth.start();<br />
           focusMotionHeight.start();</p>
<p>           super.setFocused(null);<br />
       } else {<br />
           super.setFocused(c);<br />
       }<br />
   }</p>
<p>   public void paint(Graphics g) {<br />
       super.paint(g);<br />
       if(futureFocus != null) {<br />
           g.setColor(0xaaeeff);<br />
           g.fillRect(focusMotionX.getValue(), focusMotionY.getValue()+20,<br />
                   focusMotionWidth.getValue(), focusMotionHeight.getValue()+50,(byte)150);<br />
          g.setColor(0xffffff);<br />
           g.fillRect(focusMotionX.getValue(), focusMotionY.getValue()+20,<br />
                   focusMotionWidth.getValue(), focusMotionHeight.getValue()+50,(byte)150);</p>
<p>       }<br />
   }</p>
<p>   public boolean animate() {<br />
       boolean val = super.animate();<br />
       if(futureFocus != null && focusMotionX.isFinished()) {<br />
           super.setFocused(futureFocus);<br />
           futureFocus = null;<br />
           focusMotionX = null;<br />
           focusMotionY = null;<br />
           focusMotionWidth = null;<br />
           focusMotionHeight = null;<br />
       }<br />
       return val || futureFocus != null;<br />
   }<br />
}<br />

What I need here is, when I press the fire key on a button the painted area should drop down from the button. How can i do this?

P.S. Its a bit urgent.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07
Points: 0

Since a tree doesn't "remove" its parent node yet slides children bellow I would suggest you actually re-read my reply and the example code for the tree.

vprise
Offline
Joined: 2003-11-07
Points: 0

Use Container.replace with a slide transition to slide in the new container. Look for the LWUIT Tree in the blog for an example of how this is used.

ashnee
Offline
Joined: 2009-07-20
Points: 0

Well Thanks for your reply. But i should not replace the component, but a simple drop down from the component i.e. Button. I have completed this part using the paint() method. Now the problem is I have to add two buttons named "Vied" and "Download" into the dropdown painted Area. can anyone tell me how to do that?

I tried

[code]
public void paint(Graphics g) {
super.paint(g);

if(futureFocus != null ) {
g.setColor(0xc3d9fe);
g.fillRect(focusMotionX.getValue(), focusMotionY.getValue()+25,
focusMotionWidth.getValue(), focusMotionHeight.getValue()+20,(byte)255);
Button view=new Button("View");
UIManager.getInstance().getLookAndFeel().drawButton(g,view);
//this drawButton didnt work......

}
}
[/code]

Can anyone tell me how to include two buttons within a painted Area..

rosstheboss
Offline
Joined: 2009-02-03
Points: 0

I've always done it by calling the components paint method directly,

i.e

view.paintComponent(g);