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

Rhino's "I need Java help" thread

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/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've done something similar before and what I did was create masks...

Step 1: Count the number of unique characters in the string. e.g. "blamo" has five unique characters.

Step 2: Create a "Mask" class or struct which has two definitions in it: 1) A String or char that represents this mask and 2) a String which holds the mask for that character.

Step 3: Create an array of class "mask", one for each unique character. Everything not that character has an underscore. e.g. "b____", "_l___", "__a__" etc.

Step 4: Make a MergeMask class which accepts two masks (or strings) and returns one string. This is a simple for loop where if value not equal to an underscore, copy to the output string. e.g. "b____" and "__a__" returns "b_a__"

Step 5: When they type a character, search your Mask array for a match. If no match, that's a strike against them. If it is a match you use the Step 4 method to make an output value.


I just checked how to get a char from a string:
Code:
String mystring = "blamo";
mystring.charAt(4); // 'o'
mystring.charAt(0); // 'b'

You could always stick to a byte array too. It's easy to convert from string, to bytes, and back to string.
 
Last edited:

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix
im getting there. ive been at it for 8 hours today and i am learning a lot! :):eek::shadedshu:mad::cry:

here is my code. i can return a length which is easy enough. but i need to return the inputString in an array format which is possible with strings. i just dont know how how yet...

Code:
import java.io.*;

public class ArrayDemo2 
{
	String inputString;

	private BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
	
	public void wordInput() throws IOException
	{
		System.out.println("Enter Word: ");
		inputString = keyboard.readLine();
		System.out.println("Your word has this many letters: " + inputString.length());
	}
	
	public static void main(String[] args) throws IOException
	{
		ArrayDemo2 x = new ArrayDemo2();
		x.wordInput();

	}//end of main
}//end of class
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix
I've done something similar before and what I did was create masks...

Step 1: Count the number of unique characters in the string. e.g. "blamo" has five unique characters.

Step 2: Create a "Mask" class or struct which has two definitions in it: 1) A String or char that represents this mask and 2) a String which holds the mask for that character.

Step 3: Create an array of class "mask", one for each unique character. Everything not that character has an underscore. e.g. "b____", "_l___", "__a__" etc.

Step 4: Make a MergeMask class which accepts two masks (or strings) and returns one string. This is a simple for loop where if value not equal to an underscore, copy to the output string. e.g. "b____" and "__a__" returns "b_a__"

Step 5: When they type a character, search your Mask array for a match. If no match, that's a strike against them. If it is a match you use the Step 4 method to make an output value.


I just checked how to get a char from a string:
Code:
String mystring = "blamo";
mystring.charAt(4); // 'o'
mystring.charAt(0); // 'b'

You could always stick to a byte array too. It's easy to convert from string, to bytes, and back to string.

wow you posted this just as i updated my posting. the charAt() is going to come in very handy. i figure im going to keep it simple. im going to use the readLine() to get user's secret word and then output it as a mask.

now i just need to figure out how to get a String into a JFrame.
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/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.
JLabel <- Just display a message
JTextArea <- Multiline text input
JTextField <- Single line text input

Full list here.

This article has an example of how to add components to a JFrame.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix
JLabel <- Just display a message
JTextArea <- Multiline text input
JTextField <- Single line text input

Full list here.

This article has an example of how to add components to a JFrame.

oh yes we learned that stuff. i can create buttons and fields and manipulate them. the problem is i cannot get a String into a JFrame. so if

Code:
String inputString;
System.out.println("Enter Secret Word: ");
inputString = keyboard.readLine();

i need to get inputString into a JFrame, specifically my southPanel...

Code:
JPanel southPanel = new JPanel();
southPanel.add(inputString);
getContentPane().add(southPanel, "South");

and it says the method add(Component) for type Container is not applicable for the arguments (String)
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/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.
JPanel is just a Container for other Components. TextField is a Component which primarily contains a String.

JFrame -- has a -> JPanel -- has a -> TextField -- has a -> String

Work backwards...

Create: TextField
Value: String

Create: JPanel
Value: TextField

