Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. /*
  2. This java program copies the value from a jTextField, adds it to a     predifined value
  3. and send it to command-line as a parameter. All these happens if you click     the jButton
  4.  */
  5.  
  6. import javax.swing.*;
  7. import java.awt.*;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10.  
  11. public class ComputerQuery extends JFrame {
  12.     static JTextField jTextField1 = new JTextField(20);
  13.     JButton jButton1 = new JButton("Click");
  14.     static JLabel jLabel1 = new JLabel();
  15.  
  16.     public ComputerQuery() {
  17.         super("CmdJavaParameterPass");
  18.  
  19.         getContentPane().setLayout(new FlowLayout());
  20.  
  21.         getContentPane().add(jTextField1);
  22.         getContentPane().add(jButton1);
  23.         getContentPane().add(jLabel1);
  24.         jButton1.addActionListener(new ActionListener() {
  25.             public void actionPerformed(ActionEvent e) {
  26.                 sendParam();
  27.             }
  28.         });
  29.  
  30.         setSize(300, 170);
  31.         setVisible(true);
  32.     }
  33.  
  34.     public static void sendParam() {
  35.  
  36.         try {
  37.             String val = MISControlPanel.textField.getText(); // Put whatever
  38.                                                                 // you want to
  39.                                                                 // pass as a
  40.                                                                 // prefix in
  41.                                                                 // place of
  42.                                                                 // "Computer"
  43.             jLabel1.setText(val);
  44.             Process p;
  45.             p = Runtime.getRuntime().exec(
  46.                     "cmd /c start c:\\computerQuery.bat " + val + "");
  47.         } catch (Exception e) {
  48.             e.printStackTrace();
  49.         }
  50.     }
  51.  
  52.     public static void main(String argv[]) {
  53.  
  54.         new ComputerQuery();
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement