techPowerUp! Forums

Go Back   techPowerUp! Forums > Software > Programming & Webmastering

Reply
 
Thread Tools
Old Oct 22, 2009, 04:05 AM   #126
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

Quote:
Originally Posted by FordGT90Concept View Post
letterArray has only one char (containing "2").
strange because letterArray is populated using

int len2 = textfieldString.length()

and textfieldString is a String that = tfInput.getText() and at that point it isnt populated at all.
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 04:41 AM   #127
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

fixed that little issue. i had to move the letterArray and secretWordArray creation to the actionPerformed section. i also moved the if statement that compares the two arrays to the actionPerformed method.

now i just need to get it to actually write the input letter to the mask which is hiding the secret word. for that i have...

Code:
for(int i = 0; i < inputString.length(); i++)
			{
				if(secretWordArray[i] == letterArray[j])
				{
					temp += textfieldString;
				}	
				else
				{
					temp += inputMask;
				}
			}
but when i hit the OK button nothing happens. maybe my code isnt actually changing the value??

Code:
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class TimeBomb extends JFrame implements ActionListener
{
	public String inputString = "";
	public String textfieldString = "";
	public String inputMask = "*";//mask
	public String temp = "";
	int i,j;
	
	JTextField tfInput = new JTextField(1);
	JLabel lblMessage = new JLabel("Guess A Letter: ");
	JLabel maskedWord = new JLabel();
	JLabel guessedLetter = new JLabel();
	JButton btnOK = new JButton("OK");
	JLabel timer = new JLabel("*-----");
	
	public TimeBomb() //constructor for GUI
	{
		super("Time Bomb Game");
	
		inputString = JOptionPane.showInputDialog("Enter Secret Word: ");//user enters secret word
		
		for(int i = 0; i < inputString.length(); i++)//gets the length of the secret word
		{
			temp +=  inputMask;//creates a mask of the secret word of the appropriate length
			maskedWord = new JLabel(temp);
		}
		

		Font f1 = new Font("Dialog", Font.PLAIN, 24);//set main font
		Font f2 = new Font("Dialog", Font.PLAIN, 32);//set larger font
		lblMessage.setFont(f1);
		tfInput.setFont(f1);
		guessedLetter.setFont(f1);
		btnOK.setFont(f1);
		timer.setFont(f2);
		maskedWord.setFont(f1);
		
		getContentPane().setLayout(new BorderLayout(1,1));//simple gui layout

		JPanel northPanel = new JPanel();
		northPanel.add(lblMessage);
		northPanel.add(tfInput);
		northPanel.add(btnOK);
		btnOK.addActionListener(this);
		getContentPane().add(northPanel, "North");
	
		JPanel centerPanel = new JPanel();
		centerPanel.add(maskedWord);
		centerPanel.add(guessedLetter);
		getContentPane().add(centerPanel, "Center");
		
		JPanel southPanel = new JPanel();
		southPanel.add(timer);//count down to explosion
		getContentPane().add(southPanel, "South");
		
		setSize(350, 200);//should be large enough on all platforms
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
	}
	

	
	public void actionPerformed(ActionEvent e)
	{
		if ("OK".equals(e.getActionCommand()))//OK button gets entered letter and puts it in the south panel
		{
			textfieldString = tfInput.getText();//string created from JTextField
			int len2 = textfieldString.length();//gets the length of the letter
			char[] letterArray = new char[len2];//creates array using len2
			for(int j = 0; j < len2; j++)
			{
				letterArray[j] = textfieldString.charAt(j);//populates array using textfieldString
			}
			
			int len = inputString.length();//gets the length of the secret word and stores it in len
			char[] secretWordArray = new char[len];//create array using len
			for(int i = 0; i < len; i++)
			{
				secretWordArray[i] = inputString.charAt(i);//populate array using inputString
			}
			
			for(int i = 0; i < inputString.length(); i++)
			{
				if(secretWordArray[i] == letterArray[j])
				{
					temp += textfieldString;
				}	
				else
				{
					temp += inputMask;
				}
			}
		}

	}//end of actionPerformed
	
	public static void main(String[] args) 
	{
		new TimeBomb();
	}
}//end TimeBomb class
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 05:31 AM   #128
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

