1 16 package net.sf.jftp.gui.base; 17 18 import java.io.BufferedInputStream ; 19 import java.io.BufferedOutputStream ; 20 21 import javax.swing.JComponent ; 22 import javax.swing.JOptionPane ; 23 import javax.swing.JPasswordField ; 24 25 import net.sf.jftp.tools.Shell; 26 27 28 public class UIUtils 29 { 30 public static String getPasswordFromUser(JComponent parent) 31 { 32 JOptionPane j = new JOptionPane (); 33 JPasswordField pField = new JPasswordField (); 34 35 int ret = j.showOptionDialog(parent, pField, "Password required", 36 JOptionPane.YES_NO_OPTION, 37 JOptionPane.QUESTION_MESSAGE, null, null, 38 null); 39 40 return pField.getText(); 41 } 42 43 public static void runCommand(String cmd) { 44 Spawn s = new Spawn(cmd); 45 } 46 } 47 48 class Spawn implements Runnable { 49 private Thread runner; 50 private String cmd; 51 52 public Spawn(String cmd) { 53 this.cmd = cmd; 54 55 runner = new Thread (this); 56 runner.start(); 57 } 58 59 public void run() { 60 try { 61 String str = ""; 62 63 if(cmd.startsWith("file://")) cmd = cmd.substring(7); 64 65 Process p = Runtime.getRuntime().exec(cmd); 66 new Shell(p.getInputStream(), p.getOutputStream()); 67 68 } 72 catch(Exception ex) { 73 ex.printStackTrace(); 74 } 75 } 76 77 } 78 79 80 | Popular Tags |