Created
August 26, 2015 21:17
-
-
Save shannah/9f121884fc0efb1bb779 to your computer and use it in GitHub Desktop.
ClassicFlickrConcentration Step 3: Create Card Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codename1.demos.flickrconcentration; | |
import com.codename1.components.SpanLabel; | |
import com.codename1.ui.Button; | |
import com.codename1.ui.Container; | |
import com.codename1.ui.Form; | |
import com.codename1.ui.TextField; | |
import com.codename1.ui.layouts.BorderLayout; | |
import com.codename1.ui.layouts.BoxLayout; | |
import com.codename1.ui.layouts.GridLayout; | |
import com.codename1.ui.plaf.UIManager; | |
import com.codename1.ui.util.Resources; | |
import java.io.IOException; | |
public class ClassicFlickrConcentration { | |
private int rows = 4; | |
private int cols = 4; | |
private Resources theme; | |
// Create a Card component. This will be a container | |
// that keeps a reference to two buttons: front and back | |
public class Card extends Container { | |
/** | |
* | |
* @param url The url for the image we will use for the front of the card. | |
*/ | |
public Card(String url) { | |
// For now we will just implement the back of the | |
// card using a static image that we load from the | |
// resource file. | |
// Use a BorderLayout on the Card | |
// Create a button with an icon for its back. | |
// Set UIID of button to "Label" | |
// Add button to center panel of the Card container | |
} | |
/** | |
* Flips the card. If it is currently showing front, we'll | |
* change it to show back. If showing back, we'll flip it to show front. | |
*/ | |
public void flip() { | |
// We'll implement this later | |
} | |
} | |
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"); | |
f.setLayout(new BorderLayout()); | |
Container grid = new Container(); | |
grid.setLayout(new GridLayout(rows, cols)); | |
// TODO Fill the grid with Card components. | |
f.addComponent(BorderLayout.CENTER, grid); | |
Button newGameButton = new Button("New Game"); | |
newGameButton.addActionListener((evt) -> { | |
newGameForm(); | |
}); | |
f.addComponent(BorderLayout.SOUTH, newGameButton); | |
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