导航:首页 > 编程语言 > javabindings绑定函数

javabindings绑定函数

发布时间:2024-05-14 03:09:37

java类里的数组 如何 赋值给js里数组

js(jsp)二级联动并且将java数组赋值给js

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%@taglib uri="/struts-tags" prefix="s"%>
<%
String [][]str = {{"40000","09401","09402"},{"40001","09403","09404"}};
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>add score</title>

<meta. http-equiv="pragma" content="no-cache">
<meta. http-equiv="cache-control" content="no-cache">
<meta. http-equiv="expires" content="0">
<meta. http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta. http-equiv="description" content="This is my page">

<script. language="javascript">

function select(){
var bj=document.getElementById('class');<!--删除前一次创建的-->
obj.options.length=0;
var course = document.getElementById("course").value;
alert(course);

<%
for(int i=0;i<str.length;i++){%>
if(course == "<%=str[i][0]%>"){
<%
for(int j=1;j<str[i].length;j++){%>

var ption = document.createElement("option");
oOption.innerHTML = "<%=str[i][j]%>"
oOption.value = "<%=str[i][j]%>"
document.getElementById("class").options.add(oOption);
<%}%>
}
<%}%>

var arr = "<%=str[0][1]%>";
alert(arr);
}
</script>

<script. type="text/javascript">

</script>

</head>

<body id="level1">
<form. action="delete!deleteStudent.action" method="post">
<font size="2px" color="red"><s:property value="#request.sexistError"/></font>
课程:<select id="course" name="course" > <%for(int i=0;i<str.length;i++){ %>
<option nclick="select()"><%=str[i][0]%></option>
<%} %>
</select>

班级:<select id="class" name="cla"> </select>

<div id="score_menu">
<input type="submit" name="submit" class="submit" value="提交"/>
<input type="reset" name="reset" class="reset" value="重置"/><br />

</form>
</body>
</html>

Ⅱ 如何将c++绑定至javascript

下载绑定生成器,本机路径/Users/iven/Dev/bindings-generator
为了在Mac OS X中安装运行MacPort端口,系统必须要已经安装苹果的“Command Line Developer Tools”(命令行开发者工具)。Xcode 4及以后版本的用户首先需要通过启动或运行Xcode接受Xcode EULA。

xcodebuild -license
下载安装MacPort
注意:如果是Homebrew用户,应该先卸载Homebrew。因为Homebrew不兼容MacPort。
同时执行MacPort的“selfupdate”命令以确保安装最新的发布版本。

sudo port -v selfupdate
当更新完成之后,使用MacPort在命令行中安装python依赖(dependencies)

sudo port install python27 py27-yaml py27-cheetah
你会看到如下所示:

下载llvm-3.3,解压至$HOME/bin目录。如果没有bin目录,请创建一个bin目录,将未解压的ZIP压缩包重命名为“clang+llvm-3.3”。
最后目录如下所示:/Users/guanghui/bin/clang+llvm-3.3(guanhui是本机的主目录名字)

样本代码

绑定生成器资源库中包括一个样本测试用例。打开bindings-generator/test/simple_test文件夹。

配置

根据自己的环境个性化设置“test/userconf.ini”和“test/user.cfg”文件。
注意:应该移除后缀为“.sample”的文件如“user.cfg.sample”和“userconf.ini.sample”

[DEFAULT]
androidndkdir=/Users/iven/Dev/android-ndk-r8c
clangllvmdir=/Users/iven/Dev/clang+llvm-3.1-x86_64-apple-darwin11
cxxgeneratordir=/Users/iven/Dev/bindings-generator-master
user.cfg配置如下所示

PYTHON_BIN=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/ python2.7
运行测试样本

./test.sh
如果环境设置正确,你会看到如下所示:

Errors in parsing headers:
1. <severity = Warning,
location =<SourceLocation file None, line 0, column 0>,
details = "argument unusedring compilation: '-nostdinc++'">
不用担心这个警告,你已完成运行,测试用例会创建一个包含3个文件的“simple_test_bindings”目录。

一个绑定类的.hpp头文件

一个实现绑定类的.cpp文件

一个介绍如何(从Java脚本)调用C++类暴露方法的.js文件。

运行测试

Create a JS base Cocos2d-x project. 创建基于JS的Cocos2d-x项目

将“simple_Test folder”文件夹和“simple_test_binding”文件夹添加到项目中

修改“autogentestbindings.cpp”中的注册函数如下:

void register_all_autogentestbindings(JSContext* cx, JSObject* obj) {
jsval nsval;
JSObject *ns;
JS_GetProperty(cx, obj, "ts",&nsval);
if (nsval == JSVAL_VOID) {
ns = JS_NewObject(cx, NULL, NULL, NULL);
nsval = OBJECT_TO_JSVAL(ns);
JS_SetProperty(cx, obj, "ts",&nsval);
} else {
JS_ValueToObject(cx,nsval, &ns);
}
obj = ns;
js_register_autogentestbindings_SimpleNativeClass(cx, obj);
}
注意:如果你将“ts”添加到“test.ini”文件中的“target_namespace”变量里,便会自动生成代码。无需修改。

target_namespace =ts
在“AppDelegate”中注册

包含头文件“autogentestbindings.hpp”然后注册回调函数:

sc->addRegisterCallback(register_all_autogentestbindings);
在“hello.js”文件适当地方增加以下代码。本机将“init f”函数放在第一个场景。

var myClass=new ts.SimpleNativeClass();
var myStr=myClass.returnsACString();
var label = cc.LabelTTF.create(myStr, "Helvetica", 20.0);
限制

绑定生成器存在以下两个限制

自变量数字参数无法工作,所以需要手动编写包装器
代表类无法工作,所以需要手动绑定,详见下一部分。
手动 JSB 绑定

本指南将介绍利用Cocos2d-x 2.14模板如何在自己的项目中实现JSB绑定。
首先用Cocos2d-js模板创建项目。其次,我们会介绍如何一步一步从JS调用本地函数。最后你便会学会如何从本地代码调用JS代码了。
现在让我们开始!本机使用的Mac OS X作为开发环境。

步骤1. 用Cocos2dx-js模板创建新项目,同时新建一个即将绑定至JS的C++类。

将项目命名为“JSBinding”然后点击“Next”、“ Create”

新建一个类然后实现这个类,等会再将其绑定至JS。
按“command+N”新建一个C++类并命名为“JSBinding”,路径为“OS X\C and C++\C++ Class”。

将以下代码添加到“JSBinding.h”文件中。

#include "cocos2d.h"
#include "ScriptingCore.h"
// Define a namespace to manage your code and make your code clearly
namespace JSB {
class JSBinding: public cocos2d::CCObject
{
public:
static cocos2d::CCScene* scene();
virtual bool init();
CREATE_FUNC(JSBinding);
void functionTest();
};
}
现在实现JSBinding.cpp中的类。如下所示:

bool JSB::JSBinding::init(){
bool bRef = false;
do{
cocos2d::CCLog("JSB init...");
bRef = true;
} while (0);
return bRef;
}
void JSB::JSBinding::functionTest(){
cocos2d::CCLog("Function test...");
}
步骤2. 将C++代码绑定至Java脚本代码

按“command+N”新建C++类,然后命名“JSB_AUTO”路径“OS X\C and C++\C++ Class”。

往“JSB_AUTO.h”文件中增加一些代码

#include "jsapi.h"
#include "jsfriendapi.h"
#include "ScriptingCore.h"
#include "JSBinding.h"
void register_all(JSContext* cx, JSObject* obj);
然后注意“JSB_AUTO.cpp”的实现。

#include "jsapi.h"
#include "jsfriendapi.h"
#include "ScriptingCore.h"
#include "JSBinding.h"
void register_all(JSContext* cx, JSObject* obj);
然后注意“JSB_AUTO.cpp”的实现。

