導航:首頁 > 編程語言 > 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綁定函數相關的資料

熱點內容
ug導出stp文件後顯示 瀏覽:262
struts2文件上傳例子 瀏覽:480
智能粉碎文件名 瀏覽:625
編程是干什麼的適合幾歲兒童上 瀏覽:412
photoshop中文版最新版本 瀏覽:828
什麼app能點播廣西衛視 瀏覽:338
word如何批量放入相應的文件夾 瀏覽:884
如何在excel一列刪除數據 瀏覽:534
商科學生為什麼學編程 瀏覽:438
壓縮文件記錄 瀏覽:967
網上招聘找工作去哪個網站 瀏覽:276
ps生成文件怎麼打開 瀏覽:631
文檔過期文件如何找回 瀏覽:968
daf是什麼文件 瀏覽:851
雲閃付可以適用於哪些app 瀏覽:210
jsp循環輸出44的表格 瀏覽:772
win10有哪些必裝軟體 瀏覽:151
xml文件打開是空白 瀏覽:79
snifferpro使用教程 瀏覽:391
各部門統計數據要統一該怎麼表達 瀏覽:405

友情鏈接