Does including javax.swing elements in a standalone exe cause it to crash?
이전 댓글 표시
Suppose I have a set of codes to display a JFrame, a JPanel, and a JLabel. This works fine if I run it as a script file:
frame = javax.swing.JFrame('Test');
panel = javax.swing.JPanel();
label = javax.swing.JLabel('A label');
panel.add(label);
frame.add(panel);
frame.setDefaultCloseOperation(javax.swing.JFrame.HIDE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
The problem comes when I compile this as an exe file with the deploytool. It will compile and I can run the program, but the frame will show up for about 3 seconds or so then disappear. If I run from inside Matlab with !main.exe, there is no error message. Neither is there one if I run the executable from the Windows command prompt (same results -- shows for a few seconds and then crashes).
Any ideas what is going on here? I can compile other files just fine. Is the problem because I included the javax.swing elements?
Many thanks for your help.
답변 (1개)
Sruthi Ayloo
2014년 7월 11일
편집: Sruthi Ayloo
2014년 7월 11일
You could add 'waitfor(frame)' at the end of your code and compile it using mcc with the -e flag for the windows console not to appear.
frame = javax.swing.JFrame('Test');
frame.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
panel = javax.swing.JPanel();
label = javax.swing.JLabel('A label');
panel.add(label);
frame.add(panel);
frame.pack();
frame.setVisible(true);
waitfor(frame);
This might resolve the issue. But, when the executable is run in MATLAB with the '!' operator, the control does not get returned to the MATLAB command line.
카테고리
도움말 센터 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!