You need to do something with "temp" once it exits the for loop (probably assign to both your equivilent of _Reveal and also to the text display).
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Old Oct 22, 2009, 06:52 AM   #129
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

Quote:
Originally Posted by FordGT90Concept View Post
You need to do something with "temp" once it exits the for loop (probably assign to both your equivilent of _Reveal and also to the text display).
the problem tho is you cant do a .setText or a .getText with strings, only jlabels, jtextfields, etc.

edit! ok so the command is maskedWord.setText(temp);

however it is a little glitchy lol! it creates a whole new masked array with only the letter guessed revealed. so my code isnt perfect yet obviously.
if i guess a letter wrong it creates a whole new ****** and if i guess a letter right it creates s***** and then when i guess another letter right it creates a new se**** so it jus t keeps making them and my field has ******s******e****** just running on.

so i need to have it override the original maskedWord and keep the letters correctly guessed.

Last edited by Easy Rhino; Oct 22, 2009 at 07:46 AM.
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 08:08 AM   #130
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

You have to update your equvilent of _Reveal so every time the code is executed, it is comparing the _Secret to the current _Reveal.

If you are dealing with strings:
Get: (something) = myvar;
Set: myvar = (something);

set variable = get variable
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Old Oct 22, 2009, 05:10 PM   #131
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

uhm, ok let me work on this a bit.

Last edited by Easy Rhino; Oct 22, 2009 at 05:19 PM.
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 05:44 PM   #132
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

well i cant seem to troubleshoot this issue. here is my actionPerformed()

you can see the arrays are populated here and then compared using a for statement. temp is actually equal to the masked string which happens in the constructor. so then i want textFieldString, which is the letter entered in the JTextField, to += temp. but it only puts out the guessed letter and keeps the initial temp mask.

Code:
	public void actionPerformed(ActionEvent e)
	{
		if ("OK".equals(e.getActionCommand()))//OK button gets entered letter and puts it in the south panel
		{
			textfieldString = tfInput.getText();//string created from JTextField
			int len2 = textfieldString.length();//gets the length of the letter
			char[] letterArray = new char[len2];//creates array using len2
			for(int j = 0; j < len2; j++)
			{
				letterArray[j] = textfieldString.charAt(j);//populates array using textfieldString
			}
			
			int len = inputString.length();//gets the length of the secret word and stores it in len
			char[] secretWordArray = new char[len];//create array using len
			for(int i = 0; i < len; i++)
			{
				secretWordArray[i] = inputString.charAt(i);//populate array using inputString
			}
			
			
			for(int i = 0; i < inputString.length(); i++)
			{
				if(secretWordArray[i] == letterArray[j])
				{
					temp += textfieldString;
					
				}
				else
				{
					temp += inputMask;
					timer.setText(boom.getText());
				}
				
			}
			maskedWord.setText(temp);
			
		}

	}//end of actionPerformed
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 07:53 PM   #133
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

You could use String.getChar() instead of copying it manually.

e.g.
Code:
textfieldString.getChars(0, textfieldString.length() - 1, letterArray, 0);

Once you have your temp populated, you'll want to do "new JTextField(temp)" to update that JTextField or, if possible, .setText("temp"). "temp" should be defined as a String.
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }

Last edited by FordGT90Concept; Oct 22, 2009 at 07:59 PM.
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Old Oct 22, 2009, 08:26 PM   #134
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

i did a little trouble shooting by adding

System.out.println(temp) to my if statement. like so...

Code:
for(int i = 0; i < inputString.length(); i++)
			{
				if(secretWordArray[i] == letterArray[j])
				{
					System.out.println(temp);
					temp += textfieldString;
					System.out.println(temp);
				}
				else
				{
					temp += inputMask;
					System.out.println(temp);
				}
			}
			maskedWord.setText(temp);
if the secret word is secret then the console prints out that temp is equal too...

****** <--- this is temp before textfieldString is += to it
******s <--- this is temp after textfieldString is += to it
******s* <--- and the next 5 lines are what happens in the else statement temp += inputMask
******s**
******s***
******s****
******s*****

