免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: pess
打印 上一主题 下一主题

如何让javascript取得applet的值 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2004-11-26 16:46 |只看该作者

如何让javascript取得applet的值

dennis2你好,
,,这一些都是java做凭证跟JVM的时候用到的!因为我没有把整个code po出来,所以才会没有起始的tag.^^"sorry~

JSObject window= JSObject.getWindow(TestApplet.this);
window.call("setHtml", new String[] {filename});
我想我的问题是出在,不知道怎么把这两行正确无误的加到我的Applet
你说不一定要用init,我不知道要用什么方法加>;.<...
可以跟我说应该怎么加进去吗?


  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.applet.*;
  4. import javax.swing.*;
  5. import java.io.*;
  6. import javax.sound.sampled.*;
  7. import java.util.Date;
  8. import java.text.*;
  9. import java.util.*;
  10. import sun.net.ftp.*;
  11. import sun.net.*;
  12. import netscape.javascript.*;//Applet JSObject


  13. public class cc extends Applet
  14. {

  15. TargetDataLine m_line;
  16. AudioFileFormat.Type m_targetType;
  17. AudioInputStream m_audioInputStream;
  18. File m_outputFile;
  19. int ch;
  20. private boolean isStandalone = false;
  21. JButton jButton2 = new JButton();
  22. //Get a parameter value
  23. public String getParameter(String key, String def)
  24. {
  25. return isStandalone ? System.getProperty(key, def) :
  26. (getParameter(key) != null ? getParameter(key) : def); }
  27. //Construct the applet
  28. public cc() { }
  29. //Initialize the applet

  30. public void init() {
  31. try {
  32. jbInit();
  33. }
  34. catch(Exception e)
  35. {
  36. e.printStackTrace();
  37. }
  38. }
  39. //Component initialization
  40. private void jbInit() throws Exception
  41. {

  42. this.setLayout(null);//关闭record 按键
  43. jButton2.setBounds(new Rectangle(-1, 0, 75, 18));
  44. jButton2.setEnabled(true);//直接启动stop 按键
  45. jButton2.setOpaque(false);
  46. jButton2.setRequestFocusEnabled(true);
  47. jButton2.setVerifyInputWhenFocusTarget(false);
  48. jButton2.setFocusPainted(true);
  49. jButton2.setRolloverEnabled(true);
  50. jButton2.setText("Upload");//改为上传文字
  51. jButton2.addActionListener(new cc_jButton2_actionAdapter(this));
  52.     this.add(jButton2, null);
  53. }
  54. //Start the applet
  55. public void start() { }
  56. //Stop the applet
  57. public void stop() { }
  58. //Destroy the applet
  59. public void destroy() { }
  60. //Get Applet information
  61. public String getAppletInfo() {
  62. return "Applet Information";
  63. }
  64. //Get parameter info
  65. public String[][] getParameterInfo()
  66. {
  67. return null;
  68. }

  69. //Main method
  70. public static void main(String[] args)
  71. {
  72. cc applet = new cc();
  73. applet.isStandalone = true;
  74. Frame frame;
  75. frame = new Frame();
  76. frame.setTitle("Applet Frame");
  77. frame.add(applet, BorderLayout.CENTER);
  78. applet.init();
  79. applet.start();
  80. frame.setSize(400,320);
  81. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  82. frame.setLocation((d.width - frame.getSize().width) / 2, (d.height -
  83. frame.getSize().height) / 2);
  84. frame.setVisible(true);

  85. }
  86. void jButton4_actionPerformed(ActionEvent e)
  87. {
  88. System.exit(0);
  89. }
  90. void jButton1_actionPerformed(ActionEvent e)
  91. {
  92. //jButton1.setEnabled(false);
  93. jButton2.setEnabled(true);
  94. Thread cc = new Thread()
  95. {
  96. public void run()
  97. {
  98. //Date date=new Date();
  99. //DateFormat dateformat;
  100. //dateformat = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL, Locale.TAIWAN);
  101. //dateformat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
  102. String strFilename = "1.wav";
  103. File outputFile = new File(strFilename);
  104. AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
  105. 44100.0F, 16,2,4, 44100.0F, false);
  106. DataLine.Info info = new DataLine.Info(TargetDataLine.class,
  107. audioFormat);
  108. TargetDataLine targetDataLine = null;
  109. try {
  110. targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
  111. targetDataLine.open(audioFormat);
  112. }
  113. catch (Exception ee) {}
  114. AudioFileFormat.Type targetType = AudioFileFormat.Type.WAVE;
  115. m_line = targetDataLine;
  116. m_audioInputStream = new AudioInputStream(targetDataLine);
  117. m_targetType = targetType;
  118. m_outputFile = outputFile;

  119. m_line.start();
  120. try {
  121. AudioSystem.write(m_audioInputStream, m_targetType,
  122. m_outputFile);
  123. }
  124. catch (Exception eee) {}
  125. }
  126. };
  127. cc.start();
  128. }
  129. void jButton2_actionPerformed(ActionEvent e)
  130. {
  131. //m_line.stop();//stop 不需要再暂停录音处理
  132. jButton2.setEnabled(false); // 启动关闭按键,避免重复按
  133. try{
  134. TelnetOutputStream outs;//telnet协定的输出串流
  135. DataOutputStream outputs;
  136. File localFile ;
  137. //这个是执行在server
  138. String filepathname="c:/temp.asf";
  139. String fg =new String("/");
  140. int index = filepathname.lastIndexOf(fg);//找出档案位置
  141. System.out.println(index);
  142. //String filename = filepathname.substring(index+1);//取出档案名称
  143. String filename = Long.toString(System.currentTimeMillis())+".asf";//产生一个乱数档名
  144. System.out.println(filename);
  145. localFile = new File(filepathname) ;//建立file物件

  146. FtpClient Oftp = new FtpClient(" ");//修改你要上传的主机位置
  147. Oftp.login(" "," ");//修改你要上传的帐号密码
  148. Oftp.binary();
  149. Oftp.cd(" ");

  150. //使用随机档案存取方式建立要传送的资料
  151. RandomAccessFile sendFile = new
  152. RandomAccessFile(filepathname,"rw");
  153. //设定从档头开始传送
  154. sendFile.seek(0);
  155. //建立server端档案名称,与取得输出串流
  156. outs = Oftp.put(filename);
  157. //串成data输出串流
  158. outputs = new DataOutputStream(outs);
  159. //只要还没到档尾就继续传送
  160. while (sendFile.getFilePointer() < sendFile.length() ){

  161. //一次写出一个byte
  162. ch = sendFile.read();
  163. //System.out.println(ch);
  164. outputs.write(ch);
  165. }
  166. //传送完成将各串流关闭
  167. outs.close();
  168. sendFile.close();
  169. outputs.close();
  170. System.out.println("传送成功");//传完讯息
  171. }
  172. catch(IOException eee){
  173. System.out.println("传送失败");
  174. }
  175. catch (Exception eee) {
  176. }
  177. //m_line.close();//stop 不需要再关闭录音处理,

  178. //jButton1.setEnabled(true); //不需要让 record按键可以用

  179. jButton2.setEnabled(true); //传完恢复按键
  180. }
  181. }

  182. class cc_jButton2_actionAdapter implements
  183. java.awt.event.ActionListener
  184. {
  185. cc adaptee;
  186. cc_jButton2_actionAdapter(cc adaptee)
  187. {
  188. this.adaptee = adaptee;
  189. }
  190. public void actionPerformed(ActionEvent e)
  191. {
  192. adaptee.jButton2_actionPerformed(e);
  193. }
  194. }
复制代码


code有点长,抱歉,麻烦了!
我该怎么将那两行的程式嵌入到这个里面呢??
或是还有那个地方要修改的呢??

这个code可以抓取c:\temp.asf,然后将它做编码,然后上传到远端的FTP SERVER

可能我一直表达的不完整,我想用java script抓到当档案透过编码然后上传的时候的那个档名...

这样不知清不清楚^^

请dennis2前辈指导噜.....

谢谢

论坛徽章:
0
12 [报告]
发表于 2004-11-26 19:45 |只看该作者

如何让javascript取得applet的值

我刚刚试了一下他的code做测试!
真的不行>;<,写了script也抓不到...=.="
不知道问题出在那,可以讨论这个问题是很有趣的
透过问题才能进步,
希望前辈可以帮忙解答...加油加油

论坛徽章:
0
13 [报告]
发表于 2004-11-28 17:48 |只看该作者

如何让javascript取得applet的值

....没有人可以帮忙了吗??
或是..??我的发问方式错了吗??
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP