Is there a way to use commandline within a JFrame GUI?
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 m开发者_开发问答ain 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?
Use a jtextField
to get the user input and use the gettext()
to get value entered in jtextField
and use this to show message.
Alternatively, you can obtain the parameter s
as a command line argument. There's an example here.
I can't add a
TextListener
to theJTextField
. So how could I get the text?
You can add an ActionLIstener
to your JTextField
like they show in the tutorial and other examples.
精彩评论