0

So, I made a jar file which runs a class that has JFrame, panel and a button. Once the button is clicked it runs the main method of my class that runs a method with parameter(String s);

I would like this parameter to change depending on the user's needs.

For example, if clicking the button shows a message s,

I would like the user to type in the message that they want.

So if they type in hi, they would get hi, on their screen.

Is there a way to do this?

StanislavL
  • 56,113
  • 9
  • 64
  • 93
  • I've been trying to do what Sanjay has told me. but it seems I can't add a TextListener to the jtextField. so how could i get the text – James Lee Oct 11 '11 at 07:19

3 Answers3

2

Use a jtextField to get the user input and use the gettext() to get value entered in jtextField and use this to show message.

COD3BOY
  • 11,724
  • 1
  • 36
  • 55
1

Alternatively, you can obtain the parameter s as a command line argument. There's an example here.

Community
  • 1
  • 1
trashgod
  • 200,320
  • 28
  • 229
  • 974
0

I can't add a TextListener to the JTextField. So how could I get the text?

You can add an ActionLIstener to your JTextField like they show in the tutorial and other examples.

Catalina Island
  • 6,905
  • 2
  • 22
  • 41