#include "cocos2d.h"
#include "cocos2d_specifics.hpp"
// Binding specific object by defining JSClass
JSClass* jsb_class;
JSObject* jsb_prototype;
// This function is mapping the function “functionTest” in “JSBinding.cpp”
JSBool js_functionTest(JSContext* cx, uint32_t argc, jsval* vp){
JSBool ok = JS_TRUE;
JSObject* obj = NULL;
JSB::JSBinding* cobj = NULL;
obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t* proxy = jsb_get_js_proxy(obj);
cobj = (JSB::JSBinding* )(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2(cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
cobj->functionTest();
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return ok;
}
JS_ReportError(cx, "Wrong number of arguments");
return JS_FALSE;
}
JSBool js_constructor(JSContext* cx, uint32_t argc, jsval* vp){
cocos2d::CCLog("JS Constructor...");
if (argc == 0) {
JSB::JSBinding* cobj = new JSB::JSBinding();
cocos2d::CCObject* ccobj = dynamic_cast<cocos2d::CCObject*>(cobj);
if (ccobj) {
ccobj->autorelease();
}
TypeTest<JSB::JSBinding> t;
js_type_class_t* typeClass;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass);
assert(typeClass);
JSObject* obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
js_proxy_t* p = jsb_new_proxy(cobj, obj);
JS_AddNamedObjectRoot(cx, &p->obj, "JSB::JSBinding");
return JS_TRUE;
}
JS_ReportError(cx, "Wrong number of arguments: %d, was expecting: %d", argc, 0);
return JS_FALSE;
}
// This function is mapping the function “create” when using JavaScript code
JSBool js_create(JSContext* cx, uint32_t argc, jsval* vp){
cocos2d::CCLog("js is creating...");
if (argc == 0) {
JSB::JSBinding* ret = JSB::JSBinding::create();
jsval jsret;
do{
if (ret) {
js_proxy_t* proxy = js_get_or_create_proxy<JSB::JSBinding>(cx, ret);
jsret = OBJECT_TO_JSVAL(proxy->obj);
}
else{
jsret = JSVAL_NULL;
}
} while(0);
JS_SET_RVAL(cx, vp, jsret);
return JS_FALSE;
}
JS_ReportError(cx, "Wrong number of arguments");
return JS_FALSE;
}
void js_finalize(JSFreeOp* fop, JSObject* obj){
CCLOGINFO("JSBindings: finallizing JS object %p JSB", obj);
}
// Binding JSB type
void js_register(JSContext* cx, JSObject* global){
jsb_class = (JSClass *)calloc(1, sizeof(JSClass));
jsb_class->name = "JSBinding";
jsb_class->addProperty = JS_PropertyStub;
jsb_class->delProperty = JS_PropertyStub;
jsb_class->getProperty = JS_PropertyStub;
jsb_class->setProperty = JS_StrictPropertyStub;
jsb_class->enumerate = JS_EnumerateStub;
jsb_class->resolve = JS_ResolveStub;
jsb_class->convert = JS_ConvertStub;
jsb_class->finalize = js_finalize;
jsb_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
static JSPropertySpec properties[] = {
{0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
};
// Binding functionTest function
static JSFunctionSpec funcs[] = {
JS_FN("functionTest", js_functionTest, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};
// Binding create() function
static JSFunctionSpec st_funcs[] = {
JS_FN("create", js_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};
// Binding constructor function and prototype
jsb_prototype = JS_InitClass(
cx, global,
NULL,
jsb_class,
js_constructor, 0,
properties,
funcs,
NULL,
st_funcs);
JSBool found;
JS_SetPropertyAttributes(cx, global, "JSB", JSPROP_ENUMERATE | JSPROP_READONLY, &found);
TypeTest<JSB::JSBinding> t;
js_type_class_t* p;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
if (!p) {
p = (js_type_class_t* )malloc(sizeof(_js_global_type_ht));
p->type = typeId;
p->jsclass = jsb_class;
p->proto = jsb_prototype;
p->parentProto = NULL;
HASH_ADD_INT(_js_global_type_ht, type, p);
}
}
// Binding JSB namespace so in JavaScript code JSB namespce can be recognized
void register_all(JSContext* cx, JSObject* obj){
jsval nsval;
JSObject* ns;
JS_GetProperty(cx, obj, "JS", &nsval);
if (nsval == JSVAL_VOID) {
ns = JS_NewObject(cx, NULL, NULL, NULL);
nsval = OBJECT_TO_JSVAL(ns);
JS_SetProperty(cx, obj, "JSB", &nsval);
}
else{
JS_ValueToObject(cx, nsval, &ns);
}
obj = ns;
js_register(cx, obj);
}
现在已经完成了大部分工作,但是我们需要在“SpiderMonkey”进行注册。
打开“AppDelegate.cpp”增加以下代码

ScriptingCore* sc = ScriptingCore::getInstance();
sc->addRegisterCallback(register_all); //add this line
步骤3. 内存管理
在register_all函数前增加两个新函数。

JSBool JSB_cocos2dx_retain(JSContext* cx, uint32_t argc, jsval *vp){
JSObject* thisObj = JS_THIS_OBJECT(cx, vp);
if (thisObj) {
js_proxy_t* proxy = jsb_get_js_proxy(thisObj);
if (proxy) {
((CCObject* )proxy->ptr)->retain();
CCLog("Retain succeed!");
return JS_TRUE;
}
}
JS_ReportError(cx, "Invaild native object");
return JS_FALSE;
}
JSBool JSB_cocos2dx_release(JSContext* cx, uint32_t argc, jsval *vp){
JSObject* thisObj = JS_THIS_OBJECT(cx, vp);
if (thisObj) {
js_proxy_t* proxy = jsb_get_js_proxy(thisObj);
if (proxy) {
((CCObject* )proxy->ptr)->release();
CCLog("Release succeed!");
return JS_TRUE;
}
}
JS_ReportError(cx, "Invaild native object");
return JS_FALSE;
}
在register_all函数中增加以下代码:

JS_DefineFunction(cx, jsb_prototype, "retain", JSB_cocos2dx_retain, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, jsb_prototype, "retain", JSB_cocos2dx_release, 0, JSPROP_READONLY | JSPROP_PERMANENT);
步骤4. 使用C++代码回调Java脚本代码
在C++代码回调Java脚本代码之前增加一些代码至“hello.js”文件。

var testJSB = new JSB.JSBinding();
testJSB.callback = function(i, j){
log("JSB Callback" + i + j);
};
然后打开“JSBinding.cpp”在“functionTest”中增加一些代码。

js_proxy_t* p = jsb_get_native_proxy(this);
jsval retval;
jsval v[] = {
v[0] = UINT_TO_JSVAL(32),
v[1] = UINT_TO_JSVAL(88)
};
ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj),
"callback", 2, v, &retval);
使用“executeFunctionWithOwner()”函数简化函数调用程序
步骤5. 绑定测试
在“hello.js”文件中增加以下代码。

var testJSB = new JSB.JSBinding();
testJSB.retain();
testJSB.functionTest();
testJSB.release();
步骤6. 现在取出(check out)项目
如果你的绑定程序正确无误,将会在调试窗口看到如下界面:

恭喜你成功将JS绑定至本地代码!

Ⅲ 初学了一段时间Java。想做一个应用程序,程序只需要播放一个本地视频,MP4格式,求教怎么做

使用javafx的Media,MediaPlayer,MediaView。代码如下:

importjava.io.File;

importjavafx.application.Application;
importjavafx.beans.binding.Bindings;
importjavafx.beans.property.ReadOnlyProperty;
importjavafx.beans.value.ObservableValue;
importjavafx.event.ActionEvent;
importjavafx.geometry.Pos;
importjavafx.scene.Scene;
importjavafx.scene.control.Button;
importjavafx.scene.control.Menu;
importjavafx.scene.control.MenuBar;
importjavafx.scene.control.MenuItem;
importjavafx.scene.control.Slider;
importjavafx.scene.image.Image;
importjavafx.scene.image.ImageView;
importjavafx.scene.layout.BorderPane;
importjavafx.scene.layout.HBox;
importjavafx.scene.layout.Pane;
importjavafx.scene.layout.VBox;
importjavafx.scene.media.Media;
importjavafx.scene.media.MediaPlayer;
importjavafx.scene.media.MediaPlayer.Status;
importjavafx.scene.media.MediaView;
importjavafx.stage.FileChooser;
importjavafx.stage.FileChooser.ExtensionFilter;
importjavafx.stage.Stage;
importjavafx.util.Duration;

{

privateMediaViewmediaView;
privateSliderprocessSlider;

privatestaticfinalObjectAUTO=newObject(),MANUAL=newObject();

publicstaticvoidmain(String[]args){
launch(args);
}

@Override
publicvoidstart(StageprimaryStage)throwsException{
primaryStage.setTitle("javafx视频播放器");

BorderPaneroot=newBorderPane();
//菜单栏
initMenu(root);
//视频播放控件
mediaView=initMediaView(root);
//视频功能控件
initMediaControllView(root);

primaryStage.setScene(newScene(root,600,400));
primaryStage.setOnCloseRequest(event->System.exit(0));
primaryStage.show();
}

privateMenuBarinitMenu(finalBorderPaneparent){
Menumenu=newMenu("菜单");
MenuItemitem=newMenuItem("打开");
item.setOnAction(event->{
FileChooserchooser=newFileChooser();
chooser.setTitle("选择视频文件");
chooser.getExtensionFilters().add(newExtensionFilter("视频文件","*.mp4","*.flv"));
Filefile=chooser.showOpenDialog(parent.getScene().getWindow());
if(file!=null){
MediaPlayerplayer=mediaView.getMediaPlayer();
//关闭当前的player
if(player!=null){
player.stop();
player.dispose();
}
processSlider.setValue(0);
//创建一个新的player并自动播放
player=newMediaPlayer(newMedia(file.toURI().toString()));
player.currentTimeProperty().addListener(this::mediaProcessChanged);
player.setAutoPlay(true);
mediaView.setMediaPlayer(player);
}
});
menu.getItems().add(item);

item=newMenuItem("退出");
item.setOnAction(event->parent.getScene().getWindow().hide());
menu.getItems().add(item);

MenuBarmenuBar=newMenuBar(menu);
parent.setTop(menuBar);
returnmenuBar;
}

privateMediaViewinitMediaView(finalBorderPaneparent){
MediaViewview=newMediaView();
Panepane=newPane(view);
parent.setCenter(pane);
//视频宽高可随着窗口变化而自动缩放
view.fitWidthProperty().bind(Bindings.selectDouble(view.parentProperty(),"width"));
view.fitHeightProperty().bind(Bindings.selectDouble(view.parentProperty(),"height"));
view.setPreserveRatio(true);

returnview;
}

(finalBorderPaneparent){
VBoxbottom=newVBox(10);
bottom.setAlignment(Pos.CENTER);
parent.setBottom(bottom);

Sliderslider=newSlider(0,100,0);
slider.valueProperty().addListener(this::processSliderChanged);
// slider.setOnMouseClicked(this::processSliderClicked);
bottom.getChildren().add(slider);
processSlider=slider;

HBoxhbox=newHBox(10);
bottom.getChildren().add(hbox);
hbox.setAlignment(Pos.CENTER);
Buttonbtn=newButton(null,newImageView(loadImage("pause.png")));
btn.setOnAction(this::pauseOrPlay);
hbox.getChildren().add(btn);

btn=newButton(null,newImageView(loadImage("stop.png")));
btn.setOnAction(this::stopPlay);
hbox.getChildren().add(btn);
}

privatestaticImageloadImage(StringresPath){
returnnewImage(Thread.currentThread().getContextClassLoader().getResourceAsStream(resPath));
}

privatevoidpauseOrPlay(ActionEventevent){
MediaPlayerplayer=mediaView.getMediaPlayer();
if(player==null){
return;
}
Statusstatus=player.getStatus();
if(status==Status.READY||status==Status.PAUSED){
player.play();
((Button)event.getTarget()).setGraphic(newImageView(loadImage("pause.png")));
}elseif(status==Status.PLAYING){
player.pause();
((Button)event.getTarget()).setGraphic(newImageView(loadImage("play.png")));
}
}

privatevoidstopPlay(ActionEventevent){
MediaPlayerplayer=mediaView.getMediaPlayer();
if(player==null){
return;
}
player.stop();
}

// (MouseEventevent){
// Sliderslider=(Slider)event.getSource();
// if(mediaView.getMediaPlayer()!=null){
// Durationd=mediaView.getMediaPlayer().getTotalDuration().multiply(slider.getValue()/slider.getMax());
// mediaView.getMediaPlayer().seek(d);
// }
// }

(ObservableValue<?extendsNumber>observable,NumberoldValue,NumbernewValue){
Sliderslider=(Slider)((ReadOnlyProperty<?extendsNumber>)observable).getBean();
if(slider.getUserData()==AUTO){//进度条是自动改变的,因此不用设置播放器
slider.setUserData(null);
return;
}
if(mediaView.getMediaPlayer()!=null){
slider.setUserData(MANUAL);
Durationd=mediaView.getMediaPlayer().getTotalDuration().multiply(newValue.doubleValue()/slider.getMax());
mediaView.getMediaPlayer().seek(d);
}
}

(ObservableValue<?extendsDuration>observable,DurationoldValue,DurationnewValue){
if(processSlider.getUserData()==MANUAL){//手动点击进度条
processSlider.setUserData(null);
return;
}
MediaPlayerplayer=(MediaPlayer)((ReadOnlyProperty<?extendsDuration>)observable).getBean();
processSlider.setUserData(AUTO);
processSlider.setValue(newValue.toMillis()/player.getTotalDuration().toMillis()*100);
}

}

Ⅳ java如何调用javascript的函数

[java] view plainprint?
<span style="font-size:18px;">package suggestion16;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

import javax.script.Bindings;
import javax.script.Invocable;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class ScriptText {

public static void main(String[] args) throws FileNotFoundException, ScriptException, Exception {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
Bindings bind = engine.createBindings();
bind.put("factor", 2); //这里绑定一个factor的值为2.
engine.setBindings(bind,ScriptContext.ENGINE_SCOPE);
Scanner input = new Scanner(System.in);
while(input.hasNext())
{
int first = input.nextInt();
int sec = input.nextInt();
System.out.println("输入的参数为:"+ first+ " , " + sec);
engine.eval(new FileReader("E:/cal.js"));
if(engine instanceof Invocable)
{
Invocable in = (Invocable)engine;
Double result = (Double)in.invokeFunction("cal",first,sec);
System.out.println("运算结果为:" + result.intValue());
}
}
}

}
</span>

其中的“E:/cal.js”就是我们文件的保存路径。并且这个主函数可以循环的输入。
我们运行一下这个程序得到的结果如下:
[html] view plainprint?
<span style="font-size:18px;">1
2
输入的参数为:1 , 2
运算结果为:1
</span>
上面也就是 调用了 1 + 2 - 2 = 1 ,所以结果为1
我们将js文件中的function方法改变下,改编为下面的函数:
[javascript] view plainprint?
<span style="font-size:18px;">function cal(var1,var2)
{
return var1+var2*factor;
}</span>

Ⅳ java swing 怎样实现复选框复选状态的保存

提供参考代码。
窗体1
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;

public class MainGUI extends JFrame {

private static JPanel panel;
private static JButton btn2;
private static JCheckBox chk;
private static MainGUI frame;

public static void main(String[] args) {
();
}

public static void createGUI() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
frame = new MainGUI();
frame.setTitle("window1");
frame.setSize(100,200);

panel = new JPanel();
chk = new JCheckBox("test");
chk.setSelected(true);
btn2 = new JButton("set invisible");

btn2.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
frame.setVisible(false);
CopyOfMainGUI frame2 = new CopyOfMainGUI(frame);
frame2.createGUI();
}

});

