• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Rhino's "I need Java help" thread

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
ok, in Magic(char letter)

secretWordArray is actually inputString.length() since you cant do a .length on an array. but that is fine since i guess Strings will be easier to work with.

the actionPerformed method is a toughy. when the user clicks the OK button it takes the text from tfInput and puts it in the string textfieldString. then i want to execute Magic. however it doesnt like the arguments for magic.

Code:
import java.awt.BorderLayout;
import java.awt.Component;
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 timebombtest extends JFrame implements ActionListener
{
	public String inputString = "";
	public String textfieldString = "";
	public String inputMask = "*";//mask
	public String mask = "";
	public String temp = "";
	
	JTextField tfInput = new JTextField(2);
	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 timebombtest() //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);		

		
		//set font
		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);
		
		//gui properties
		getContentPane().setLayout(new BorderLayout(1,1));

		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);
		getContentPane().add(southPanel, "South");
		
		setSize(350, 200);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	
	private Boolean Magic(char letter)
	{
		Boolean hit = false;

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

		return hit;
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if ("OK".equals(e.getActionCommand()))
		{
			textfieldString = tfInput.getText();
			Magic();
		}
	}
	
	public static void main(String[] args) 
	{
		new timebombtest();
	}
}//end TimeBomb class

im using Eclipse !
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
The argument should be the letter the user input. My guess is you should do Magic(tfInput.getText().charAt(0)). After you call Magic, make sure to update your bomb if Magic returns false.

Rename the "temp" outside of Magic to "reveal" or something else. "temp" should only exist inside of Magic.

Code:
public String mask = "";
mask should be a char and it should be set once with initilization and used after that point instead of using .charAt() to access it.

It is Array.length instead of Array.length().


Eclipse should allow you to use break points to see what is in variables at that point in the application. It is very helpful.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
this doesnt work. cant invoke charAt(int) on the array type char[]

Code:
if (letter == secretWordArray.charAt(i))
				{
					temp += secretWordArray.charAt(i);
					hit = true;
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
If it is defined as a char[] array, use brackets:

secreWordArray


.charAt() only applies to Strings.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
i think it all comes down to actionPerformed...

also, in Magic... inputMask is a class level variable String

public String inputMask = "*";

while mask is

public char mask = '*';

so how would you suggest i encounter that?

Code:
public void actionPerformed(ActionEvent e)
	{
		if ("OK".equals(e.getActionCommand()))
		{
			textfieldString = tfInput.getText();
			Magic(tfInput.getText().charAt(0));
		}
	}

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at timebombtest.Magic(timebombtest.java:91)
at timebombtest.actionPerformed(timebombtest.java:120)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:253)
at java.awt.Component.processMouseEvent(Component.java:6108)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3276)
at java.awt.Component.processEvent(Component.java:5873)
at java.awt.Container.processEvent(Container.java:2105)
at java.awt.Component.dispatchEventImpl(Component.java:4469)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Component.dispatchEvent(Component.java:4295)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4461)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4125)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4055)
at java.awt.Container.dispatchEventImpl(Container.java:2149)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4295)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
 
Last edited:

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
i think it all comes down to actionPerformed...

also, in Magic... inputMask is a class level variable String
I guessed what names belonged where because I don't follow your naming at all. :( I think you had a variable missing (equivilent of reveal) but I really don't know.


public String inputMask = "*";

while mask is

public char mask = '*';

so how would you suggest i encounter that?
I don't follow? You can make a char a string by appending it to an empty string. e.g.
Code:
inputMask += mask;
The two should now equal although doing so is kind of pointless.



There's a NullPointerException at Magic(timebombtest.java:91). If you can copy that area and point out which line is 91, I should be able to help you with that.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
I guessed what names belonged where because I don't follow your naming at all. :( I think you had a variable missing (equivilent of reveal) but I really don't know.



I don't follow? You can make a char a string by appending it to an empty string. e.g.
Code:
inputMask += mask;
The two should now equal although doing so is kind of pointless.

well cause in Magic inputMask.charAt(i) and if that is a char then you cant do .charAt(i)

There's a NullPointerException at Magic(timebombtest.java:91). If you can copy that area and point out which line is 91, I should be able to help you with that.