im not sure why it runs both the if and else part of the code. isnt it either or??? (if the letter does match a letter in the secret word it runs both, if it doesnt match it only runs else) and this explains that with temp += textfieldString it is only adding the entered letter onto the mask, NOT replacing the * with the letter.

so ive screwed something up somewhere.

Last edited by Easy Rhino; Oct 22, 2009 at 08:32 PM.
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 08:28 PM   #135
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

temp needs to be cleared (temp = "") before it is used (the for loop).
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Old Oct 22, 2009, 08:43 PM   #136
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

Quote:
Originally Posted by FordGT90Concept View Post
temp needs to be cleared (temp = "") before it is used (the for loop).
hrm, i think i am getting there. except if my if else statement when the letter is correct is does both if and else!! and when it is incorrect is only does else(like it should here)
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 08:53 PM   #137
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

It can never do if and else with the same evaluation. It has to be reevaluated to send it on a different code path.
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Old Oct 22, 2009, 09:01 PM   #138
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

Quote:
Originally Posted by FordGT90Concept View Post
It can never do if and else with the same evaluation. It has to be reevaluated to send it on a different code path.
i dont want it to do if and else, but it is. that is the strange thing.
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 09:05 PM   #139
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

It is an impossibility for it to do both. The syntax is correct.
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Old Oct 22, 2009, 09:14 PM   #140
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

Quote:
Originally Posted by FordGT90Concept View Post
It is an impossibility for it to do both. The syntax is correct.
weird glitch. anyway, i cant seem to replace the correct letter with the correct *. += just addes the letter to the existing mask, it doesnt replace the correct * with the letter.
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 09:21 PM   #141
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

In a String, you can't replace just one letter. That's why you append it. You are creating a new string one charater at a time.

Edit: Did you put that temp = ""; in there yet?
Code:
			temp = "";
			for(int i = 0; i < inputString.length(); i++)
			{
				if(secretWordArray[i] == letterArray[j])
				{
					temp += textfieldString;
					
				}
				else
				{
					temp += inputMask;
					timer.setText(boom.getText());
				}
				
			}
			maskedWord.setText(temp);
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Old Oct 22, 2009, 09:28 PM   #142
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

Quote:
Originally Posted by FordGT90Concept View Post
In a String, you can't replace just one letter. That's why you append it. You are creating a new string one charater at a time.

Edit: Did you put that temp = ""; in there yet?
Code:
			temp = "";
			for(int i = 0; i < inputString.length(); i++)
			{
				if(secretWordArray[i] == letterArray[j])
				{
					temp += textfieldString;
					
				}
				else
				{
					temp += inputMask;
					timer.setText(boom.getText());
				}
				
			}
			maskedWord.setText(temp);
yes i put temp = ""; in there and it simply wipes out the value of temp but that doesnt really solve my issue. my issue is that when i choose a letter if it is correct it replaces the *.

i want this to happen. secret word is secret
it creates a mask ******
i guess s
the output on the gui is now s*****
i guess e
the output on the gui is now se**e*
i guess t
the output on the gui is now se**et
and so on.

so with my current code it totally replaces ****** with s
and then when i enter e it reads ee
and when i enter t it reads t

so it isnt
1) replacing * with the correct letter
2) storing that value in memory

NOTE: my algorithm is going to blow my professor away lol.
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 09:55 PM   #143
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

Code:
secretWordArray[i] == letterArray[j]
You have i and j there. they should both be i or j (most likely i).
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Old Oct 22, 2009, 10:13 PM   #144
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