FlowLayout layout = new FlowLayout();
layout.setAlignment(0);
panel.setLayout(layout);
panel.add(chk);

frame.add(panel, BorderLayout.CENTER);
frame.add(btn2, BorderLayout.NORTH);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}

}

}
窗体2
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;

public class CopyOfMainGUI extends JFrame {
private static JButton btn;
private CopyOfMainGUI frame2;
private MainGUI frame1;

public CopyOfMainGUI(MainGUI frame) {
frame1 = frame;
}

public void createGUI() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
frame2 = new CopyOfMainGUI(frame1);
frame2.setTitle("window2");
frame2.setSize(200, 200);
btn = new JButton("set visible");
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try {
frame1.setVisible(true);
frame2.setVisible(false);
} catch (HeadlessException e) {
e.printStackTrace();
}
}
});
FlowLayout layout = new FlowLayout();
layout.setAlignment(0);
frame2.add(btn, BorderLayout.SOUTH);
frame2.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Ⅵ 濡備綍浣跨敤 bindings-generator 鑷鍔ㄧ敓鎴 lua缁戝畾

Since Cocos2d-x 3.0, we use bindings-generator to generate lua bindings for c++ automatically
鑷浠嶤ocos2d-x 3.0锛屾垜浠浣跨敤 bindings-generator 鑷鍔ㄧ敓鎴 c++ lua 缁戝畾銆
bindings-generator 鏄鍩轰簬 tolua++锛屼綘鍙浠ラ厤缃 tools/tolua鐩褰曚笅鐨刬ni鏂囦欢锛岀劧鍚庤繍琛実enbindings.py鑴氭湰鐢熸垚缁戝畾浠g爜銆傞氳繃浣跨敤杩欑嶆柟娉曪紝澶уぇ闄嶄綆浜嗚板綍鐨刾kg鏂囦欢鐨勯厤缃宸ヤ綔銆
鎺ヤ笅鏉ワ紝灏辫╂垜浠涓璧锋潵CustomClass浣滀负涓涓渚嬪瓙锛屾垜浠灏嗗悜鎮ㄥ睍绀哄備綍浣跨敤bindings-generator鏉ョ敓鎴愮粦瀹氥
鍒涘缓鑷瀹氫箟绫(CustomClass)
杩欓噷鏄浠g爜鐗囨
// CustomClass.h

#ifndef __CUSTOM__CLASS

#define __CUSTOM__CLASS

#include "cocos2d.h"

namespace cocos2d {
class CustomClass : public cocos2d::Ref
{
public:

CustomClass();

~CustomClass();

static cocos2d::CustomClass* create();

bool init();

CREATE_FUNC(CustomClass);
};
} //namespace cocos2d

#endif // __CUSTOM__CLASS

(娉ㄦ剰锛氫负浜嗕繚鎸侀〉闈㈢煭鑰屽共鍑锛屾垜浠鐪佺暐浜哻pp鏂囦欢鍜宐indings-generator鍙鎵鎻忓ご鏂囦欢銆)
鏈変竴浠朵簨浣犲簲璇ヨ颁綇锛岃嚜瀹氫箟绫诲簲璇ョ户鎵縞ocos2d::Ref绫伙紝杩欎富瑕佹槸鐢变簬鎵鏈夌殑鍏ㄥ眬瀵硅薄鐨勫垱寤哄拰閿姣佺敱REFID_PTR_MAPPING鍦板浘鍦╟++灞傚勭悊鐨勪簨瀹炪傚傛灉鎴戜滑缁ф壙璇ョ被鐨凴ef锛岄偅涔堝畠鐨勬瀽鏋勫嚱鏁板皢澶勭悊杩欎簺鑴忎笢瑗裤

阅读全文

与javabindings绑定函数相关的资料

热点内容
如何从杀毒软件里面恢复出文件 浏览:972
越狱iphone如何备份 浏览:124
苹果四S万能钥匙怎么破不开 浏览:603
网络打印机共享怎么连接 浏览:313
fme系统找不到指定文件 浏览:301
iphoneid和密码忘了怎么办 浏览:238
苹果电脑优盘里的文件如何加密 浏览:284
word标题名和文件名一致 浏览:957
excel修改后的文件保持了怎么恢复 浏览:340
社保网络认证怎么弄 浏览:92
苹果手机怎么传数据到新手机相册 浏览:50
5s升级ios92无服务 浏览:354
ubuntu翻译工具 浏览:665
wifi安装教程 浏览:398
苹果有些qq文件打不开 浏览:139
微信分身图片缓存在哪个文件 浏览:544
众筹用什么网站 浏览:1
天马座的幻想版本 浏览:536
微云保存文件图片没有了 浏览:236
如何把excel表格图片导出到文件夹 浏览:387

友情链接