Java小程序和文本输入控件在网页上的桥梁 [英] Bridge between the Java applet and the text input controls on the web page

查看:228
本文介绍了Java小程序和文本输入控件在网页上的桥梁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Java小程序是一个小程序,可以帮助写只使用鼠标。对于我而言,我试图将其纳入我的网站这个项目如下:

I have been working with a Java applet which is an applet that helps to write using only a mouse. For my case, I am trying to incorporate this into my webiste project as follows:

在页面上的任何输入元素用户点击(文本/ textarea的),对网页本身这个Java小程序的负载。在下面看到的Java小程序的截图,用户指向一个字母表和相应的文字被写在小应用程序的文本框中。

When the user clicks on any input element (textbox/textarea) on the page, this JAVA applet loads on the webpage itself. In the screenshot of the JAVA applet seen below, the user points to an alphabet to and the corresponding text gets written in the text box of the applet.

现在我所要做的是让从applet到网页上的输入元素的文本框此文本。我知道,这需要Java和JavaScript之间的交互,而不是作为一个职业球员,我真的没有渔获物。这里的Java小程序和code我已经写了。

Now what I am trying to do is to get this text from the TextBox of the applet to the input element on the webpage. I know that this needs an interaction between the Java and JavaScript, but not being a pro, I really do not have the catch. Here's the Java applet and the code I have written.

Java小程序和jQuery code(298KB): http://bit.ly/jItN9m

Java applet and jQuery code (298kB): http://bit.ly/jItN9m

请能somebdoy帮助扩展这个code。
非常感谢!

Please could somebdoy help for extending this code. Thanks a lot!

更新

我搜索的地方,发现这个 - >获取Java文本框内的文字,在Applet的getter方法​​来检索文本:

I searched somewhere and found this -> To get the text inside of Java text box, a getter method in the Applet to retrieve the text:

public class MyApplet extends JApplet {
  // ...
  public String getTextBoxText() { return myTextBox.getText(); }
}

在JQuery的code,以下行被添加,我认为:

In the JQuery code, the following lines are to be added I think:

var textBoxText = $("#applet-id")[0].getTextBoxText();
//Now do something with the text

有关applet的code,我在这里看到了一个GNOME git的页面。 gettext的电话已经存在 - 看看这个文件的底部:<一href=\"http://git.gnome.org/browse/dasher/tree/java/dasher/applet/JDasherApplet.java\">http://git.gnome.org/browse/dasher/tree/java/dasher/applet/JDasherApplet.java

For the code of the applet, I saw a GNOME git page here. The getText call already exists -- look at the bottom of this file: http://git.gnome.org/browse/dasher/tree/java/dasher/applet/JDasherApplet.java

我需要调用getCurrentEditBoxText,但时应这种方法'getCurrentEditBoxText被称为?
就我而言,我可能会做,当用户点击一个新的输入控制等。

I'd need to call 'getCurrentEditBoxText' but when should this method 'getCurrentEditBoxText' be called? In my case, I would probably have to do it when the user clicks in a new input control etc.

推荐答案

您可以有你的Applet与任何JavaScript页​​面上的方法之间的充分沟通。凯尔具有良好的示范后的JavaScript如何调用该applet,并要求文本值。不过,我presume你想要的HTML文本字段与每个鼠标点击更新,这意味着小程序需要与该页面进行通信。我会修改你的JavaScript来是这样的:

You can have full communication between your Applet and any javascript method on the page. Kyle has a good post demonstrating how the Javascript can call the applet and request the text value. However, I presume you want the HTML Textfield to update with each mouse click, meaning the applet needs to communicate with the page. I would modify your javascript to something like this:

var activeTextArea = null;

$('textarea, input').click(function() {
    $(this).dasher();
    activeTextArea = this;
}); 

function updateText(text) {
     // Careful: I think textarea and input have different 
     // methods for setting the value. Check the 
     // jQuery documentation
     $(activeTextArea).val(text); 
}