Quote:
Originally Posted by FordGT90Concept View Post
Code:
secretWordArray[i] == letterArray[j]
You have i and j there. they should both be i or j (most likely i).
they have to be different or the program poops out a massive error listing

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
at TimeBomb.actionPerformed(TimeBomb.java:107)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:253)
at java.awt.Component.processMouseEvent(Component.jav a:6108)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3276)
at java.awt.Component.processEvent(Component.java:587 3)
at java.awt.Container.processEvent(Container.java:210 5)
at java.awt.Component.dispatchEventImpl(Component.jav a:4469)
at java.awt.Container.dispatchEventImpl(Container.jav a:2163)
at java.awt.Component.dispatchEvent(Component.java:42 95)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4461)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4125)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4055)
at java.awt.Container.dispatchEventImpl(Container.jav a:2149)
at java.awt.Window.dispatchEventImpl(Window.java:2478 )
at java.awt.Component.dispatchEvent(Component.java:42 95)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 604)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:138)
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 10:32 PM   #145
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

Why are they not equal in length?
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Old Oct 22, 2009, 10:34 PM   #146
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

Quote:
Originally Posted by FordGT90Concept View Post
Why are they not equal in length?
letterArray is obviously only going to be 1 char long and secretWordArray is going to be however long inputString is.
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 11:10 PM   #147
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

If that is the case, then you aren't comparing your equivlent of _Secret and _Reveal. You must perform that comparison in order to update your display (temp). Without it, you would get "s*****" on the first one then "*e**e*" on the second instead of "se**e*"


If the array is only one character long, it should be a char instead of an array. String.charAt(0) to get the first character of a String.
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Old Oct 22, 2009, 11:37 PM   #148
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

Quote:
Originally Posted by FordGT90Concept View Post
If that is the case, then you aren't comparing your equivlent of _Secret and _Reveal. You must perform that comparison in order to update your display (temp). Without it, you would get "s*****" on the first one then "*e**e*" on the second instead of "se**e*"


If the array is only one character long, it should be a char instead of an array. String.charAt(0) to get the first character of a String.
so let me double check then...this line

Code:
if(secretWordArray[i] == textfieldString.charAt(0))
says that if the char at position 0 on textfieldString is equal to any of the characters in the array secretWordArray...

right?
Easy Rhino is offline  
Reply With Quote
Old Oct 22, 2009, 11:42 PM   #149
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,224 (4.29/day)
Thanks: 1,207
Thanked 2,775 Times in 1,793 Posts

System Specs

my prof just told me that it would be easier to use the indexof() and lastindexof() methods to determine if the letter is part of the word. so i should go with strings rather than arrays. bah,

now i am totally lost.
Easy Rhino is offline  
Reply With Quote
Old Oct 23, 2009, 12:14 AM   #150
FordGT90Concept
"I go fast!1!11!1!"
 
FordGT90Concept's Avatar
 
Join Date: Oct 2008
Location: IA, USA
Posts: 10,581 (6.28/day)
Thanks: 1,755
Thanked 2,598 Times in 1,962 Posts

System Specs

Quote:
Originally Posted by Easy Rhino View Post
so let me double check then...this line

Code:
if(secretWordArray[i] == textfieldString.charAt(0))
says that if the char at position 0 on textfieldString is equal to any of the characters in the array secretWordArray...

right?
The if statement only checks one. The for loop makes it run the if statement for the length of secretWordArray.

I converted Magic to Java for you:
Code:
	private Boolean Magic(char letter)
	{
		Boolean hit = false;

		String temp = "";
		for (int i = 0; i < secretWordArray.length(); i++)
		{
			if (textfieldString.charAt(i) == inputMask.charAt(i))
			{
				if (letter == secretWordArray.charAt(i))
				{
					temp += secretWordArray.charAt(i);
					hit = true;
				}
				else
				{
					temp += inputMask.charAt(i);
				}
			}
			else
			{
				temp += textfieldString.charAt(i);
			}
		}
		textfieldString = temp;

		return hit;
	}
I didn't test it but what it is trying to do is exactly what you need. Notice how there is more than one if statement.

After running that code, you would still have to update the GUI with the text.


What IDE are you using to create this?
__________________
Golden Rule of Programming: Never assume.

try { SteamDownload(); }
catch (Steamception ex) { RageQuit(); }
FordGT90Concept is online now  
Crunching for Team TPU
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a "Malicious Software Tips, Help and Discussion" thread to the forums Black Panther Comments & Feedback 29 Apr 2, 2008 06:34 PM


All times are GMT. The time now is 02:32 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
no new posts