Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法通过调用“设置Java小程序的焦点”;requestFocus();MAC上java脚本中的方法_Java_Javascript_Applet - Fatal编程技术网

无法通过调用“设置Java小程序的焦点”;requestFocus();MAC上java脚本中的方法

无法通过调用“设置Java小程序的焦点”;requestFocus();MAC上java脚本中的方法,java,javascript,applet,Java,Javascript,Applet,我在we页面中嵌入了一个java小程序。当我“单击我”链接get focus时,它在java脚本中调用一个方法“focusApplet”。此方法正在调用小程序的“requestFocus()”方法。函数“focusApplet”正在成功执行。但苹果电脑上所有浏览器(包括safari 5、Firefox和chrome)的小程序内部并没有关注焦点。但同样的代码也在windows平台上工作。我也尝试了“requestFocusInWindow()”方法,但它不起作用。请帮我解决这个问题 <HTM

我在we页面中嵌入了一个java小程序。当我“单击我”链接get focus时,它在java脚本中调用一个方法“focusApplet”。此方法正在调用小程序的“requestFocus()”方法。函数“focusApplet”正在成功执行。但苹果电脑上所有浏览器(包括safari 5、Firefox和chrome)的小程序内部并没有关注焦点。但同样的代码也在windows平台上工作。我也尝试了“requestFocusInWindow()”方法,但它不起作用。请帮我解决这个问题

<HTML>
    <HEAD>
    </HEAD>
    <BODY>
        <script type="text/javascript">
            function sayhello(){
                var name = document.getElementById('hellotext');
                name.focus();
                name.click();
                name.value = "raman";
            }
            function focusMe() {
                alert('Hello world!!');
                document.getElementById('hellotext').focus();
            }
            function show() {
                var name = document.getElementById('name');
                var address = document.getElementById('address');
                alert("Hello " + name.value + " Your Address is : " + address.value);// + address.value
            }
            function focusApplet(){
                document.getElementsByName('mediamaster')[0].requestFocus();
            }
        </script>
        <form>
            Text : <input type="text" id="mytext" >
            Address : <input type="text" id="address" >
            <div >
                <a  id="medialink" href="#" onfocus="focusApplet();">Click Me</a>
            </div>
            <div>
                <APPLET name="mediamaster" CODE="FirstApplet.class" WIDTH="200"
                        HEIGHT="200" name="FirstApplet" id="fA"></APPLET>
            </div>
            Name : <input type="text" id="hellotext"> Address : <input type="text">
            <input type="reset">
            <button value="Show" onclick="show()">show</button>
        </form>
    </BODY>
</HTML>
import java.applet.Applet;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import netscape.javascript.JSObject;
import org.w3c.dom.html.HTMLDocument;
import com.sun.java.browser.dom.DOMAccessor;
import com.sun.java.browser.dom.DOMAction;
import com.sun.java.browser.dom.DOMService;
import com.sun.java.browser.dom.DOMUnsupportedException;

public class FirstApplet extends Applet {
    private Button clear_button;
    private Choice color_choices;
    private Button button;
    public void init() {

        this.setFocusable(true);
        this.setBackground(Color.green);
        try {
            service = DOMService.getService(this);
        } catch (DOMUnsupportedException e3) {
            e3.printStackTrace();
        }
        final JSObject win = JSObject.getWindow(this);
        // Create a button and add it to the applet.
        // Also, set the button's colors
        clear_button = new Button("Clear");
        clear_button.setForeground(Color.black);
        clear_button.setBackground(Color.lightGray);
        button = new Button("Push Me");
        this.add(clear_button);
        this.add(button);
        // Create a menu of colors and add it to the applet.
        // Also set the menus's colors and add a label.
        color_choices = new Choice();
        color_choices.addItem("black");
        color_choices.addItem("red");
        color_choices.addItem("yellow");
        color_choices.addItem("green");
        color_choices.setForeground(Color.black);
        color_choices.setBackground(Color.lightGray);
        this.add(new Label("Color: "));
        this.add(color_choices);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                System.out.println("Hello World!!! Thread2");
                win.eval("sayhello()");
            }
        });

    }
}