Results 1 to 6 of 6
- 07-05-2013, 11:24 AM #1
Pinging an IP adress that is taken from a TextField.
hey.
im making a program with different sorts of buttons and textfields, to execute commands in the command prompt. (such as ping, ipconfig, and more).
im kinda stuck on the ping option.
i have a JTextField where the user has to fill in an IP adress to ping.
then i save that ip adress in a string and i tried to make a command out of that.
check out how i did it below:
Java Code:JButton btnNewButton_7 = new JButton("Ping -->"); btnNewButton_7.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try{ String ipadd = textField_1.getText(); Process p = Runtime.getRuntime().exec("cmd /c ping"+ipadd); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = reader.readLine(); while(line != null){ textArea.append(line+"\n"); line = reader.readLine(); } }catch(IOException e3){} } }); btnNewButton_7.setBounds(221, 154, 107, 31); getContentPane().add(btnNewButton_7);
i know that i cant put a string on that process, but i don't know any other way i could do this.
so what i want: user filling in an ip adress in the textfield, then i want to make the command ping the filled in ip adress.
any solutions?
ThanksNever give up.
- 07-05-2013, 11:35 AM #2
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Pinging an IP adress that is taken from a TextField.
Check out this epic article:
When Runtime.exec() won't - JavaWorld
And you will want to do the actual ping in a separate thread; you don't want the action listener to be on hold while the ping command is doing its thing, it runs on the EDT and so will block the EDT. That is most likely the reason why you don't "see" anything happening.
- 07-05-2013, 12:10 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 07-05-2013, 12:13 PM #4
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Pinging an IP adress that is taken from a TextField.
Doh! Nice catch.
- 07-05-2013, 12:23 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: Pinging an IP adress that is taken from a TextField.
Build a wall around Donald Trump; I'll pay for it.
- 07-05-2013, 12:36 PM #6
Similar Threads
-
One row help with Locking Java to MAC Adress
By Darkbound in forum New To JavaReplies: 1Last Post: 04-28-2011, 08:42 PM -
Won't set to textfield
By Steffers in forum New To JavaReplies: 7Last Post: 11-04-2010, 03:32 PM -
Get Ip adress?
By Godsent in forum NetworkingReplies: 2Last Post: 07-11-2009, 03:15 PM -
TextField Example
By Java Tip in forum SWT TipsReplies: 0Last Post: 07-25-2008, 03:21 PM -
JSP - getting value from a textfield
By Java Tip in forum Java TipReplies: 0Last Post: 12-01-2007, 09:58 PM
Bookmarks