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,971
  • 9
  • 68
  • 98
  • 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,964
  • 1
  • 38
  • 56
1

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

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
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
  • 7,027
  • 2
  • 23
  • 42