随笔-126  评论-247  文章-5  trackbacks-0

示例一效果图


示例一代码

MessageBox.alert("System Message", "Access Denied!", new Listener<MessageBoxEvent>() {
    public void handleEvent(MessageBoxEvent be) {
        Info.display(" ", "Got it.");
    }
});

示例二效果图


示例二代码

MessageBox.confirm("System Message", "Are you sure you want to do that?", new Listener<MessageBoxEvent>() {
    public void handleEvent(MessageBoxEvent be) {
        //如果点击YES按钮
        if(be.getButtonClicked().getItemId().equals(Dialog.YES)){
            Info.display(" ", "You really do that!");
        }else{
            Info.display(" ", "Thank god you didn't do that!");
        }
    }
});

示例三效果图


示例三代码

MessageBox.prompt("Prompt", "Please input something.", new Listener<MessageBoxEvent>() {
    public void handleEvent(MessageBoxEvent be) {
        //OK按钮被点击
        if(be.getButtonClicked().getItemId().equals(Dialog.OK)){
            Info.display(" ", "You input '{0}'", be.getValue());
        }
    }
});

示例四效果图


示例四代码

MessageBox.prompt("Multiline Prompt", "Please input something.", truenew Listener<MessageBoxEvent>() {
    public void handleEvent(MessageBoxEvent be) {
        //OK按钮被点击
        if(be.getButtonClicked().getItemId().equals(Dialog.OK)){
            Info.display(" ", "You input '{0}'", Format.ellipse(be.getValue(), 10));
        }
    }
});

示例五效果图


示例五代码

MessageBox messageBox = new MessageBox();
//设置图标
messageBox.setIcon(MessageBox.QUESTION);
//设置按钮样式
messageBox.setButtons(Dialog.YESNOCANCEL);
messageBox.setTitleHtml("System Message");
messageBox.setMessage("Are you sure you want to do that?");
messageBox.addCallback(new Listener<MessageBoxEvent>() {
    public void handleEvent(MessageBoxEvent be) {
        if(be.getButtonClicked().getItemId().equals(Dialog.YES)){
            Info.display(" ", "You really do that!");
        }else if(be.getButtonClicked().getItemId().equals(Dialog.NO)){
            Info.display(" ", "Thank god you didn't do that!");
        }
    }
});
messageBox.show();

示例六效果图


示例六代码

final MessageBox messageBox = MessageBox.progress("", "Loading items, please wait", "0%");
final ProgressBar progressBar = messageBox.getProgressBar();
Timer timer = new Timer() {
    private double i = 0;  //不能是int类型, 否则进度条不会滚动
    private static final int MAX = 100;
    private Random random = new Random();
    public void run() {
        progressBar.updateProgress(i / MAX, i + "%");
        i += random.nextInt(5) + 5;
        if(i > MAX + 5){
            cancel();
            messageBox.close();
            Info.display(" ", "Items were loaded!");
        }
    }
};
timer.scheduleRepeating(300);

示例七效果图


示例七代码

final MessageBox messageBox = MessageBox.wait("", "Saving data, please wait", "Saving");
Timer timer = new Timer() {
    private int i;
    private static final int MAX = 100;
    private Random random = new Random();
    public void run() {
        i += random.nextInt(5) + 5;
        if(i > MAX + 5){
            cancel();
            messageBox.close();
            Info.display(" ", "Data is successfully saved.");
        }
    }
};
timer.scheduleRepeating(300);

示例完整代码

package fan.tutorial.client.ui.win;

import java.util.Random;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Format;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.ProgressBar;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Timer;

public class MessageBoxExample extends LayoutContainer {

