Skip to content

Instantly share code, notes, and snippets.

@shannah
Created August 26, 2015 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shannah/bd5a8398bb680538f99b to your computer and use it in GitHub Desktop.
Save shannah/bd5a8398bb680538f99b to your computer and use it in GitHub Desktop.
Classic Flickr Concentration Step 2: Create new game form
package com.codename1.demos.flickrconcentration;
import com.codename1.components.SpanLabel;
import com.codename1.ui.Button;
import com.codename1.ui.Form;
import com.codename1.ui.TextField;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import java.io.IOException;
public class ClassicFlickrConcentration {
private Resources theme;
public void init(Object context) {
try {
theme = Resources.openLayered("/theme");
UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
} catch(IOException e){
e.printStackTrace();
}
}
public void start() {
newGameForm();
}
/**
* The entry form for the app. Allows user to enter a search for flickr images.
*/
public void newGameForm() {
Form f = new Form("Classic Flickr Concentration");
f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
f.addComponent(new SpanLabel("Welcome to Classic Flickr Concentration. "
+ "A card matching game that uses flickr images."));
f.addComponent(new SpanLabel("Begin by entering a keyword to search for matching images."));
TextField searchField = new TextField();
f.addComponent(searchField);
Button searchButton = new Button("Start Game");
searchButton.addActionListener((evt) -> {
showBoard(searchField.getText());
});
f.addComponent(searchButton);
f.show();
}
public void showBoard(String search) {
Form f = new Form("Game Board");
// Show a form that will eventually contain our game board.
// Form uses BorderLayout. Center panel will have a container
// that uses GridLayout, and the south will have a button to
// go back to the new game form.
f.show();
}
public void stop() {
}
public void destroy() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment