使用java与flex轻便构建cs程序

 今日发现SmartInvoke这一好东西,拿过来与大伙分享分享!

 

原稿地址 http://smartinvoke.cn/pages/document.jsp

 

透过它可以轻巧的兑现java与flex在本土的相互调用,利用java与flex构建强大的CS程序不是梦。

原稿如次:

================================================

 

大伙儿都晓得flex的web application不能操作和访问本土资料,我们今日就透过
smartInvoke让flex可以轻便的访问到本土资料。

1:在java应用程序中创造1操作当地资料的test.CFile种,创造几个对资料进展
访问的步骤;具体如次:

1.
2. package test;
3.
四.import java.io.File;
5.
六.import cn.smartinvoke.javaflex.gui.IServerObject;
7.//IServerObject示意该类型是一个服务门类专诚接受flex署理门类对象的访问
八.public class CFile implements IServerObject{
9. public File file=null;
10. public CFile(String fileName) {
11. file=new File(fileName);
12. }
13. public long getSize(){
14. return this.file.length();
15. }
16. public String getName(){
17. return this.file.getName();
18. }
19. /**
20. * @param args
21. */
22. public static void main(String[] args) {
23.
24. }
25.
26.}
Java代码
1.
2. package test;
3.
四.import java.io.File;
5.
六.import cn.smartinvoke.javaflex.gui.IServerObject;
7.//IServerObject示意该类型是一个服务门类专程接受flex署理门类对象的访问
八.public class CFile implements IServerObject{
9. public File file=null;
10. public CFile(String fileName) {
11. file=new File(fileName);
12. }
13. public long getSize(){
14. return this.file.length();
15. }
16. public String getName(){
17. return this.file.getName();
18. }
19. /**
20. * @param args
21. */
22. public static void main(String[] args) {
23.
24. }
25.
26.}

package test;

import java.io.File;

import cn.smartinvoke.javaflex.gui.IServerObject;
//IServerObject示意该类型是一个服务门类专诚接受flex署理部类对象的访问
public class CFile implements IServerObject{
public File file=null;
public CFile(String fileName) {
file=new File(fileName);
}
public long getSize(){
return this.file.length();
}
public String getName(){
return this.file.getName();
}
/**
* @param args
*/
public static void main(String[] args) {

}

}

2:应用CodeTransform工具生成test.CFile种的署理种test.CFile.as,具体内容如次:


1. package test
2.
三.import cn.smartinvoke.RemoteObject;
4./**
5. 该类承继于cn.smartinvoke.RemoteObject是java中的test.CFile种的署理门类
6. 专程用来调用java中的对应部类。
7.*/
八.public class CFile extends RemoteObject {
9. public function CFile(){
10. super();
11. }
12. //调用此步骤可以创造java中的test.CFile门类对象
13. public static function create_CFile(fileName:String):CFile{
14. var file:CFile=new CFile();
15. file.createRemoteObject(null,arguments);
16. return file;
17. }
18. //此步骤会调用java中的test.CFile.getName()步骤,并将该步骤的回到值回来
19. public function getName():String{
20. var retObj:Object=this.call("getName",arguments);
21. return retObj as String;
22.
23. }
24. public function getSize():Number{
25. var retObj:Object=this.call("getSize",arguments);
26. return Number(retObj);
27.
28. }
29.}
Java代码
1. package test
2.
三.import cn.smartinvoke.RemoteObject;
4./**
5. 该类承继于cn.smartinvoke.RemoteObject是java中的test.CFile种的署理门类
6. 专程用来调用java中的对应门类。
7.*/
八.public class CFile extends RemoteObject {
9. public function CFile(){
10. super();
11. }
12. //调用此步骤可以创办java中的test.CFile门类对象
13. public static function create_CFile(fileName:String):CFile{
14. var file:CFile=new CFile();
15. file.createRemoteObject(null,arguments);
16. return file;
17. }
18. //此步骤会调用java中的test.CFile.getName()步骤,并将该步骤的回来值回来
19. public function getName():String{
20. var retObj:Object=this.call("getName",arguments);
21. return retObj as String;
22.
23. }
24. public function getSize():Number{
25. var retObj:Object=this.call("getSize",arguments);
26. return Number(retObj);
27.
28. }
29.}
30.
31.
package test
{
import cn.smartinvoke.RemoteObject;
/**
该类承袭于cn.smartinvoke.RemoteObject是java中的test.CFile种的署理部类
专程用来调用java中的对应门类。
*/
public class CFile extends RemoteObject {
public function CFile(){
super();
}
//调用此步骤可以创设java中的test.CFile门类对象
public static function create_CFile(fileName:String):CFile{
var file:CFile=new CFile();
file.createRemoteObject(null,arguments);
return file;
}
//此步骤会调用java中的test.CFile.getName()步骤,并将该步骤的回到值回来
public function getName():String{
var retObj:Object=this.call("getName",arguments);
return retObj as String;

}
public function getSize():Number{
var retObj:Object=this.call("getSize",arguments);
return Number(retObj);

}
}

}
3:创设flex程序smartinvoke.mxml并调用CFile署理种


1.
2.
3.
4. 5. import mx.controls.Alert;
6. import test.CFile;
7. import cn.smartinvoke.executor.Executor;
8. /**
9. *此swf加载完毕后调用此步骤
10. */
11. function onLoad():void{
12. //让smartInvoke为java与flex互相调用办好预备
13. Executor.init();
14. }
15. /**
16. *此步骤调用java的test.CFile.getSize步骤取得C:/win_yy.png资料的大小,并显示出来
17. */
18. function getFileName():void{
19. //调用java创办test.CFile种对象,并将此对象包装成flex的test.CFile
20. //署理对象并回到
21. var file:CFile=CFile.create_CFile("C:/win_yy.png");
22. //取得C:/win_yy.png资料的大小
23. var fileSize:Number=file.getSize();
24.
25. Alert.show("资料大小为"+fileSize);
26. }
27. ]]>
28.
29.
30.
31.
Xml代码
1.
2.
3.
4. 5. import mx.controls.Alert;
6. import test.CFile;
7. import cn.smartinvoke.executor.Executor;
8. /**
9. *此swf加载完毕后调用此步骤
10. */
11. function onLoad():void{
12. //让smartInvoke为java与flex互相调用办好预备
13. Executor.init();
14. }
15. /**
16. *此步骤调用java的test.CFile.getSize步骤取得C:/win_yy.png资料的大小,并显示出来
17. */
18. function getFileName():void{
19. //调用java创设test.CFile种对象,并将此对象包装成flex的test.CFile
20. //署理对象并回到
21. var file:CFile=CFile.create_CFile("C:/win_yy.png");
22. //取得C:/win_yy.png资料的大小
23. var fileSize:Number=file.getSize();
24.
25. Alert.show("资料大小为"+fileSize);
26. }
27. ]]>
28.
29.
30.
31.

 

import mx.controls.Alert;
import test.CFile;
import cn.smartinvoke.executor.Executor;
/**
*此swf加载完毕后调用此步骤
*/
function onLoad():void{
//让smartInvoke为java与flex互相调用办好预备
Executor.init();
}
/**
*此步骤调用java的test.CFile.getSize步骤取得C:/win_yy.png资料的大小,并显示出来
*/
function getFileName():void{
//调用java创设test.CFile种对象,并将此对象包装成flex的test.CFile
//署理对象并回来
var file:CFile=CFile.create_CFile("C:/win_yy.png");
//取得C:/win_yy.png资料的大小
var fileSize:Number=file.getSize();

Alert.show("资料大小为"+fileSize);
}
]]>

 

4:利用swt 将flex 调整到java程序中间并运作整个程序。


1. package test;
2.
三.import org.eclipse.swt.SWT;
四.import org.eclipse.swt.layout.FillLayout;
五.import org.eclipse.swt.widgets.Display;
六.import org.eclipse.swt.widgets.Shell;
7.
八.import cn.smartinvoke.javaflex.gui.FlashContainer;
9.
十.public class DemoFirst extends Shell {
11.
12. /**
13. * Launch the application
14. * @param args
15. */
16. public static void main(String args[]) {
17. try {
18. Display display = Display.getDefault();
19. DemoFirst shell = new DemoFirst(display, SWT.SHELL_TRIM);
20. shell.open();
21. shell.layout();
22. while (!shell.isDisposed()) {
23. if (!display.readAndDispatch())
24. display.sleep();
25. }
26. } catch (Exception e) {
27. e.printStackTrace();
28. }
29. }
30.
31. /**
32. * Create the shell
33. * @param display
34. * @param style
35. */
36. public DemoFirst(Display display, int style) {
37. super(display, style);
38. createContents();
39. setLayout(new FillLayout());
40. }
41.
42. /**
43. * Create contents of the window
44. */
45. protected void createContents() {
46. setText("smartinvoke测试程序");
47. //将flash控件添加到窗体
48. FlashContainer flashContainer=new FlashContainer(this);
49. //加载smartinvoke.mxml编译生成的smartinvoke.swf
50. flashContainer.loadMovie(零, "E:/flexWork/smartinvoke/bin-debug/smartinvoke.swf");
51. setSize(500, 375);
52. //
53. }
54.
55. @Override
56. protected void checkSubclass() {
57. // Disable the check that prevents subclassing of SWT components
58. }
59.
60.}
Java代码
1. package test;
2.
三.import org.eclipse.swt.SWT;
四.import org.eclipse.swt.layout.FillLayout;
五.import org.eclipse.swt.widgets.Display;
六.import org.eclipse.swt.widgets.Shell;
7.
八.import cn.smartinvoke.javaflex.gui.FlashContainer;
9.
十.public class DemoFirst extends Shell {
11.
12. /**
13. * Launch the application
14. * @param args
15. */
16. public static void main(String args[]) {
17. try {
18. Display display = Display.getDefault();
19. DemoFirst shell = new DemoFirst(display, SWT.SHELL_TRIM);
20. shell.open();
21. shell.layout();
22. while (!shell.isDisposed()) {
23. if (!display.readAndDispatch())
24. display.sleep();
25. }
26. } catch (Exception e) {
27. e.printStackTrace();
28. }
29. }
30.
31. /**
32. * Create the shell
33. * @param display
34. * @param style
35. */
36. public DemoFirst(Display display, int style) {
37. super(display, style);
38. createContents();
39. setLayout(new FillLayout());
40. }
41.
42. /**
43. * Create contents of the window
44. */
45. protected void createContents() {
46. setText("smartinvoke测试程序");
47. //将flash控件添加到窗体
48. FlashContainer flashContainer=new FlashContainer(this);
49. //加载smartinvoke.mxml编译生成的smartinvoke.swf
50. flashContainer.loadMovie(零, "E:/flexWork/smartinvoke/bin-debug/smartinvoke.swf");
51. setSize(500, 375);
52. //
53. }
54.
55. @Override
56. protected void checkSubclass() {
57. // Disable the check that prevents subclassing of SWT components
58. }
59.
60.}
package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import cn.smartinvoke.javaflex.gui.FlashContainer;

public class DemoFirst extends Shell {

/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
Display display = Display.getDefault();
DemoFirst shell = new DemoFirst(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Create the shell
* @param display
* @param style
*/
public DemoFirst(Display display, int style) {
super(display, style);
createContents();
setLayout(new FillLayout());
}

/**
* Create contents of the window
*/
protected void createContents() {
setText("smartinvoke测试程序");
//将flash控件添加到窗体
FlashContainer flashContainer=new FlashContainer(this);
//加载smartinvoke.mxml编译生成的smartinvoke.swf
flashContainer.loadMovie(零, "E:/flexWork/smartinvoke/bin-debug/smartinvoke.swf");
setSize(500, 375);
//
}

@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}

}
运作DemoFirst程序就可以看到结果了^_^,是否觉着一切都很简单呀

java调用flex也是相仿

接下来我们模拟1实施靠山业务的java工作线程,当此线程实施完毕后调用test.FlexShell种的
setStatus(String info)步骤将info字符串展示在flex窗体中,以示意靠山业务施行完成。

第一:在flex中创办test.FlexShell.as种,具体内容如次:


1. package test
2.{
3. import cn.smartinvoke.IServerObject;
4.
5. import mx.controls.Alert;
6.
7. public class FlexShell implements IServerObject
8. {
9. public function FlexShell()
10. {
11. }
12. /**
13. *将info代表的讯息打印出来
14. */
15. public function setStatus(info:String):void{
16. Alert.show(info);
17. }
18. }
19.}
Java代码
1. package test
2.{
3. import cn.smartinvoke.IServerObject;
4.
5. import mx.controls.Alert;
6.
7. public class FlexShell implements IServerObject
8. {
9. public function FlexShell()
10. {
11. }
12. /**
13. *将info代表的讯息打印出来
14. */
15. public function setStatus(info:String):void{
16. Alert.show(info);
17. }
18. }
19.}
package test
{
import cn.smartinvoke.IServerObject;

import mx.controls.Alert;

public class FlexShell implements IServerObject
{
public function FlexShell()
{
}
/**
*将info代表的讯息打印出来
*/
public function setStatus(info:String):void{
Alert.show(info);
}
}
}
第二:运用CodeTransform工具生成test.FlexShell.as种的署理种test.FlexShell.java,具体内容如次:


