Java Code Examples for com.codename1.ui.Form#show()
The following examples show how to use
com.codename1.ui.Form#show() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToolbarRTLTest.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); Toolbar tb = new Toolbar(); hi.setToolbar(tb); tb.addCommandToLeftSideMenu(new Command("Test") {; public void actionPerformed(ActionEvent e) { System.out.println("Action clicked"); } }); hi.add(new Label("Hi World")); hi.show(); }
Example 2
Source File: AutocompleteSample2788.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Popup test", BorderLayout.absolute()); AutoCompleteTextField autocomplete = new AutoCompleteTextField("1", "2", "3", "11", "22", "33"); autocomplete.setMinimumLength(1); Button tapMe = new Button("Tap me leaving the popup opened"); tapMe.addActionListener(l -> { hi.replace(autocomplete, new Label("other content"), null); hi.revalidate(); }); hi.add(BorderLayout.CENTER, autocomplete); hi.add(BorderLayout.NORTH, tapMe); hi.show(); }
Example 3
Source File: TestComponent.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void getComponentAt_int_int_label() { log("Testing getComponentAt(x, y) with label"); int w = Display.getInstance().getDisplayWidth(); int h = Display.getInstance().getDisplayHeight(); Form f = new Form("My Form", new BorderLayout()); Label l = new Label("Hello"); f.add(BorderLayout.CENTER, l); f.show(); TestUtils.waitForFormTitle("My Form", 2000); Component middleComponent = f.getComponentAt(w/2, h/2); assertEqual(l, middleComponent, "Found wrong component"); }
Example 4
Source File: SignIn.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
private void showFacebookUser(String token){ ConnectionRequest req = new ConnectionRequest(); req.setPost(false); req.setUrl("https://graph.facebook.com/v2.3/me"); req.addArgumentNoEncoding("access_token", token); InfiniteProgress ip = new InfiniteProgress(); Dialog d = ip.showInifiniteBlocking(); NetworkManager.getInstance().addToQueueAndWait(req); byte[] data = req.getResponseData(); JSONParser parser = new JSONParser(); Map map = null; try { map = parser.parseJSON(new InputStreamReader(new ByteArrayInputStream(data), "UTF-8")); } catch (IOException ex) { ex.printStackTrace(); } String name = (String) map.get("name"); d.dispose(); Form userForm = new UserForm(name, (EncodedImage) theme.getImage("user.png"), "https://graph.facebook.com/v2.3/me/picture?access_token=" + token); userForm.show(); }
Example 5
Source File: InfiniteContainerSafeAreaTest.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if (current != null) { current.show(); return; } Form hi = new Form("InfiniteContainer", new BorderLayout()); Style s = UIManager.getInstance().getComponentStyle("MultiLine1"); FontImage p = FontImage.createMaterial(FontImage.MATERIAL_PORTRAIT, s); EncodedImage placeholder = EncodedImage.createFromImage(p.scaled(p.getWidth() * 3, p.getHeight() * 3), false); InfiniteContainer ic = new InfiniteContainer() { @Override public Component[] fetchComponents(int index, int amount) { java.util.List<Map<String, Object>> data = fetchPropertyData("Leeds"); MultiButton[] cmps = new MultiButton[data.size()]; for (int iter = 0; iter < cmps.length; iter++) { Map<String, Object> currentListing = data.get(iter); if (currentListing == null) { return null; } String thumb_url = (String) currentListing.get("thumb_url"); String guid = (String) currentListing.get("guid"); String summary = (String) currentListing.get("summary"); cmps[iter] = new MultiButton(summary); //cmps[iter].setIcon(URLImage.createToStorage(placeholder, guid, thumb_url)); } return cmps; } }; ic.setUIID("Blue"); ic.setSafeArea(true); ic.addComponent(new Label("This is a test")); hi.add(BorderLayout.CENTER, ic); hi.show(); }
Example 6
Source File: AsyncMediaSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World"); new Recorder().initUI(hi); hi.show(); }
Example 7
Source File: TestCSSRegression3077.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); TextField textField = new TextField(); Button button = new Button("Button", "Button"); Button linkButton = new Button("Link Button", "LinkButton"); hi.add(textField); hi.add(button); hi.add(linkButton); hi.show(); }
Example 8
Source File: ProfileAvatarViewSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); Profile profile = new Profile(); profile.set(Profile.name, "Steve"); profile.set(Profile.icon, "https://www.codenameone.com/img/steve.jpg"); ProfileAvatarView avatar = new ProfileAvatarView(profile, 30f); hi.add("Avatar with Name and Icon"); hi.add(FlowLayout.encloseCenter(avatar)); profile = new Profile(); profile.set(Profile.name, "Steve"); avatar = new ProfileAvatarView(profile, 30f); hi.add("Avatar with only Name"); hi.add(FlowLayout.encloseCenter(avatar)); profile = new Profile(); avatar = new ProfileAvatarView(profile, 30f); hi.add("Avatar with no name or icon"); hi.add(FlowLayout.encloseCenter(avatar)); profile = new Profile(); profile.set(Profile.name, "Steve"); profile.set(Profile.icon, "https://www.codenameone.com/img/steve.jpg"); hi.add("Avatar with view controller"); hi.add(FlowLayout.encloseCenter(new ProfileViewController(null, profile).getView())); hi.show(); }
Example 9
Source File: WebSocketsSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
void showChat() { Form f= new Form("Chat"); f.setLayout(new BorderLayout()); Container south = new Container(); final TextField tf = new TextField(); Button send = new Button(new Command("Send") { @Override public void actionPerformed(ActionEvent evt) { if (sock.getReadyState() == WebSocketState.OPEN) { sock.send(tf.getText()); tf.setText(""); } else { Dialog.show("", "The socket is not open", "OK", null); showLogin(); } } }); chatContainer = new Container(); chatContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); south.addComponent(tf); south.addComponent(send); f.addComponent(BorderLayout.SOUTH, south); f.addComponent(BorderLayout.CENTER, chatContainer); f.setFormBottomPaddingEditingMode(true); f.show(); }
Example 10
Source File: SwitchTest2644.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); Switch sw = new Switch(); hi.add(new Label("Hi World")); hi.add(sw); hi.show(); }
Example 11
Source File: FillShapeTest.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { Form f = new Form("Test Fill Shape"); f.setLayout(BorderLayout.center()); ButtonGroup bg = new ButtonGroup(); drawStringBtn = RadioButton.createToggle("String", bg); drawPathBtn = RadioButton.createToggle("Path", bg); f.add(BorderLayout.CENTER, new DrawingCanvas()); f.add(BorderLayout.NORTH, GridLayout.encloseIn(drawStringBtn, drawPathBtn)); f.show(); }
Example 12
Source File: PropertyCross.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
/** * Shows the favorites screen */ void showFavs() { final Form favsForm = new Form("Favourites"); addBackToHome(favsForm); favsForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); if(favoritesList.size() == 0) { favsForm.addComponent(new SpanLabel("You have not added any properties to your favourites")); } else { // this is really trivial we just take the favorites and show them as a set of buttons for(Map<String, Object> c : favoritesList) { MultiButton mb = new MultiButton(); final Map<String, Object> currentListing = c; String thumb_url = (String)currentListing.get("thumb_url"); String guid = (String)currentListing.get("guid"); String price_formatted = (String)currentListing.get("price_formatted"); String summary = (String)currentListing.get("summary"); mb.setIcon(URLImage.createToStorage(placeholder, guid, thumb_url, URLImage.RESIZE_SCALE_TO_FILL)); mb.setTextLine1(price_formatted); mb.setTextLine2(summary); mb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { showPropertyDetails(favsForm, currentListing); } }); favsForm.addComponent(mb); } } favsForm.show(); }
Example 13
Source File: LoadingTextAnimationSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); Button b = new Button("Show Details"); b.addActionListener(e->{ showForm(); }); hi.add(b); hi.show(); }
Example 14
Source File: TestNativePlayerMode2972.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form f = new Form("NativePlayerMode Test"); f.setLayout(BoxLayout.y()); Button playButton = new Button("Play Video"); playButton.addActionListener(e->{ String videoPath; if (isSimulator()) { videoPath = "http://www.codenameone.com/files/hello-codenameone.mp4"; } else { videoPath = "https://www.codenameone.com/files/hello-codenameone.mp4"; } try { Media video = MediaManager.createMedia(videoPath, true); video.setNativePlayerMode(true); // this works nicely on iOS 12, I didn't test other iOS versions yet video.prepare(); video.setFullScreen(true); video.play(); } catch (Exception ex) { Log.e(ex); } }); f.add(playButton); f.show(); }
Example 15
Source File: NativeControlsSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void webviewLoginTest() { Form f= new Form("Test Webview Login", new BorderLayout()); String html = "<!doctype html>" + "<html><body><table><tr><td>Username:</td><td><input type='text' autocomplete='username'/></td></tr><tr><td>Password</td>" + "<td><input type='password' autocomplete='current-password'/></td></tr></body></html>"; BrowserComponent c = new BrowserComponent(); c.setPage(html, "https://weblite.ca/"); f.add(BorderLayout.CENTER, c); f.show(); }
Example 16
Source File: ProgressAnimationsSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); hi.add(new Label("Hi World")); hi.add(new CommonProgressAnimations.CircleProgress()); hi.add(new CommonProgressAnimations.LoadingTextAnimation()); Label labelThatIsLoading = new Label("Loading..."); hi.add(labelThatIsLoading); CommonProgressAnimations.CircleProgress.markComponentLoading(labelThatIsLoading); UITimer.timer(2000, false, hi, ()-> { labelThatIsLoading.setText("Found 248 results"); CommonProgressAnimations.CircleProgress.markComponentReady(labelThatIsLoading); }); Label anotherLabelThatIsLoading = new Label("Loading..."); hi.add(anotherLabelThatIsLoading); CommonProgressAnimations.CircleProgress.markComponentLoading(anotherLabelThatIsLoading); UITimer.timer(4000, false, hi, ()-> { labelThatIsLoading.setText("Found 512 results"); CommonProgressAnimations.CircleProgress.markComponentReady(anotherLabelThatIsLoading, CommonTransitions.createFade(300)); }); TextArea someText = new TextArea("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."); someText.setGrowByContent(true); someText.setRows(4); someText.setColumns(40); someText.setPreferredW(Display.getInstance().getDisplayWidth()); hi.add(someText); CommonProgressAnimations.LoadingTextAnimation.markComponentLoading(someText).cols(40).rows(5); UITimer.timer(6000, false, hi, ()-> { CommonProgressAnimations.CircleProgress.markComponentReady(someText, CommonTransitions.createFade(300)); }); hi.show(); }
Example 17
Source File: SampleMain.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); hi.add(new Label("Hi World")); hi.show(); }
Example 18
Source File: DraggableTabsSample.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public void start() { if (current != null) { current.show(); return; } Form hi = new Form("Tabs", new BorderLayout()); Tabs t = new Tabs(); t.addTab("T1", new Label("Tab 1")); t.addTab("T2", new Label("Tab 2")); t.addTab("T3", new Label("Tab 3")); t.addTab("T4", new Label("Tab 4")); Container tabsC = t.getTabsContainer(); tabsC.setDropTarget(true); for (Component c : tabsC) { c.setDraggable(true); c.addDropListener(e -> { e.consume(); Component dragged = c; int x = e.getX(); int y = e.getY(); int i = tabsC.getComponentIndex(dragged); if (i > -1) { Component dest = tabsC.getComponentAt(x, y); if (dest != dragged) { Component source = t.getTabComponentAt(i); int destIndex = tabsC.getComponentIndex(dest); if (destIndex > -1 && destIndex != i) { String title = t.getTabTitle(i); t.removeTabAt(i); if (destIndex > i) { t.insertTab(title, null, source, destIndex - 1); } else { t.insertTab(title, null, source, destIndex); } } } tabsC.animateLayout(400); } }); } hi.add(CENTER, t); hi.show(); }
Example 19
Source File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
private void showForm(Form f, Command sourceCommand, Component sourceComponent) { Form currentForm = Display.getInstance().getCurrent(); if(currentForm != null && currentForm instanceof Dialog) { ((Dialog)Display.getInstance().getCurrent()).dispose(); currentForm = Display.getInstance().getCurrent(); } Vector formNavigationStack = baseFormNavigationStack; if(sourceCommand != null && currentForm != null && currentForm.getBackCommand() == sourceCommand) { if(currentForm != null) { exitForm(currentForm); } if(formNavigationStack != null && formNavigationStack.size() > 0) { String name = f.getName(); if(name != null && name.equals(homeForm)) { if(formNavigationStack.size() > 0) { setFormState(f, (Hashtable)formNavigationStack.elementAt(formNavigationStack.size() - 1)); } formNavigationStack.clear(); } else { initBackForm(f); } } onBackNavigation(); beforeShow(f, sourceCommand); f.showBack(); postShowImpl(f); } else { if(currentForm != null) { exitForm(currentForm); } if(formNavigationStack != null && !(f instanceof Dialog) && !f.getName().equals(homeForm)) { if(currentForm != null) { String nextForm = (String)f.getClientProperty("%next_form%"); // we are in the sidemenu view we should really be using the parent form SideMenuBar b = (SideMenuBar)currentForm.getClientProperty("cn1$sideMenuParent"); if(b != null) { currentForm = b.getParentForm(); } // don't add back commands to transitional forms if(nextForm == null) { String commandAction = currentForm.getName(); if(allowBackTo(commandAction) && f.getBackCommand() == null) { Command backCommand; if(isSameBackDestination(currentForm, f)) { backCommand = currentForm.getBackCommand(); } else { backCommand = createCommandImpl(getBackCommandText(currentForm.getTitle()), null, BACK_COMMAND_ID, commandAction, true, ""); backCommand.putClientProperty(COMMAND_ARGUMENTS, ""); backCommand.putClientProperty(COMMAND_ACTION, commandAction); } if(backCommand != null) { setBackCommand(f, backCommand); } // trigger listener creation if this is the only command in the form getFormListenerInstance(f, null); formNavigationStack.addElement(getFormState(currentForm)); } } } } if(f instanceof Dialog) { beforeShow(f, sourceCommand); if(sourceComponent != null) { // we are cheating with the post show here since we are using a modal // dialog to prevent the "double clicking button" problem by using // a modal dialog sourceComponent.setEnabled(false); postShowImpl(f); f.show(); sourceComponent.setEnabled(true); exitForm(f); } else { ((Dialog)f).showModeless(); postShowImpl(f); } } else { beforeShow(f, sourceCommand); f.show(); postShowImpl(f); } } }
Example 20
Source File: InterFormContainerSample.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public void start() { Button sharedButton = new Button("Shared Button"); InterFormContainer cnt = new InterFormContainer(sharedButton); InterFormContainer cnt2 = new InterFormContainer(sharedButton); Toolbar.setGlobalToolbar(true); Form hi = new Form("Transitions", new BorderLayout()); Container c = new Container(BoxLayout.y()); hi.add(BorderLayout.CENTER, c); hi.add(BorderLayout.SOUTH, cnt); Style bg = hi.getContentPane().getUnselectedStyle(); bg.setBgTransparency(255); bg.setBgColor(0xff0000); Button showTransition = new Button("Show"); Picker pick = new Picker(); pick.setStrings("Slide", "SlideFade", "Cover", "Uncover", "Fade", "Flip"); pick.setSelectedString("Slide"); TextField duration = new TextField("10000", "Duration", 6, TextArea.NUMERIC); CheckBox horizontal = CheckBox.createToggle("Horizontal"); pick.addActionListener((e) -> { String s = pick.getSelectedString().toLowerCase(); horizontal.setEnabled(s.equals("slide") || s.indexOf("cover") > -1); }); horizontal.setSelected(true); c.add(showTransition). add(pick). add(duration). add(horizontal); Form dest = new Form("Destination", new BorderLayout()); sharedButton.addActionListener(e -> { if (sharedButton.getComponentForm() == hi) { dest.show(); } else { hi.showBack(); } }); dest.add(BorderLayout.SOUTH, cnt2); bg = dest.getContentPane().getUnselectedStyle(); bg.setBgTransparency(255); bg.setBgColor(0xff); dest.setBackCommand( dest.getToolbar().addCommandToLeftBar("Back", null, (e) -> hi.showBack())); showTransition.addActionListener((e) -> { int h = CommonTransitions.SLIDE_HORIZONTAL; if (!horizontal.isSelected()) { h = CommonTransitions.SLIDE_VERTICAL; } switch (pick.getSelectedString()) { case "Slide": hi.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000))); break; case "SlideFade": hi.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000))); break; case "Cover": hi.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000))); break; case "Uncover": hi.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000))); break; case "Fade": hi.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000))); break; case "Flip": hi.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000))); dest.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000))); break; } dest.show(); }); hi.show(); }