假设你有applet的源代码,你可以把它用javascript函数上面沟通。添加此导入:

Assuming you have the source for the applet, you can have it communicate with the above javascript function. Add this import:

import netscape.javascript.JSObject;

,然后在任何的onClick处理程序中,你有鼠标点击,添加:

And then, in whatever onClick handler you have for the mouse clicks, add:

// After the Applet Text has been updated
JSObject win = null;
try {
    win = (JSObject) JSObject.getWindow(Applet.this);
    win.call("updateText", new Object[] { textBox.getText() });
} catch (Exception ex) {
    // oops
}

这将每个code的那一块被调用时更新文本。如果你没有获得Applet源,事情变得棘手。你需要设置的JavaScript超时的不断读取applet的价值的一些方式,但这种假设的小程序有这样一个返回文本框的值的方法。

That will update the text each time that chunk of code is called. If you do NOT have access to the applet source, things get trickier. You'd need to set some manner of javascript timeout that constantly reads the value from the applet, but this assumes the applet has such a method that returns the value of the textbox.

另请参见:<一href=\"http://java.sun.com/products/plugin/1.3/docs/jsobject.html\">http://java.sun.com/products/plugin/1.3/docs/jsobject.html

更新修改小程序是你最好的拍摄,因为这是任何事件将被触发。例如,如果希望在HTML TextField对改变的每次点击,点击发生在这将需要修改来触发更新,如上所述的小程序。无需修改小程序,我看到两个选项。选项​​#1使用计时器:

Update Modifying the applet is your best shot since that is where any event would be triggered. For example, if you want the HTML TextField to change on every click, the click happens in the applet which would need to be modified to trigger the update, as described above. Without modifying the applet, I see two options. Option #1 uses a timer:

var timer;
var activeTextArea;

$('textarea, input').click(function() {
    $(this).dasher();
    activeTextArea = this;
    updateText();
} 

function updateText() {
    // Same warnings about textarea vs. input
    $(activeTextArea).val($('#appletId')[0].getCurrentEditBoxText());
    timer = setTimeout("updateText()", 50);
}

function stopUpdating() {
    clearTimeout(timer);
}

这是类似于code以上,除了点​​击文本区域触发循环功能 UPDATETEXT()这将设置HTML文本字段中的值Applet的文本字段的值每隔50ms。这将有可能推出点击更新之间的未成年人延迟,但它会很小。您可以增加定时器的频率,但会增加性能消耗。我没有看到你'隐藏'的小程序,但同样的功能应该叫 stopUpdating 让我们不再试图联系一个隐藏的小程序。

This is similar to the code above except clicking on a text area triggers the looping function updateText() which will set the value of the HTML text field to the value of the Applet text field every 50ms. This will potentially introduce a minor delay between click and update, but it'll be small. You can increase the timer frequency, but that will add a performance drain. I don't see where you've 'hidden' the applet, but that same function should call stopUpdating so that we are no longer trying to contact a hidden applet.

选项#2(未codeD)

Option #2 (not coded)

我会尝试和捕捉单击小程序,它通过气泡的HTML DOM。然后,你可以跳过计时器,并把点击()行为的Applet容器上做同样的更新。我不知道如果这样的事件冒泡,虽然如此,不知道这会工作。即使做了,我不知道它是如何兼容是跨浏览器。

I would be to try and capture the click in the Applet as it bubbles through the HTML Dom. Then, you could skip the timer and put a click() behavior on the Applet container to do the same update. I'm not sure if such events bubble, though, so not sure if this would work. Even if it did, I'm not sure how compatible it would be across browsers.

选项#3

第三个选项是不是每一次点击更新HTML文本字段。这仅仅是凯尔的组合及以上我的职位设置,只要你'完成'与applet的文本字段的值。

Third option is to not update the HTML text field on every click. This would simply be a combination of Kyle's and my posts above to set the value of the text field whenever you 'finish' with the applet.

这篇关于Java小程序和文本输入控件在网页上的桥梁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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