Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #1649 > unrolled thread

JButton and Execute Windo

Started by"banker123" <banker123@THRWHITE.remove-dii-this>
First post2011-04-27 15:34 +0000
Last post2011-04-27 15:34 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.lang.java.gui


Contents

  JButton and Execute Windo "banker123" <banker123@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
    Re: JButton and Execute W "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
      Re: JButton and Execute W "m.djukic" <m.djukic@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000

#1649 — JButton and Execute Windo

From"banker123" <banker123@THRWHITE.remove-dii-this>
Date2011-04-27 15:34 +0000
SubjectJButton and Execute Windo
Message-ID<1179422059.871542.165620@q75g2000hsh.googlegroups.com>
  To: comp.lang.java.gui
I am new to Java, I have built a GUI that contains a JButton.  I would
like this JButton to execute a windows batch file when the user clicks
the button.  Below is my attempt, please help.


private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{

    try {
    Runtime rt = Runtime.getRuntime();
    String[] args = {"c:\\test.bat"};
    Process proc = rt.exec(args);
    }
    catch  (IOException e) {
    System.err.println (e);
    }

    }

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#1653 — Re: JButton and Execute W

From"Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this>
Date2011-04-27 15:34 +0000
SubjectRe: JButton and Execute W
Message-ID<464d19f9$0$15090$4c368faf@roadrunner.com>
In reply to#1649
  To: comp.lang.java.gui
banker123 wrote:
> I am new to Java, I have built a GUI that contains a JButton.  I would
> like this JButton to execute a windows batch file when the user clicks
> the button.  Below is my attempt, please help.
> 
> 
> private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
> {
> 
>     try {
>     Runtime rt = Runtime.getRuntime();
>     String[] args = {"c:\\test.bat"};
>     Process proc = rt.exec(args);
>     }
>     catch  (IOException e) {
>     System.err.println (e);
>     }
> 
>     }
> 

Maybe you should tell us what the problem is unless you think we can 
read your mind.

At first glance, an ActionListener must implement "public void 
actionPerformed(ActionEvent)" so you need to at least change that in 
your code.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#1663 — Re: JButton and Execute W

From"m.djukic" <m.djukic@THRWHITE.remove-dii-this>
Date2011-04-27 15:34 +0000
SubjectRe: JButton and Execute W
Message-ID<1179615714.926267.217230@n59g2000hsh.googlegroups.com>
In reply to#1653
  To: comp.lang.java.gui


try:

...
	Runtime r = Runtime.getRuntime();
	Process p = null;
	String cmd =  "c://test.bat";
	try {
	    p = r.exec(cmd);

           p.waitFor(); //to wait to execute command

	} catch (Exception e) {
	    System.out.println("error executing " + cmd);
	}
	System.out.println(cmd + " returned " + p.exitValue());

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web