We have this project.. FLAMES.. I was able to run my program without using JFrame..(you can see the codes below).
Just that I don't know how to use JFrame... I need to run the program using the window with the buttons and textfields.. I know how to create the window with the buttons and everything..but I don't know how could I "bind" my program to the window that I've created...
public class Main {
/**
* @param args the command line arguments
*/
static Scanner console = new Scanner(System.in);
public static StringUtil obj = new StringUtil();
public static void main(String[] args) {
playGame();
}
public static void playGame()
{
String wantRead;
int want = 0;
wantRead = JOptionPane.showInputDialog("F L A M E S\nMenu\n1-Play\n0-Exit");
want = Integer.parseInt(wantRead);
if(want == 1)
{
gameProp();
}
else
{
JOptionPane.showMessageDialog(null, "Till next time! Thanks

System.exit(0);
}
}
public static String trim(String sentence)
{
sentence = sentence.toLowerCase();
String newName = "";
char[] nameIs = sentence.toCharArray();
int i;
for(i = 0; i<sentence.length(); i++)
{
if(obj.isAlpha(nameIs[i]))
newName += nameIs[i];
}
return newName;
}
public static int compareNames(String name1, String name2)
{
char[] nameOne = name1.toCharArray();
char[] nameTwo = name2.toCharArray();
int i, j, counter = 0;
for(i = 0; i < name1.length(); i++)
{
for(j = 0; j <name2.length(); j++)
{
if(nameOne[i] == nameTwo[j])
{
counter++;
break;
}
}
}
String output = " "+counter;
JOptionPane.showMessageDialog(null, output);
return counter;
}
public static void match(int count, String name1, String name2)
{
String output = "";
if(count%6 != 0)
count = count%6;
else
count = 6;
if(count == 1)
output = name1 + " & " + name2 + "\n\nFRIENDS";
else if ( count == 2)
output = name1 + " & " + name2 + "\n\nLOVERS";
else if ( count == 3)
output = name1 + " & " + name2 + "\n\nANGRY";
else if ( count == 4)
output = name1 + " & " + name2 + "\n\nMARRIAGE";
else if ( count == 5)
output = name1 + " & " + name2 + "\n\nENEMIES";
else if ( count == 6)
output = name1 + " & " + name2 + "\n\nSWEETHEARTS";
JOptionPane.showMessageDialog(null, output);
}
public static void gameProp()
{
String first = JOptionPane.showInputDialog("Please enter full name of person #1: ");
String second = JOptionPane.showInputDialog("Please enter full name of person #2: ");
String new1st = trim(first);
String new2nd = trim(second);
String output = first+"\n"+second;
JOptionPane.showMessageDialog(null, output);
int ctrName = compareNames(new1st, new2nd);
match(ctrName, first, second);
}
}
public class StringUtil {
public boolean isAlpha(char x)
{
if((x=='a')||(x=='b')||(x=='c')||(x=='d')||(x=='e'))
return true;
else if((x=='f')||(x=='g')||(x=='h')||(x=='i')||(x=='j'))
return true;
else if((x=='k')||(x=='l')||(x=='m')||(x=='n')||(x=='o'))
return true;
else if((x=='p')||(x=='q')||(x=='r')||(x=='s')||(x=='t'))
return true;
else if((x=='u')||(x=='v')||(x=='w')||(x=='x')||(x=='y')||(x=='z'))
return true;
else
return false;
}
}
PS. I just don't have any idea..how these things could be done using the window

THANKS IN ADVANCE TO ALL WHO ARE WILLING TO HELP
