我从班级批处理中调用了类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中的任何东西之前打印这条线。
答案 0 :(得分:1)
您的代码显示您的java项目有两个主要类。另一个在batchrun
类中,guibuilder
类。 [来自您的陈述guibuilder.main(args)
]
在项目中只使用一个主类。这可能会解决您的问题。
我认为您的guibuilder
类具有这样的结构
class guibuilder{
...... //global variables
public static void main(String[] args){
......... //statments
}
}
不要在一个项目中使用两种主要方法。
你需要像这样构建你的guibuilder
类(如下所示)
class guibuilder{
...... //global variables
public static void buildGui(){//you can use any method name here
......... //statments
}
}
从另一个类调用此方法只需使用此语句
guibuilder.buildGui()
或另一种方式
class guibuilder{
...... //global variables
public void buildGui(){//you can use any method name here
......... //statments
}
}
从另一个类调用此方法使用此语句
guibuilder gui=new guibuilder();
gui.buildGui();