Code:
for (int i = 0; i < secretWordArray.length; i++)

and here is my entire code

Code:
import java.awt.BorderLayout;
import java.awt.Component;
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 timebombtest extends JFrame implements ActionListener
{
	public String inputString = "";
	public String textfieldString = "";
	public String inputMask = "*";
	public char mask = '*';
	public String hidereveal = "";
	public char[] secretWordArray;
	
	JTextField tfInput = new JTextField(2);
	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 timebombtest() //constructor for GUI
	{
		super("Time Bomb Game");
		
		inputString = JOptionPane.showInputDialog("Enter Secret Word: ");//user enters secret word
		textfieldString = tfInput.getText();
		
		for(int i = 0; i < inputString.length(); i++)
		{
			hidereveal +=  mask;//creates a mask of the secret word of the appropriate length
			maskedWord = new JLabel(hidereveal);		
		}
		
		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 <inputString.length(); i++)
		{
			secretWordArray[i] = inputString.charAt(i);//populate array using inputString
		}

		//set font
		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);
		
		//gui properties
		getContentPane().setLayout(new BorderLayout(1,1));

		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);
		getContentPane().add(southPanel, "South");
		
		setSize(350, 200);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	
	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[i])
				{
					temp += secretWordArray[i];
					hit = true;
				}
				else
				{
					temp += inputMask.charAt(i);
				}
			}
			else
			{
				temp += textfieldString.charAt(i);
			}
		}
		textfieldString = temp;

		return hit;
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if ("OK".equals(e.getActionCommand()))
		{
			Magic(tfInput.getText().charAt(0));
		}
	}
	
	public static void main(String[] args) 
	{
		new timebombtest();
	}
}//end TimeBomb class
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
secretWordArray is null in Magic.

Edit:
Code:
	private Boolean Magic(char letter)
	{
		Boolean hit = false;

		String temp = "";
		for (int i = 0; i < inputString.length(); i++)
		{
			if (hidereveal.charAt(i) == mask)
			{
				if (hidereveal.charAt(i) == inputString.charAt(i))
				{
					temp += inputString.charAt(i);
					hit = true;
				}
				else
				{
					temp += mask;
				}
			}
			else
			{
				temp += hidereveal.charAt(i);
			}
		}
		hidereveal = temp;

		return hit;
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if ("OK".equals(e.getActionCommand()))
		{
			if (tfInput.getText().length() > 0)
			{
			Magic(tfInput.getText().charAt(0));
			tfInput.setText(""); // clear for next letter
			maskedWord.setText(hidereveal);
			}
		}
	}

Before running Magic, make sure inputString has a value (e.g. "blamo"), make sure hidereveal matches inputString in length but containing all masks (e.g. "*****").
 
Last edited:

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
k i did a little troubleshooting with System.out.println and i noticed that in Magic that while
hidereveal does equal the number letters in the secret word it does not equal mask.

the mask before the for statement equals *