一.package test;
二.import cn.smartinvoke.javaflex.gui.RemoteObject;
三.import cn.smartinvoke.javaflex.gui.FlashContainer;
四.public class FlexShell extends RemoteObject {
5. public FlexShell(FlashContainer container){
6. super(container);
7. this.createRemoteObject(null);//调用flex创办该署理种的服务种
8. }
9. public void setStatus(String info){//调用flex对应服务部类的setStatus步骤
10. this.call("setStatus",new Object[]{info});
11. }
12.}
Java代码
一.package test;
二.import cn.smartinvoke.javaflex.gui.RemoteObject;
三.import cn.smartinvoke.javaflex.gui.FlashContainer;
四.public class FlexShell extends RemoteObject {
5. public FlexShell(FlashContainer container){
6. super(container);
7. this.createRemoteObject(null);//调用flex创设该署理种的服务种
8. }
9. public void setStatus(String info){//调用flex对应服务部类的setStatus步骤
10. this.call("setStatus",new Object[]{info});
11. }
12.}
package test;
import cn.smartinvoke.javaflex.gui.RemoteObject;
import cn.smartinvoke.javaflex.gui.FlashContainer;
public class FlexShell extends RemoteObject {
public FlexShell(FlashContainer container){
super(container);
this.createRemoteObject(null);//调用flex创办该署理种的服务种
}
public void setStatus(String info){//调用flex对应服务部类的setStatus步骤
this.call("setStatus",new Object[]{info});
}
}
最后:在java的DemoFirst部类中加入后台老板业务处置线程的逻辑如次:


