Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to call Visual Basic .exe from Java?

Posted on 2003-03-10
2
Medium Priority
?
132 Views
Last Modified: 2011-09-20
Hello;

     Can anyone help how to call a visual basic exe file from a JButton, because I'd like to call my print software in my java program so that I could print my report, thanks . . .

0
Comment
Question by:Rosewell
2 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8103108
You can use this:

import java.io.*;

public class RunAsync {

    public static void main(String args[]){

     try {
        Process pro = null;
        if (args.length > 0) {
          pro = Runtime.getRuntime().exec(args);
        }
        else {
          pro = Runtime.getRuntime().exec(args[0]);
        }
        InputStream error = pro.getErrorStream();
        InputStream output = pro.getInputStream();
        Thread err = new Thread(new OutErrReader(error));
        Thread out = new Thread(new OutErrReader(output));
        out.start();
        err.start();
        pro.waitFor();
     }
     catch(java.io.IOException e){
       e.printStackTrace();
     }
     catch(java.lang.InterruptedException e){
       e.printStackTrace();
     }

    }

    static class OutErrReader implements Runnable {
      InputStream is;

      public OutErrReader(InputStream is){
        this.is = is;
      }

      public void run(){
        try {
          BufferedReader in = new BufferedReader(new InputStreamReader(is));
          String temp = null;
          while((temp = in.readLine()) != null){
             System.out.println(temp);
          }
          is.close();
        }
        catch(Exception e){
          e.printStackTrace();
        }
      }
    }
}
0
 
LVL 2

Accepted Solution

by:
antonsigur earned 320 total points
ID: 8103301
...

JButton b = new JButton("Run application");

b.addActionListener(new myListener());

 ....


//The button listener
pirvare class myListener implements ActionListener {
  public void actionPerformed(ActionEvent ev) {
    try {
     Runtime.getRuntime().exec("yourprogram.exe");
     } catch(java.io.IOException e){
      e.printStackTrace();
    }
    catch(java.lang.InterruptedException e){
      e.printStackTrace();
    }
  }
}

Note, that you should give your points to CEHJ, I only implemented the raw listener...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question