当前位置: 首页>>代码示例>>Java>>正文


Java Button.setDraggable方法代码示例

本文整理汇总了Java中com.codename1.ui.Button.setDraggable方法的典型用法代码示例。如果您正苦于以下问题:Java Button.setDraggable方法的具体用法?Java Button.setDraggable怎么用?Java Button.setDraggable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.codename1.ui.Button的用法示例。


在下文中一共展示了Button.setDraggable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dealCard

import com.codename1.ui.Button; //导入方法依赖的package包/类
/**
 * A blocking method that creates the card deal animation and binds the drop logic when cards are dropped on the deck
 */
private void dealCard(Component deck, final Container destination, Image cardImage, Card currentCard) {
    final Button card = new Button();
    card.setUIID("Label");
    card.setIcon(cardImage);
    
    // Components are normally placed by layout managers so setX/Y/Width/Height shouldn't be invoked. However,
    // in this case we want the layout animation to deal from a specific location. Notice that we use absoluteX/Y
    // since the default X/Y are relative to their parent container.
    card.setX(deck.getAbsoluteX());
    int deckAbsY = deck.getAbsoluteY();
    if(destination.getY() > deckAbsY) {
        card.setY(deckAbsY - destination.getAbsoluteY());
    } else {
        card.setY(deckAbsY);
    }
    card.setWidth(deck.getWidth());
    card.setHeight(deck.getHeight());
    destination.addComponent(card);
    
    // we save the model data directly into the component so we don't need to keep track of it. Later when we
    // need to check the card type a user touched we can just use getClientProperty
    card.putClientProperty("card", currentCard);
    destination.getParent().animateHierarchyAndWait(400);
    card.setDraggable(true);
    
    // when the user drops a card on a drop target (currently only the deck) we remove it and animate it out
    card.addDropListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            evt.consume();
            card.getParent().removeComponent(card);
            destination.animateLayout(300);
        }
    });
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:38,代码来源:Poker.java


注:本文中的com.codename1.ui.Button.setDraggable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。