1. package test;
2.
三.import org.eclipse.swt.SWT;
四.import org.eclipse.swt.layout.FillLayout;
五.import org.eclipse.swt.widgets.Display;
六.import org.eclipse.swt.widgets.Shell;
7.
八.import cn.smartinvoke.javaflex.gui.FlashContainer;
九.import cn.smartinvoke.javaflex.gui.ILoadCompleteListener;
十.import cn.smartinvoke.javaflex.util.Log;
11.
12.public class DemoFirst extends Shell {
13.
14. /**
15. * Launch the application
16. * @param args
17. */
18. public static void main(String args[]) {
19. try {
20. Log.open=true;
21. Display display = Display.getDefault();
22. DemoFirst shell = new DemoFirst(display, SWT.SHELL_TRIM);
23. shell.open();
24. shell.layout();
25. while (!shell.isDisposed()) {
26. if (!display.readAndDispatch())
27. display.sleep();
28. }
29. } catch (Exception e) {
30. e.printStackTrace();
31. }
32. }
33.
34. /**
35. * Create the shell
36. * @param display
37. * @param style
38. */
39. public DemoFirst(Display display, int style) {
40. super(display, style);
41. createContents();
42. setLayout(new FillLayout());
43. }
44.
45. /**
46. * Create contents of the window
47. */
48. protected void createContents() {
49. setText("smartinvoke测试程序");
50. //将flash控件添加到窗体
51. final FlashContainer flashContainer=new FlashContainer(this);
52. /**
53. *应flash加载完毕后,FlashContainer会调用ILoadCompleteListener
54. *的run步骤,你可以在这里做一些初始化
55. */
56. flashContainer.completeListener=new ILoadCompleteListener(){
57. public void run() {
58. //起动一靠山实施线程
59. Thread task=new Thread(){
60. public void run(){
61. //模拟后台任务
62. try {
63. Thread.sleep(2000);//等候十秒
64.
65. FlexShell flexShell=new FlexShell(flashContainer);
66. flexShell.setStatus("退后任务施行完毕...");
67. } catch (InterruptedException e) {
68. e.printStackTrace();
69. }
70. }
71. };
72.
73. task.setDaemon(true);//将后盾线程设立为看护线程,保证书主线程退出时此线程也能退出
74. task.start();
75. }
76. };
77.
78.
79. //加载smartinvoke.mxml编译生成的smartinvoke.swf
80. flashContainer.loadMovie(零, "E:/flexWork/smartinvoke/bin-debug/smartinvoke.swf");
81. setSize(500, 375);
82. //
83. }
84.
85. @Override
86. protected void checkSubclass() {
87. // Disable the check that prevents subclassing of SWT components
88. }
89.
90.}
Java代码
1. package test;
2.
三.import org.eclipse.swt.SWT;
四.import org.eclipse.swt.layout.FillLayout;
五.import org.eclipse.swt.widgets.Display;
六.import org.eclipse.swt.widgets.Shell;
7.
八.import cn.smartinvoke.javaflex.gui.FlashContainer;
九.import cn.smartinvoke.javaflex.gui.ILoadCompleteListener;
十.import cn.smartinvoke.javaflex.util.Log;
11.
12.public class DemoFirst extends Shell {
13.
14. /**
15. * Launch the application
16. * @param args
17. */
18. public static void main(String args[]) {
19. try {
20. Log.open=true;
21. Display display = Display.getDefault();
22. DemoFirst shell = new DemoFirst(display, SWT.SHELL_TRIM);
23. shell.open();
24. shell.layout();
25. while (!shell.isDisposed()) {
26. if (!display.readAndDispatch())
27. display.sleep();
28. }
29. } catch (Exception e) {
30. e.printStackTrace();
31. }
32. }
33.
34. /**
35. * Create the shell
36. * @param display
37. * @param style
38. */
39. public DemoFirst(Display display, int style) {
40. super(display, style);
41. createContents();
42. setLayout(new FillLayout());
43. }
44.
45. /**
46. * Create contents of the window
47. */
48. protected void createContents() {
49. setText("smartinvoke测试程序");
50. //将flash控件添加到窗体
51. final FlashContainer flashContainer=new FlashContainer(this);
52. /**
53. *应flash加载完毕后,FlashContainer会调用ILoadCompleteListener
54. *的run步骤,你可以在这里做一些初始化
55. */
56. flashContainer.completeListener=new ILoadCompleteListener(){
57. public void run() {
58. //起动一靠山施行线程
59. Thread task=new Thread(){
60. public void run(){
61. //模拟后台任务
62. try {
63. Thread.sleep(2000);//等候一十秒
64.
65. FlexShell flexShell=new FlexShell(flashContainer);
66. flexShell.setStatus("退后任务实施完毕...");
67. } catch (InterruptedException e) {
68. e.printStackTrace();
69. }
70. }
71. };
72.
73. task.setDaemon(true);//将后盾线程设立为照护线程,责任书主线程退出时此线程也能退出
74. task.start();
75. }
76. };
77.
78.
79. //加载smartinvoke.mxml编译生成的smartinvoke.swf
80. flashContainer.loadMovie(零, "E:/flexWork/smartinvoke/bin-debug/smartinvoke.swf");
81. setSize(500, 375);
82. //
83. }
84.
85. @Override
86. protected void checkSubclass() {
87. // Disable the check that prevents subclassing of SWT components
88. }
89.
90.}
package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import cn.smartinvoke.javaflex.gui.FlashContainer;
import cn.smartinvoke.javaflex.gui.ILoadCompleteListener;
import cn.smartinvoke.javaflex.util.Log;

