将控制权从应用程序带到Java框架 [英] Bring control from application to java frame

查看:59
本文介绍了将控制权从应用程序带到Java框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Java程序在arduino板和暂存文件之间进行通信.沟通进行得很好.我使用一个用户界面来启动通信,其中有一个名为

I use a java program for communication between a arduino board and a scratch file. The communication happen well. I use a user interface to start the communication where i have buttons called

连接 关闭并最小化

connect close and minimize

当用户单击连接按钮代码时,将检查组合框中的值,并相应地打开临时文件.

When the user clicks the connect button code will check the value in combo box and accordingly it opens the scratch file.

单击连接按钮后,控件将移至临时应用程序.完成工作后,当我尝试关闭草稿时.我的临时应用程序按预期关闭,但是控件没有返回到用户界面,因此我无法关闭该应用程序,而无法在Net Bean中强制关闭该应用程序.在输出屏幕中,我看不到构建成功,而是停止构建.那是我的过程完美地工作,直到我给出连接,但是一旦按下按钮,它就会挂在某个地方.

Once the connect button is clicked the control moves to the scratch application. After completing my work when i tried closing the scratch. My scratch application closes as expected but the control does not return to the user interface because of which i am not able to close the application and i close it in net beans forcefully. In the output screen i don't see build successful and instead i get build stopped. That is my process works perfectly until i give connect but once the button is pressed it is hanged up some where.

我尝试将其制作为jar文件,然后在另一台计算机上运行它,当时我使用任务管理器中的最终任务来关闭应用程序.

I tried making it as a jar file and running it in a different machine at that time i use end task in task manager to close the application.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

if("Disconnect".equals(jButton1.getText()))
{
    System.exit(0);
}

if(jComboBox2.getSelectedItem()==null)
{
    System.out.println("Select one port");
}
else
{           
    Runtime r = Runtime.getRuntime();

    try {
        //this.hide();
        //p = r.exec("C:\\Program Files\\Scratch 2\\Scratch 2.exe     C:\\Users\\Admin\\Desktop\\fwdbckpwm12.sb2");

        p = Runtime.getRuntime().exec("C:\\Program Files\\Scratch 2\\Scratch   2.exe C:\\Users\\Admin\\Desktop\\scratch files new.sb2");

        //Runtime.getRuntime().exec("taskkill /F /IM <p>.exe");            
        //p.destroy();
        //r.exec("C:\\Windows\\notepad.exe C:\\Windows\\ss.txt");
        //this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        A4S a4sObj = new A4S(new String[] {jComboBox2.getSelectedItem().toString()});  //defaultline

        //A4S a4sObj = new A4S(new String[]{"COM16"});  //addedline
        //r.gc();
        //this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    } catch (IOException ex) {
        Logger.getLogger(serialportselection.class.getName()).log(Level.SEVERE, null, ex);
    } 
    finally{
        //p.destroy();
        //System.gc(); 
   // }

}            

这是我尝试的代码.但是似乎没有一个起作用.

Here is the code i tried. But none seems to work.

推荐答案

  1. 将所有与Process相关的工作移到单独的线程中.
  2. 使用 waitFor 识别过程结束的方法-那么您可以自由地 退出您的应用.
  1. Move all Process related work into separate Thread.
  2. Use waitFor method to recognise Process end - then you are free to exit your app.

这篇关于将控制权从应用程序带到Java框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