【发布时间】:2016-07-26 05:35:32
【问题描述】:
我正在从我的类批处理运行中调用类 guibuilder。 batchrun 的代码是:-
public class batchrun {
public static String md5gen(String a) throws NoSuchAlgorithmException
{
MessageDigest m= MessageDigest.getInstance("MD5");
m.reset();
m.update(a.getBytes());
byte[] digest=m.digest();
BigInteger bigInt = new BigInteger(1,digest);
String hashtext = bigInt.toString(16);
while(hashtext.length() < 32 ){
hashtext = "0"+hashtext;
}
return hashtext;
}
private static String getInputAsString(InputStream is)
{
try(java.util.Scanner s = new java.util.Scanner(is))
{
return s.useDelimiter("\\A").hasNext() ? s.next() : "";
}
}
public static void main(String[] args) throws InterruptedException {
try {
guibuilder.main(args);
guibuilder gb=new guibuilder();
String fg=guibuilder.antd;
String arg1=gb.arg;
String userinp1=gb.userinp;
System.out.println("FG="+fg+" arg1="+arg1+" userinp="+userinp1);
Process pan = Runtime.getRuntime().exec(new String[] {"C:\\test1.bat",arg1,fg});
pan.waitFor();
String extra="\\";
extra+=userinp1;
String patha=fg+extra;
ProcessBuilder pb = new ProcessBuilder("adb","shell","getprop","ro.csc.sales_code");
Process p=pb.start();
p.waitFor();
String stdout = getInputAsString(p.getInputStream());
String newstring=stdout.substring(0,3);;
String fn=fg+"\\"+newstring+".txt";
ZipFile zipFile = new ZipFile(patha);
Enumeration<?> enu = zipFile.entries();
int flag=0;
String so="so";
File file = new File(fn);
FileOutputStream fos = new FileOutputStream(file);
PrintStream ps = new PrintStream(fos);
System.setOut(ps);
while (enu.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) enu.nextElement();
String name = zipEntry.getName();
long size= zipEntry.getSize();
String extension= name.substring(name.lastIndexOf(".")+1,name.length());
if(extension.equals(so))
{
String plaintext=name+size;
String md5result=md5gen(plaintext);
System.out.println(name+" "+size+" "+md5result);
++flag;
}
}
if(flag==0)
System.out.println("fail");
}catch (IOException ex){
System.out.println(ex.getMessage());
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
guibuilder的代码是
public class guibuilder {
private JFrame frame;
public static String antd;
public static String arg;
public static String userinp;
/**
* Launch the application.
* @return
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
guibuilder window = new guibuilder();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public guibuilder() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnExtract = new JButton("Extract");
btnExtract.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
frame.dispose();
fchooser fc1=new fchooser();
antd=fc1.demo();
arg=JOptionPane.showInputDialog("Enter the apk path");
userinp=JOptionPane.showInputDialog("Enter the apk name");
}
});
btnExtract.setBounds(69, 55, 89, 23);
frame.getContentPane().add(btnExtract);
JButton btnCompare = new JButton("Compare");
btnCompare.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
frame.dispose();
newjframe n = new newjframe();
n.setVisible(true);
}
});
btnCompare.setBounds(261, 55, 89, 23);
frame.getContentPane().add(btnCompare);
}
}
我希望程序在继续执行 batchrun 中的代码之前等待 guibuilder 的执行。但是在这段代码中,我什至没有选择 guibuilder 中的文件,程序继续执行并且 System.out.println("FG="+fg+" arg1="+arg1+" userinp="+userinp1);在我在 guibuilder 中选择任何内容之前打印此行。
【问题讨论】:
-
它确实在等待(如果不是多线程的),如果它直接进入你说的那一行,那么你之前的方法已经完成了。
-
如需尽快获得更好的帮助,请发帖minimal reproducible example 或Short, Self Contained, Correct Example。
-
为更清晰而编辑。你现在能帮我解决这个问题吗
标签: java swing class jfilechooser