Create: JFrame
Value: JPanel
 

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
Since I'm learning along with Rhino ... ;) something like this?
Code:
JTextField intputStringContainer = new JTextField(inputString)
JPanel panel = new JPanel();
panel.add(intputStringContainer);

For what I can garner from Rhino's description, it looks like he wants to display the input string hidden (masked). Since JTextField is an editable control, wouldn't a JLabel be a more likely candidate so it could not be edited in the GUI?
Or does JTextField have some kind of ReadOnly property?

Or am I completely off base here?
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix
Since I'm learning along with Rhino ... ;) something like this?
Code:
JTextField intputStringContainer = new JTextField(inputString)
JPanel panel = new JPanel();
panel.add(intputStringContainer);

For what I can garner from Rhino's description, it looks like he wants to display the input string hidden (masked). Since JTextField is an editable control, wouldn't a JLabel be a more likely candidate so it could not be edited in the GUI?
Or does JTextField have some kind of ReadOnly property?

so how in the world do i get inputString to a JFrame. one is a String and the other is a JFrame

anyway, i need to come up with a method that gets the inputString entered in the console and put it in the JFrame

Or am I completely off base here?

you are right that in this case we need a JLabel to display our masked/unmasked word.
ive actually have it set up as you do but it doesnt display anything. im thinking it is because i am entering the word in the console. that is how my prof set it up tho. he actually used a dialog box.
 
Last edited:

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix
i think where most of my confusion lays is with JFrames and Strings.

Is it possible to enter a word into the console and have it appear in a GUI ?

The only way you can enter and store a word from the console is by using a String.

The only way you can put data onto a GUI is by using a JFrame.

This is where I am stuck.
 

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
Why not have them enter it in the GUI?
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix
Why not have them enter it in the GUI?

well i am thinking that. the problem there is that JBbuttons/labels are all final. they do not change. So you can't put a label in the GUI that says "Enter Secret Word" and then have that same label change to "Guess A Letter."
 

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
Why do the two have to be in the same place?
2 labels, 2 input boxes
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/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.
Code:
public class Program
{
	public static String UserInput = ""

	public static void main(String[] args)
	{
		System.out.println("Enter Word: ");
		UserInput = keyboard.readLine();

		// Call up the Main frame of the GUI.
		new Main();
	}
}

public class Main extends JFrame
{
	public Main()
	{
		// Set generics.
		this.setTitle("Test");
		this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		this.setSize(700, 300);
		this.setResizable(false);
		
		JPanel panel = new JPanel() // The panel.
		panel.add(new JLabel(Program.UserInput))  // The label set to the user inputed text.
		this.add(panel);
		
		this.setVisible(true);
	}
}
I didn't compile it so I'm not certain it works.


well i am thinking that. the problem there is that JBbuttons/labels are all final. they do not change. So you can't put a label in the GUI that says "Enter Secret Word" and then have that same label change to "Guess A Letter."
You can change the text on JButton and JLabel via .setText("new value")


Generally speaking, you either want all console or all GUI. They are like oil and water (due to the static nature of the console) so they don't mix well.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix
Code:
public class Program
{
	public static String UserInput = ""

	public static void main(String[] args)
	{
		System.out.println("Enter Word: ");
		UserInput = keyboard.readLine();

		// Call up the Main frame of the GUI.
		new Main();
	}
}

public class Main extends JFrame
{
	public Main()
	{
		// Set generics.
		this.setTitle("Test");
		this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		this.setSize(700, 300);
		this.setResizable(false);
		
		JPanel panel = new JPanel() // The panel.
		panel.add(new JLabel(Program.UserInput))  // The label set to the user inputed text.
		this.add(panel);
		
		this.setVisible(true);
	}
}
I didn't compile it so I'm not certain it works.



You can change the text on JButton and JLabel via .setText("new value")


Generally speaking, you either want all console or all GUI. They are like oil and water (due to the static nature of the console) so they don't mix well.

well i am a noob. i just realized the JLabel guessLetter wasnt putting out inputString because there is no value for inputString yet when I declare JLabel. :laugh::banghead:

java --> :nutkick: <-- me
 

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
Welcome to programming. If you read my thread on the Control array problem, you will realize stuff like this happens for the rest of your life.
Get used to it. :laugh:
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix
i have finally reached the HEART of my problem. check out my 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.JPanel;
import javax.swing.JTextField;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class TimeBomb extends JFrame implements ActionListener
{
	String inputString;
	String inputMask = "*";//mask
	private final BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
	
	private final JTextField tfInput = new JTextField(2);
	private final JLabel lblMessage = new JLabel("Enter A Letter: ");
	private final JLabel guessLetter = new JLabel(inputMask);
	private final JButton btnOK = new JButton("OK");
	private final JLabel timer = new JLabel("*-----");
	
	public TimeBomb() throws IOException//constructor for GUI
	{
		super("Time Bomb Game");
		
		System.out.println("Enter Secret Word: ");//enter secret word into console
		inputString = keyboard.readLine();//store secret word
		for(int i = 0; i < inputString.length(); i++)//gets the length of the secret word
			System.out.print(inputMask);//creates a mask of the secret word of the appropriate length

		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);
		guessLetter.setFont(f1);
		btnOK.setFont(f1);
		timer.setFont(f2);
		
		getContentPane().setLayout(new BorderLayout(1,1));

		JPanel northPanel = new JPanel();
		northPanel.add(lblMessage);
		getContentPane().add(northPanel, "North");
		
		JPanel westPanel = new JPanel();
		westPanel.add(timer);
		getContentPane().add(westPanel, "West");
		
		JPanel centerPanel = new JPanel();
		centerPanel.add(tfInput);
		getContentPane().add(centerPanel, "Center");
		
		JPanel eastPanel = new JPanel();
		eastPanel.add(btnOK);
		getContentPane().add(eastPanel, "East");
		btnOK.addActionListener(this);
		
		JPanel southPanel = new JPanel();
		southPanel.add(guessLetter);
		getContentPane().add(southPanel, "South");
		
		setSize(310, 200);
		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
		{
			guessLetter.setText(tfInput.getText());
		}
	}
	
	public static void main(String[] args) throws IOException
	{
		new TimeBomb();
	}
}//end TimeBomb class

notice...

private final JLabel guessLetter = new JLabel(inputMask);

well that is actually pulling the initial value of inputMask which is set to * as a class level variable. in the actual contsructor though, inputMask gets set to whatever the length of the word is.

so i need to get guessLetter to read the inputMask from the contsructor, not from the class level variable.
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/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.
Code:
	String inputString;
	String inputMask = "*";//mask
Those two should have an access modifier on them.


Code:
private final JLabel guessLetter = new JLabel(inputMask);
That could raise an error because of the "final" flag.
 

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
final in Java is like const in C#, isn't it.
Does all that stuff have to be final?
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/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's the same as "readonly."

None of it has to be "final."
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/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 guess I don't understand what problem you are having.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix
I guess I don't understand what problem you are having.

eheh. well the problem is that JLabel guessLetter = new JLabel(inputMask) is getting the inputMask value from the class level variable rather than from the constructor which sets inputMask to the length of the inputString but with * instead of letters.

could this be an issue of the order of my code?
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/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.
Well, this bit of code is quite useless:
Code:
		for(int i = 0; i < inputString.length(); i++)//gets the length of the secret word
			System.out.print(inputMask);//creates a mask of the secret word of the appropriate length
System.out will do ***** in the console, not your JLabel.

guessLetter will be a JLabel with the text "*" on load. You aren't chaning the value of it until the action is performed.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/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 The Matrix
Well, this bit of code is quite useless:
Code:
		for(int i = 0; i < inputString.length(); i++)//gets the length of the secret word
			System.out.print(inputMask);//creates a mask of the secret word of the appropriate length
System.out will do ***** in the console, not your JLabel.

guessLetter will be a JLabel with the text "*" on load. You aren't chaning the value of it until the action is performed.

that is my issue. i know that it will output ****in the console and i need it to output**** in guessLetter
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/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.
Code:
		String temp = "";
		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
		guessLetter = new JLabel(temp);
 
Top