java swing receiving input (strings) from a jtextfield
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Windows 7 home premium X86_64 | Linux
Posts: 63
Rep:
java swing receiving input (strings) from a jtextfield
hello!
I am trying to make a Java swing application that executes commands. My question is that how do you receive a string of characters (a-z, or 1-9) when the user puts the command on the jtextfield?. like if the user types in the jtextfield: kdesudo adept
how would i get those characters to execute them? Thank you so much!
Distribution: Windows 7 home premium X86_64 | Linux
Posts: 63
Original Poster
Rep:
Ok thanks guys! But im confused. I Use netbeans and i drag the jbutton onto the GUI. then i side click the button and do the ActionPerformed event. But when ever i try doing Runtime.getRuntime().exec(cmd)
The IDE tells me: "catch" without "finnaly"
i know that i must import java.io.IOException and for the top of the source code do: public static void main(String[] Args)Extends IOException
But i wanted the button to execute the command. i would have to execute the command in the same bracket as where i Extend IOException. How do i fix this? thank you!
If you need to separate the process from the event handler, you can create a separate method in your class that also declares that it throws IOException. You can then send the input from the event handler to that method to have it processed.
JTextEdit.getString() tells you *what* command to run. You've probably also got a JButton somewhere to trigger *when* you run the command. The JButton, of course, is yet a third, completely different thing. With its own, separate, action listener.
STRONG SUGGESTION:
1. Create a new project in your IDE
2. Cut and paste (or type in) one of the tutorial examples jay73 and I cited above.
Do *not* use the IDE to create any GUI elements for you - do everything with code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.