    @Override
    protected void onRender(Element parent, int index) {
        super.onRender(parent, index);
        
        ButtonBar buttonBar = new ButtonBar();
        buttonBar.setMinButtonWidth(100);
        
        buttonBar.add(new Button("Alert", new SelectionListener<ButtonEvent>() {
            public void componentSelected(ButtonEvent ce) {
                MessageBox.alert("System Message", "Access Denied!", new Listener<MessageBoxEvent>() {
                    public void handleEvent(MessageBoxEvent be) {
                        Info.display(" ", "Got it.");
                    }
                });
            }
        }));
        
        buttonBar.add(new Button("Confirm", new SelectionListener<ButtonEvent>() {
            public void componentSelected(ButtonEvent ce) {
                MessageBox.confirm("System Message", "Are you sure you want to do that?", new Listener<MessageBoxEvent>() {
                    public void handleEvent(MessageBoxEvent be) {
                        //如果点击YES按钮
                        if(be.getButtonClicked().getItemId().equals(Dialog.YES)){
                            Info.display(" ", "You really do that!");
                        }else{
                            Info.display(" ", "Thank god you didn't do that!");
                        }
                    }
                });
            }
        }));
        
        buttonBar.add(new Button("Prompt", new SelectionListener<ButtonEvent>() {
            public void componentSelected(ButtonEvent ce) {
                MessageBox.prompt("Prompt", "Please input something.", new Listener<MessageBoxEvent>() {
                    public void handleEvent(MessageBoxEvent be) {
                        //OK按钮被点击
                        if(be.getButtonClicked().getItemId().equals(Dialog.OK)){
                            Info.display(" ", "You input '{0}'", be.getValue());
                        }
                    }
                });
            }
        }));
        
        buttonBar.add(new Button("Multiline Prompt", new SelectionListener<ButtonEvent>() {
            public void componentSelected(ButtonEvent ce) {
                MessageBox.prompt("Multiline Prompt", "Please input something.", truenew Listener<MessageBoxEvent>() {
                    public void handleEvent(MessageBoxEvent be) {
                        //OK按钮被点击
                        if(be.getButtonClicked().getItemId().equals(Dialog.OK)){
                            Info.display(" ", "You input '{0}'", Format.ellipse(be.getValue(), 10));
                        }
                    }
                });
            }
            
        }));
        
        buttonBar.add(new Button("Yes / No / Cancel", new SelectionListener<ButtonEvent>() {
            public void componentSelected(ButtonEvent ce) {
                MessageBox messageBox = new MessageBox();
                //设置图标
                messageBox.setIcon(MessageBox.QUESTION);
                //设置按钮样式
                messageBox.setButtons(Dialog.YESNOCANCEL);
                messageBox.setTitleHtml("System Message");
                messageBox.setMessage("Are you sure you want to do that?");
                messageBox.addCallback(new Listener<MessageBoxEvent>() {
                    public void handleEvent(MessageBoxEvent be) {
                        if(be.getButtonClicked().getItemId().equals(Dialog.YES)){
                            Info.display(" ", "You really do that!");
                        }else if(be.getButtonClicked().getItemId().equals(Dialog.NO)){
                            Info.display(" ", "Thank god you didn't do that!");
                        }
                    }
                });
                messageBox.show();
            }
        }));
        
        buttonBar.add(new Button("Progress", new SelectionListener<ButtonEvent>() {
            public void componentSelected(ButtonEvent ce) {
                final MessageBox messageBox = MessageBox.progress("", "Loading items, please wait", "0%");
                final ProgressBar progressBar = messageBox.getProgressBar();
                Timer timer = new Timer() {
                    private double i = 0;  //不能是int类型, 否则进度条不会滚动
                    private static final int MAX = 100;
                    private Random random = new Random();
                    public void run() {
                        progressBar.updateProgress(i / MAX, i + "%");
                        i += random.nextInt(5) + 5;
                        if(i > MAX + 5){
                            cancel();
                            messageBox.close();
                            Info.display(" ", "Items were loaded!");
                        }
                    }
                };
                timer.scheduleRepeating(300);
            }
        }));
        
        buttonBar.add(new Button("Wait", new SelectionListener<ButtonEvent>() {
            public void componentSelected(ButtonEvent ce) {
                final MessageBox messageBox = MessageBox.wait("", "Saving data, please wait", "Saving");
                Timer timer = new Timer() {
                    private int i;
                    private static final int MAX = 100;
                    private Random random = new Random();
                    public void run() {
                        i += random.nextInt(5) + 5;
                        if(i > MAX + 5){
                            cancel();
                            messageBox.close();
                            Info.display(" ", "Data is successfully saved.");
                        }
                    }
                };
                timer.scheduleRepeating(300);
            }
        }));
        
        add(buttonBar);
    }
}







  
posted on 2014-06-08 12:30 fancydeepin 阅读(1385) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: