本文整理汇总了Java中com.codename1.ui.Button.addActionListener方法的典型用法代码示例。如果您正苦于以下问题:Java Button.addActionListener方法的具体用法?Java Button.addActionListener怎么用?Java Button.addActionListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.codename1.ui.Button
的用法示例。
在下文中一共展示了Button.addActionListener方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createImageButton
import com.codename1.ui.Button; //导入方法依赖的package包/类
Button createImageButton(final long imageId, final Container grid, final int offset) {
final Button btn = new Button(URLImage.createToFileSystem(placeholder, FileSystemStorage.getInstance().getAppHomePath() + "/Thumb_" + imageId, THUMB_URL_PREFIX + imageId, URLImage.RESIZE_SCALE_TO_FILL));
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
imageList.setSelectedIndex(offset);
final Container viewerParent = new Container(new LayeredLayout());
ImageViewer viewer = new ImageViewer(imageList.getItemAt(offset));
viewerParent.addComponent(viewer);
Container parent = new Container(new BorderLayout());
viewerParent.addComponent(parent);
parent.addComponent(BorderLayout.SOUTH, createToolbar(imageId));
likeCount = new Label("");
parent.addComponent(BorderLayout.NORTH, likeCount);
viewer.setImageList(imageList);
grid.getParent().replace(grid, viewerParent, CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 300));
Display.getInstance().getCurrent().setBackCommand(createBackCommand(viewerParent, grid));
}
});
return btn;
}
示例2: createToolbar
import com.codename1.ui.Button; //导入方法依赖的package包/类
Container createToolbar(long imageId) {
Container toolbar = new Container(new GridLayout(1, 4));
toolbar.setUIID("Toolbar");
// notice that the characters in the name of the buttons map to icons in the icon font!
Button likeButton = new Button("d");
Button flagButton = new Button("c");
Button detailsButton = new Button("a");
final ShareButton shareButton = new ShareButton();
shareButton.setIcon(null);
shareButton.setText("b");
bindShareButtonSelectionListener(shareButton);
likeButton.setUIID("ToolbarLabel");
flagButton.setUIID("ToolbarLabel");
detailsButton.setUIID("ToolbarLabel");
shareButton.setUIID("ToolbarLabel");
toolbar.addComponent(likeButton);
toolbar.addComponent(shareButton);
toolbar.addComponent(detailsButton);
toolbar.addComponent(flagButton);
likeButton.addActionListener(createLikeAction(imageId));
detailsButton.addActionListener(createDetailsButtonActionListener(imageId));
return toolbar;
}
示例3: wrap
import com.codename1.ui.Button; //导入方法依赖的package包/类
/**
* Wraps the given text field with a UI that will allow us to clear it
* @param tf the text field
* @param iconSize size in millimeters for the clear icon, -1 for default size
* @return a Container that should be added to the UI instead of the actual text field
*/
public static ClearableTextField wrap(final TextArea tf, float iconSize) {
ClearableTextField cf = new ClearableTextField();
Button b = new Button("", tf.getUIID());
if(iconSize > 0) {
FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR, iconSize);
} else {
FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR);
}
removeCmpBackground(tf);
removeCmpBackground(b);
cf.setUIID(tf.getUIID());
cf.add(BorderLayout.CENTER, tf);
cf.add(BorderLayout.EAST, b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
tf.stopEditing();
tf.setText("");
tf.startEditingAsync();
}
});
return cf;
}
示例4: buildMenuCommand
import com.codename1.ui.Button; //导入方法依赖的package包/类
private Command buildMenuCommand(String title, String icon, ActionListener listener)
{
Button l = new Button(title);
//Image iconImage = StateMachine.getResourceFile().getImage(icon);
//iconImage.lock();
//l.setIcon(iconImage);
l.setGap(20);
//l.setUIID("NavigationButton");
l.addActionListener(listener);
Command c = new Command(title);
c.putClientProperty("SideComponent", l);
return c;
}
示例5: showLoginForm
import com.codename1.ui.Button; //导入方法依赖的package包/类
private void showLoginForm() {
Form loginForm = new Form();
loginForm.getTitleArea().setUIID("Container");
loginForm.setLayout(new BorderLayout());
loginForm.setUIID("MainForm");
Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
cnt.setUIID("Padding");
Button loginWithGoogle = new Button("Signin with Google");
loginWithGoogle.setUIID("LoginButtonGoogle");
Button loginWithFacebook = new Button("Signin with Facebook");
loginWithFacebook.setUIID("LoginButtonFacebook");
Style iconFontStyle = UIManager.getInstance().getComponentStyle("IconFont");
loginWithFacebook.setIcon(FontImage.create(" \ue96c ", iconFontStyle));
loginWithGoogle.setIcon(FontImage.create(" \ue976 ", iconFontStyle));
cnt.addComponent(loginWithGoogle);
cnt.addComponent(loginWithFacebook);
loginWithGoogle.addActionListener((e) -> {
Dialog.show("Test", "Test", "OK", null);
tokenPrefix = "google";
Login gc = GoogleConnect.getInstance();
gc.setScope("profile email https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me");
gc.setClientId("1013232201263-lf4aib14r7g6mln58v1e36ibhktd79db.apps.googleusercontent.com");
gc.setRedirectURI("https://www.codenameone.com/oauth2callback");
gc.setClientSecret("uvu03IXOhx9sO8iPcmDfuX3R");
doLogin(gc, new GoogleData(), false);
});
loginWithFacebook.addActionListener((e) -> {
tokenPrefix = "facebook";
Login fb = FacebookConnect.getInstance();
fb.setClientId("739727009469185");
fb.setRedirectURI("http://www.codenameone.com/");
fb.setClientSecret("4c4a7df81a8e9ab29ac4e38e6b9e4eb1");
doLogin(fb, new FacebookData(), false);
});
loginForm.addComponent(BorderLayout.SOUTH, cnt);
loginForm.show();
}
示例6: showLoginForm
import com.codename1.ui.Button; //导入方法依赖的package包/类
private void showLoginForm() {
Form login = new Form("Login");
BorderLayout bl = new BorderLayout();
bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
ComponentGroup loginDetails = new ComponentGroup();
TextField displayName = new TextField();
displayName.setHint("Display Name");
loginDetails.addComponent(displayName);
final TextField email = new TextField();
email.setHint("E-Mail");
loginDetails.addComponent(email);
Button send = new Button("Send Verification");
loginDetails.addComponent(send);
send.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
onSendAction(email);
}
});
login.setLayout(bl);
login.addComponent(BorderLayout.CENTER, loginDetails);
login.show();
}
示例7: createDemo
import com.codename1.ui.Button; //导入方法依赖的package包/类
public Container createDemo() {
final Container contactsDemo = new Container(new BorderLayout());
final Image defaultIcon = getResources().getImage("stock_new-meeting.png");
ContactsModel m = new ContactsModel(Display.getInstance().getAllContacts(true));
m.setPlaceHolderImage(defaultIcon);
final List contactsList = new List(m);
GridLayout grd = new GridLayout(3, 3);
grd.setAutoFit(true);
final ContainerList grid = new ContainerList(m);
grid.setLayout(grd);
contactsDemo.addComponent(BorderLayout.CENTER, contactsList);
contactsList.setRenderer(createListRenderer());
grid.setRenderer(createGridRenderer());
final Button asGrid = new Button("As Grid");
asGrid.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
if(contactsList.getParent() != null) {
contactsDemo.replace(contactsList, grid, CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 300));
asGrid.setText("As List");
} else {
contactsDemo.replace(grid, contactsList, CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 300));
asGrid.setText("As Grid");
}
}
});
ComponentGroup gp = new ComponentGroup();
gp.addComponent(asGrid);
contactsDemo.addComponent(BorderLayout.SOUTH, gp);
return contactsDemo;
}
示例8: createDemo
import com.codename1.ui.Button; //导入方法依赖的package包/类
public Container createDemo() {
Container message = new Container(new BoxLayout(BoxLayout.Y_AXIS));
ComponentGroup gp = new ComponentGroup();
message.addComponent(gp);
final TextField to = new TextField("");
to.setHint("TO:");
gp.addComponent(to);
final TextField subject = new TextField("Codename One Is Cool");
subject.setHint("Subject");
gp.addComponent(subject);
final TextField body = new TextField("Try it out at http://www.codenameone.com/");
body.setSingleLineTextArea(false);
body.setRows(4);
body.setHint("Message Body");
gp.addComponent(body);
ComponentGroup buttonGroup = new ComponentGroup();
Button btn = new Button("Send");
buttonGroup.addComponent(btn);
message.addComponent(buttonGroup);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Message msg = new Message(body.getText());
Display.getInstance().sendMessage(new String[] {to.getText()}, subject.getText(), msg);
}
});
return message;
}
示例9: createDemo
import com.codename1.ui.Button; //导入方法依赖的package包/类
public Container createDemo() {
Container cnt = new Container(new BorderLayout());
final WebBrowser wb = new WebBrowser();
if(wb.getInternal() instanceof BrowserComponent) {
Button btn = new Button("Add");
final TextArea content = new TextArea();
Container north = new Container(new BorderLayout());
north.addComponent(BorderLayout.CENTER, content);
north.addComponent(BorderLayout.EAST, btn);
cnt.addComponent(BorderLayout.NORTH, north);
content.setHint("Add to web document");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
((BrowserComponent)wb.getInternal()).execute("fnc('" + content.getText() + "');");
}
});
((BrowserComponent)wb.getInternal()).setBrowserNavigationCallback(new BrowserNavigationCallback() {
public boolean shouldNavigate(String url) {
if(url.startsWith("http://sayhello")) {
// warning!!! This is not on the EDT and this method MUST return immediately!
Display.getInstance().callSerially(new Runnable() {
public void run() {
((BrowserComponent)wb.getInternal()).execute("fnc('this was written by Java code!')");
}
});
return false;
}
return true;
}
});
}
cnt.addComponent(BorderLayout.CENTER, wb);
wb.setURL("jar:///Page.html");
return cnt;
}
示例10: Login
import com.codename1.ui.Button; //导入方法依赖的package包/类
public Login(Form f) {
super("Login Form");
this.main = f;
setLayout(new LayeredLayout());
Button login = new Button(FBDemo.getTheme().getImage("SignInFacebook.png_veryHigh.png"));
login.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
signIn(main);
}
});
login.setUIID("CenterLabel");
addComponent(login);
}
示例11: show
import com.codename1.ui.Button; //导入方法依赖的package包/类
public static void show(String title, String text, final Command cmd)
{
int popupWidth = Display.getInstance().getCurrent().getWidth() - StateMachine.getPixelFromMM(10, true);
if(popupWidth > StateMachine.getPixelFromMM(40,true))
popupWidth = StateMachine.getPixelFromMM(40,true);
final Dialog dia = new Dialog();
dia.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
dia.getDialogStyle().setBgTransparency(0);
Command backCommand = new Command(null){
@Override
public void actionPerformed(ActionEvent ev) {
dia.dispose();
}
};
dia.setBackCommand(backCommand);
SpanLabel lblTitle = new SpanLabel(title);
lblTitle.setUIID("ViewOptionsRowFirst");
lblTitle.setTextUIID("ViewOptionsRowFirstText");
lblTitle.setPreferredW(popupWidth);
dia.addComponent(lblTitle);
SpanLabel lblText = new SpanLabel(text);
lblText.setUIID("ViewOptionsRow");
lblText.setTextUIID("ViewOptionsRowText");
lblText.setPreferredW(popupWidth);
dia.addComponent(lblText);
Container ctn = new Container(new LayeredLayout());
Button closebg = new Button();
closebg.setUIID("ViewOptionsRowLast");
closebg.getStyle().setBgTransparency(0);
closebg.setPreferredW(popupWidth);
ctn.addComponent(closebg);
Container ctnButtons = new Container(new BoxLayout(BoxLayout.Y_AXIS));
ctnButtons.getStyle().setMargin(StateMachine.getPixelFromMM(2, false), StateMachine.getPixelFromMM(2, false), StateMachine.getPixelFromMM(2, true), StateMachine.getPixelFromMM(2, true));
ctn.addComponent(ctnButtons);
Button close = new Button(StateMachine._translate("button_ok", "[default] Ok"));
if (cmd != null && cmd.getCommandName() != null)
close.setText(cmd.getCommandName());
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (cmd != null)
cmd.actionPerformed(evt);
dia.dispose();
}
});
close.setUIID("ViewOptionsRowClose");
close.setVerticalAlignment(Label.CENTER);
ctnButtons.addComponent(close);
dia.addComponent(ctn);
dia.showPacked(BorderLayout.CENTER, true);
}
示例12: createEntry
import com.codename1.ui.Button; //导入方法依赖的package包/类
/**
* This method builds a UI Entry dynamically from a data Map object.
*/
private static Component createEntry(Map data, final int index) {
final Container cnt = new Container(new BorderLayout());
cnt.setUIID("MultiButton");
Button icon = new Button();
icon.setUIID("Label");
//take the time and use it as the identifier of the image
String time = (String) data.get("date_taken");
String link = (String) ((Map) data.get("media")).get("m");
EncodedImage im = (EncodedImage) res.getImage("flickr.png");
final URLImage image = URLImage.createToStorage(im, time, link, null);
icon.setIcon(image);
icon.setName("ImageButton" + index);
icon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Dialog d = new Dialog();
//d.setDialogUIID("Container");
d.setLayout(new BorderLayout());
Label l = new Label(image);
l.setUIID("ImagePop");
d.add(BorderLayout.CENTER, l);
d.setDisposeWhenPointerOutOfBounds(true);
d.setTransitionInAnimator(new BubbleTransition(300, "ImageButton" + index));
d.setTransitionOutAnimator(new BubbleTransition(300, "ImageButton" + index));
d.show();
}
});
cnt.addComponent(BorderLayout.WEST, icon);
Container center = new Container(new BorderLayout());
Label des = new Label((String) data.get("title"));
des.setUIID("MultiLine1");
center.addComponent(BorderLayout.NORTH, des);
Label author = new Label((String) data.get("author"));
author.setUIID("MultiLine2");
center.addComponent(BorderLayout.SOUTH, author);
cnt.addComponent(BorderLayout.CENTER, center);
return cnt;
}
示例13: bindListener
import com.codename1.ui.Button; //导入方法依赖的package包/类
@Override
public void bindListener(Button cmp, ActionListener<ActionEvent> l) {
cmp.addActionListener(l);
}
示例14: SignatureComponent
import com.codename1.ui.Button; //导入方法依赖的package包/类
/**
* Creates a new signature component.
*/
public SignatureComponent() {
setLayout(new BorderLayout());
xFont = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
lead = new Button() {
@Override
protected void paintBackground(Graphics g) {
super.paintBackground(g);
g.setColor(0x666666);
Style s = getStyle();
g.drawRect(
getX()+s.getPaddingLeftNoRTL(),
getY()+s.getPaddingTop(),
getWidth()-s.getPaddingRightNoRTL()-s.getPaddingLeftNoRTL(),
getHeight()-s.getPaddingBottom() - s.getPaddingTop()
);
g.setFont(xFont);
g.drawString("X", getX() + getStyle().getPaddingLeftNoRTL() + Display.getInstance().convertToPixels(3, true), getY() + getHeight() / 2);
}
};
lead.setText(localize("SignatureComponent.LeadText","Press to sign"));
lead.setUIID("SignatureButton");
lead.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
final Dialog dialog = new Dialog(localize("SignatureComponent.DialogTitle", "Sign Here"));
final SignatureDialogBody sigBody = new SignatureDialogBody() {
@Override
protected void onCancel() {
super.onCancel();
dialog.dispose();
}
};
sigBody.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent sigDoneEvent) {
dialog.dispose();
setSignatureImage(sigBody.getValue());
fireActionEvent();
}
});
dialog.setLayout(new BorderLayout());
dialog.addComponent(BorderLayout.CENTER, sigBody);
dialog.setScrollable(false);
dialog.setFocusable(false);
dialog.show();
}
});
addComponent(BorderLayout.CENTER, lead);
}