当前位置: 技术问答>java相关
菜鸟问题:javascript访问applet中方法的问题
来源: 互联网 发布时间:2015-06-03
本文导语: 代码如下: import javax.swing.*; import java.awt.*; public class IOTest extends JApplet { public String str; public void init() { str=getParameter("mystr"); System.out.println("hello"); System.out.println(str); } public void paint(Graphics g) ...
代码如下:
import javax.swing.*;
import java.awt.*;
public class IOTest extends JApplet
{
public String str;
public void init()
{
str=getParameter("mystr");
System.out.println("hello");
System.out.println(str);
}
public void paint(Graphics g)
{
g.drawString(str,10,10);
}
public String Output()
{
str="Output value";
return str;
}
public void testText()
{
str="called";
repaint();
}
}
function func()
{
document.write("hello");
str=document.IOTest.Output();//报错,can not find Object IOTest
document.write(str);
document.IOTest.testText();
}
请高手指正一下,谢谢!
import javax.swing.*;
import java.awt.*;
public class IOTest extends JApplet
{
public String str;
public void init()
{
str=getParameter("mystr");
System.out.println("hello");
System.out.println(str);
}
public void paint(Graphics g)
{
g.drawString(str,10,10);
}
public String Output()
{
str="Output value";
return str;
}
public void testText()
{
str="called";
repaint();
}
}
function func()
{
document.write("hello");
str=document.IOTest.Output();//报错,can not find Object IOTest
document.write(str);
document.IOTest.testText();
}
请高手指正一下,谢谢!
|
try again!
|
applet正常加载了吗?
|
你用的是swing...... 你得用hemlconvert转化html文件
或:
public class IOTest extends JApplet
改为
public class IOTest extends Applet
或:
public class IOTest extends JApplet
改为
public class IOTest extends Applet