public class DemoFirst extends Shell {

/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
Log.open=true;
Display display = Display.getDefault();
DemoFirst shell = new DemoFirst(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Create the shell
* @param display
* @param style
*/
public DemoFirst(Display display, int style) {
super(display, style);
createContents();
setLayout(new FillLayout());
}

/**
* Create contents of the window
*/
protected void createContents() {
setText("smartinvoke测试程序");
//将flash控件添加到窗体
final FlashContainer flashContainer=new FlashContainer(this);
/**
*应flash加载完毕后,FlashContainer会调用ILoadCompleteListener
*的run步骤,你可以在这里做一些初始化
*/
flashContainer.completeListener=new ILoadCompleteListener(){
public void run() {
//起步一后台老板实施线程
Thread task=new Thread(){
public void run(){
//模拟后台任务
try {
Thread.sleep(2000);//等候十秒

FlexShell flexShell=new FlexShell(flashContainer);
flexShell.setStatus("退后任务施行完毕...");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};

task.setDaemon(true);//将靠山线程设立为照护线程,军令状主线程退出时此线程也能退出
task.start();
}
};


//加载smartinvoke.mxml编译生成的smartinvoke.swf
flashContainer.loadMovie(零, "E:/flexWork/smartinvoke/bin-debug/smartinvoke.swf");
setSize(500, 375);
//
}

@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}

}
将smartinvoke.mxml该为如次:


1.
2.3. layout="vertical" creationComplete="onLoad()">
4.
5. 6. import test.FlexShell;
7. import mx.controls.Alert;
8. import test.CFile;
9. import cn.smartinvoke.executor.Executor;
10. /**
11. *此swf加载完毕后调用此步骤
12. */
13. var file:CFile=null;
14. //将FlexShell摘引到目前程序中间,否则flex没法用反照形式创造FlexShell门类对象
15. var flexShell:FlexShell;
16. function onLoad():void{
17. //让smartInvoke为java与flex互相调用抓好预备
18. Executor.init();
19. this.file=CFile.create_CFile("C:/win_yy.png");
20. }
21. /**
22. *此步骤调用java的test.CFile.getSize步骤取得C:/win_yy.png资料的大小,并显示出来
23. */
24. function getFileName():void{
25. //调用java创办test.CFile种对象,并将此对象包装成flex的test.CFile
26. //署理对象并回到
27.
28. //取得C:/win_yy.png资料的大小
29. var fileSize:Number=file.getSize();
30.
31. Alert.show("资料大小为"+fileSize);
32. //运用完毕后调用dispose步骤开释java的对应部类
33. file.dispose();
34.
35. }
36. ]]>
37.
38.
39.
40.
Java代码
1.
2.3. layout="vertical" creationComplete="onLoad()">
4.
5. 6. import test.FlexShell;
7. import mx.controls.Alert;
8. import test.CFile;
9. import cn.smartinvoke.executor.Executor;
10. /**
11. *此swf加载完毕后调用此步骤
12. */
13. var file:CFile=null;
14. //将FlexShell引述到目前程序中间,要不然flex没法用反照模式创办FlexShell部类对象
15. var flexShell:FlexShell;
16. function onLoad():void{
17. //让smartInvoke为java与flex互相调用搞好预备
18. Executor.init();
19. this.file=CFile.create_CFile("C:/win_yy.png");
20. }
21. /**
22. *此步骤调用java的test.CFile.getSize步骤取得C:/win_yy.png资料的大小,并显示出来
23. */
24. function getFileName():void{
25. //调用java创办test.CFile种对象,并将此对象包装成flex的test.CFile
26. //署理对象并回到
27.
28. //取得C:/win_yy.png资料的大小
29. var fileSize:Number=file.getSize();
30.
31. Alert.show("资料大小为"+fileSize);
32. //施用完毕后调用dispose步骤开释java的对应部类
33. file.dispose();
34.
35. }
36. ]]>
37.
38.
39.
40.

layout="vertical" creationComplete="onLoad()">

import test.FlexShell;
import mx.controls.Alert;
import test.CFile;
import cn.smartinvoke.executor.Executor;
/**
*此swf加载完毕后调用此步骤
*/
var file:CFile=null;
//将FlexShell摘引到现阶段程序中间,要不然flex没法用反照模式创造FlexShell部类对象
var flexShell:FlexShell;
function onLoad():void{
//让smartInvoke为java与flex互相调用抓好预备
Executor.init();
this.file=CFile.create_CFile("C:/win_yy.png");
}
/**
*此步骤调用java的test.CFile.getSize步骤取得C:/win_yy.png资料的大小,并显示出来
*/
function getFileName():void{
//调用java创办test.CFile种对象,并将此对象包装成flex的test.CFile
//署理对象并回来

//取得C:/win_yy.png资料的大小
var fileSize:Number=file.getSize();

Alert.show("资料大小为"+fileSize);
//施用完毕后调用dispose步骤开释java的对应部类
file.dispose();

}
]]>

 


从新编译mxml,并运作DemoFirst 程序就可以看到成效了。

到现在我们已经轻便的兑现java与flex其间相互调用了,是否有种幸福来得太忽然的感觉

 

我的异常网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值