Skip to content

Instantly share code, notes, and snippets.

@josefdlange
Created December 5, 2012 20:46
Show Gist options
  • Select an option

  • Save josefdlange/4219337 to your computer and use it in GitHub Desktop.

Select an option

Save josefdlange/4219337 to your computer and use it in GitHub Desktop.
Class to hold flag data given user input and (potentially) draw it.
import javax.swing.*;
import java.lang.*;
class FlagDrawer {
private int countryCode;
private int flagWidth;
private int flagHeight;
public static void main(String args[]) {
int inputCountry = FlagDrawer.getInputCountry();
int inputSize = FlagDrawer.getInputSize();
FlagDrawer flag = new FlagDrawer(inputCountry, inputSize);
flag.drawFlag();
}
public FlagDrawer(int country, int size) {
countryCode = country;
flagHeight = size;
flagWidth = size * 2;
}
public void drawFlag() {
// Code to draw flag using the fields in our object.
// Just showing the values for now in message dialogs.
JOptionPane.showMessageDialog(null, countryCode, "Country", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, flagHeight, "Height", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, flagWidth, "Width", JOptionPane.INFORMATION_MESSAGE);
}
public static int getInputCountry() {
String input = JOptionPane.showInputDialog("Please input a country code.");
return Integer.parseInt(input);
}
public static int getInputSize() {
String input = JOptionPane.showInputDialog("Please input the height you'd like your flag to be.");
return Integer.parseInt(input);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment