Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with GUI? 1

Status
Not open for further replies.

jeak

Technical User
Oct 9, 2002
16
0
0
US
I am working on a simple program where in the code below I need to display "Hello, (name entered)!" instead of "A very good name!". I'm not sure how to display the input from the user to the screen. Does anyone have any suggestions on the best way to do this? Thanks!

public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("Test"))
name.setText("A very good name!");
else if (e.getActionCommand().equals("Clear"))
name.setText("");
else
name.setText("Error in window interface.");
}
 
If you want to display it to the console then use
Code:
System.out.println(String)

If you want to display it on a GUI window then I suggest you read the Java documentation for JLabels. They provide everything you need.

Doco is here -> ----------------------------------------
There are no onions, only magic
----------------------------------------
 
I want to display the text on a GUI window and I have read the Java documentation for JLabels. I am still not sure how to display both "Hello, " and the input from the user. Does anyone have any other suggestions? Thanks!
 
Assuming your user input is set to a variable named usrInput:

name.setText("Hello, " +usrInput);

should do it... basically just *concatinate* the strings... napa1m
hansen@ithsite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top