开发者

Is there a way to use commandline within a JFrame GUI?

开发者 https://www.devze.com 2023-04-12 07:13 出处:网络
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

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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号