- 论坛徽章:
- 0
|
如何让javascript取得applet的值
dennis2你好,
,,这一些都是java做凭证跟JVM的时候用到的!因为我没有把整个code po出来,所以才会没有起始的tag.^^"sorry~
JSObject window= JSObject.getWindow(TestApplet.this);
window.call("setHtml", new String[] {filename});
我想我的问题是出在,不知道怎么把这两行正确无误的加到我的Applet
你说不一定要用init,我不知道要用什么方法加>;.<...
可以跟我说应该怎么加进去吗?
- import java.awt.*;
- import java.awt.event.*;
- import java.applet.*;
- import javax.swing.*;
- import java.io.*;
- import javax.sound.sampled.*;
- import java.util.Date;
- import java.text.*;
- import java.util.*;
- import sun.net.ftp.*;
- import sun.net.*;
- import netscape.javascript.*;//Applet JSObject
- public class cc extends Applet
- {
- TargetDataLine m_line;
- AudioFileFormat.Type m_targetType;
- AudioInputStream m_audioInputStream;
- File m_outputFile;
- int ch;
- private boolean isStandalone = false;
- JButton jButton2 = new JButton();
- //Get a parameter value
- public String getParameter(String key, String def)
- {
- return isStandalone ? System.getProperty(key, def) :
- (getParameter(key) != null ? getParameter(key) : def); }
- //Construct the applet
- public cc() { }
- //Initialize the applet
- public void init() {
- try {
- jbInit();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- //Component initialization
- private void jbInit() throws Exception
- {
- this.setLayout(null);//关闭record 按键
- jButton2.setBounds(new Rectangle(-1, 0, 75, 18));
- jButton2.setEnabled(true);//直接启动stop 按键
- jButton2.setOpaque(false);
- jButton2.setRequestFocusEnabled(true);
- jButton2.setVerifyInputWhenFocusTarget(false);
- jButton2.setFocusPainted(true);
- jButton2.setRolloverEnabled(true);
- jButton2.setText("Upload");//改为上传文字
- jButton2.addActionListener(new cc_jButton2_actionAdapter(this));
- this.add(jButton2, null);
- }
- //Start the applet
- public void start() { }
- //Stop the applet
- public void stop() { }
- //Destroy the applet
- public void destroy() { }
- //Get Applet information
- public String getAppletInfo() {
- return "Applet Information";
- }
- //Get parameter info
- public String[][] getParameterInfo()
- {
- return null;
- }
- //Main method
- public static void main(String[] args)
- {
- cc applet = new cc();
- applet.isStandalone = true;
- Frame frame;
- frame = new Frame();
- frame.setTitle("Applet Frame");
- frame.add(applet, BorderLayout.CENTER);
- applet.init();
- applet.start();
- frame.setSize(400,320);
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
- frame.setLocation((d.width - frame.getSize().width) / 2, (d.height -
- frame.getSize().height) / 2);
- frame.setVisible(true);
- }
- void jButton4_actionPerformed(ActionEvent e)
- {
- System.exit(0);
- }
- void jButton1_actionPerformed(ActionEvent e)
- {
- //jButton1.setEnabled(false);
- jButton2.setEnabled(true);
- Thread cc = new Thread()
- {
- public void run()
- {
- //Date date=new Date();
- //DateFormat dateformat;
- //dateformat = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL, Locale.TAIWAN);
- //dateformat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
- String strFilename = "1.wav";
- File outputFile = new File(strFilename);
- AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
- 44100.0F, 16,2,4, 44100.0F, false);
- DataLine.Info info = new DataLine.Info(TargetDataLine.class,
- audioFormat);
- TargetDataLine targetDataLine = null;
- try {
- targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
- targetDataLine.open(audioFormat);
- }
- catch (Exception ee) {}
- AudioFileFormat.Type targetType = AudioFileFormat.Type.WAVE;
- m_line = targetDataLine;
- m_audioInputStream = new AudioInputStream(targetDataLine);
- m_targetType = targetType;
- m_outputFile = outputFile;
- m_line.start();
- try {
- AudioSystem.write(m_audioInputStream, m_targetType,
- m_outputFile);
- }
- catch (Exception eee) {}
- }
- };
- cc.start();
- }
- void jButton2_actionPerformed(ActionEvent e)
- {
- //m_line.stop();//stop 不需要再暂停录音处理
- jButton2.setEnabled(false); // 启动关闭按键,避免重复按
- try{
- TelnetOutputStream outs;//telnet协定的输出串流
- DataOutputStream outputs;
- File localFile ;
- //这个是执行在server
- String filepathname="c:/temp.asf";
- String fg =new String("/");
- int index = filepathname.lastIndexOf(fg);//找出档案位置
- System.out.println(index);
- //String filename = filepathname.substring(index+1);//取出档案名称
- String filename = Long.toString(System.currentTimeMillis())+".asf";//产生一个乱数档名
- System.out.println(filename);
- localFile = new File(filepathname) ;//建立file物件
- FtpClient Oftp = new FtpClient(" ");//修改你要上传的主机位置
- Oftp.login(" "," ");//修改你要上传的帐号密码
- Oftp.binary();
- Oftp.cd(" ");
- //使用随机档案存取方式建立要传送的资料
- RandomAccessFile sendFile = new
- RandomAccessFile(filepathname,"rw");
- //设定从档头开始传送
- sendFile.seek(0);
- //建立server端档案名称,与取得输出串流
- outs = Oftp.put(filename);
- //串成data输出串流
- outputs = new DataOutputStream(outs);
- //只要还没到档尾就继续传送
- while (sendFile.getFilePointer() < sendFile.length() ){
- //一次写出一个byte
- ch = sendFile.read();
- //System.out.println(ch);
- outputs.write(ch);
- }
- //传送完成将各串流关闭
- outs.close();
- sendFile.close();
- outputs.close();
- System.out.println("传送成功");//传完讯息
- }
- catch(IOException eee){
- System.out.println("传送失败");
- }
- catch (Exception eee) {
- }
- //m_line.close();//stop 不需要再关闭录音处理,
- //jButton1.setEnabled(true); //不需要让 record按键可以用
- jButton2.setEnabled(true); //传完恢复按键
- }
- }
- class cc_jButton2_actionAdapter implements
- java.awt.event.ActionListener
- {
- cc adaptee;
- cc_jButton2_actionAdapter(cc adaptee)
- {
- this.adaptee = adaptee;
- }
- public void actionPerformed(ActionEvent e)
- {
- adaptee.jButton2_actionPerformed(e);
- }
- }
复制代码
code有点长,抱歉,麻烦了!
我该怎么将那两行的程式嵌入到这个里面呢??
或是还有那个地方要修改的呢??
这个code可以抓取c:\temp.asf,然后将它做编码,然后上传到远端的FTP SERVER
可能我一直表达的不完整,我想用java script抓到当档案透过编码然后上传的时候的那个档名...
这样不知清不清楚^^
请dennis2前辈指导噜.....
谢谢 |
|