but after the for statement ( the secret word is awesome(7 letters) it shows

*
*
*
*
*
*
*

so 1 for every letter
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
mask should always be *

Only hidereveal and temp should change. temp is especially the one to watch because it is merging hidereveal, the letter, and inputString.


I don't see a problem. :confused:
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
for this code

Code:
	private Boolean Magic(char letter)
	{
		Boolean hit = false;

		String temp = "";
		System.out.println("inputString = " + inputString);
		System.out.println("hidereveal = " + hidereveal);
		System.out.println("mask = " + mask);
		for (int i = 0; i < inputString.length(); i++)
		{
			if (hidereveal.charAt(i) == mask)
			{
				System.out.println("mask = " + mask);
				if (hidereveal.charAt(i) == inputString.charAt(i))
				{
					temp += inputString.charAt(i);
					System.out.println("temp = " + temp);
					hit = true;
				}
				else
				{
					temp += mask;
					System.out.println("temp = " + temp);
					System.out.println("mask = " + mask);
				}
			}
			else
			{
				temp += hidereveal.charAt(i);
			}
		}
		hidereveal = temp;

i get this in console

inputString = awesome
hidereveal = *******
mask = *
mask = *
temp = *
mask = *
mask = *
temp = **
mask = *
mask = *
temp = ***
mask = *
mask = *
temp = ****
mask = *
mask = *
temp = *****
mask = *
mask = *
temp = ******
mask = *
mask = *
temp = *******
mask = *


as you can see inputString does equal the correct value and hidereveal equals the exact amount of necessary * but inputString.charAt(i) never adds anything to temp. and then it just keeps looping asterisks.
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
What's the letter you gave to Magic?
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
I think I see the bug. I check my code...

Code:
				System.out.println("mask = " + mask);
				if (hidereveal.charAt(i) == inputString.charAt(i))
				{
					temp += inputString.charAt(i);
					System.out.println("temp = " + temp);
					hit = true;
				}
				else
				{
					temp += mask;
					System.out.println("temp = " + temp);
					System.out.println("mask = " + mask);
				}
change to:
Code:
				System.out.println("mask = " + mask);
				if (letter == inputString.charAt(i))
				{
					temp += inputString.charAt(i);
					System.out.println("temp = " + temp);
					hit = true;
				}
				else
				{
					temp += mask;
					System.out.println("temp = " + temp);
					System.out.println("mask = " + mask);
				}

I deleted the "letter" bit. :( temp should then be correct. :)
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
damn man, id celebrate but im too exhausted :laugh: :toast:

ok, so now i just have to work on the timer. im guessing i should put some sort of for loop inside the nested else statement...
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
When Magic (recommend you change the name of that to something more descriptive, by the way) return false, redraw the timer. I'd use a for loop to create the dashes.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
When Magic (recommend you change the name of that to something more descriptive, by the way) return false, redraw the timer. I'd use a for loop to create the dashes.

shouldnt i put a hit = false; after

temp += hidereveal.charAt(i);

sidenote: what exactly is letter doing in your magic method?
 
Last edited:

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
It depends on how creative you want to get with it.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
not sure what is going on here but if you guess wrong on the very first guess it does not deduct 1. you have to guess right first and then no matter what your guess the second time it deducts 1.

am i putting the timer in the wrong spot??
hit = false; isnt necessary is it since we declare it false before the for loop runs?
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
if (!Magic(char))
{
// decrement timer
}

Don't do anything if it returns true.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
The button click action performed.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
right now i set it up to simply count down to 0 and go boom when ever the user enters a letter right or wrong. here is my code for that. now i need ot get actionPerformed to recognize the boolean hit results from compareSecret.

int guessedWrong = 5; // class level variable
JLabel timer = new JLabel(" ==- 5 -== "); // class level variable that represents the initial value of gussedWrong

Code:
public void actionPerformed(ActionEvent e)
	{
		if ("OK".equals(e.getActionCommand()))
		{
			if (tfInput.getText().length() > 0)
			{
			compareSecret(tfInput.getText().charAt(0));
			tfInput.setText(""); // clear for next letter
			maskedWord.setText(hidereveal);

			guessedWrong--; // subtract 1 from guessedWrong
			String wrongGuess = String.valueOf(guessedWrong); // turn the int gussedWrong into a String so it can be put into setText
			timer.setText(" ==- " + wrongGuess + " -== "); // place the value of guessedWrong into the JLabel timer. 
			if(guessedWrong == 0) // set condition for BOOM!
			{
				timer.setText("BOOM!"); // set "BOOM!"
			}
			}
			
		}

	}
 
Last edited:

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.41/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
I think (note the Boolean hit = )...
Code:
	public void actionPerformed(ActionEvent e)
	{
		if ("OK".equals(e.getActionCommand()))
		{
			if (tfInput.getText().length() > 0)
			{
				Boolean hit = compareSecret(tfInput.getText().charAt(0));
				tfInput.setText(""); // clear for next letter
				maskedWord.setText(hidereveal);
				
				if (!hit)
				{
					guessedWrong--; // subtract 1 from guessedWrong
					String wrongGuess = String.valueOf(guessedWrong); // turn the int gussedWrong into a String so it can be put into setText
					timer.setText(" ==- " + wrongGuess + " -== "); // place the value of guessedWrong into the JLabel timer. 
					if(guessedWrong == 0) // set condition for BOOM!
					{
						timer.setText("BOOM!"); // set "BOOM!"
					}
				}
			}
			
		}

	}
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,643 (2.35/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software Fedora KDE Spin
yup that did it.
 
Top