小程序常用,AppletContext接口

AppletContext接口

该接口对应于小程序的环境,可以获取环境的相关信息。

  1. AudioClip getAudioClip(URL url)创建音频剪辑,参数url是音频剪辑位置的绝对URL,得到的结果是音频剪辑在指定的URL。
package com.appletContext;

import javax.swing.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.net.URL;

/**
 * @author Sky
 * @date 2021/2/25 11:25
 */
public class AudioClipTest {
    private static AudioClip ac;

    public static void main(String[] args) throws Exception{
        JApplet applet = new JApplet();
        URL urlAudio;
        File f = new File("D:\\CloudMusic\\胡伟立 - 初识太极.mp3");
        urlAudio = f.toURL();
        ac = Applet.newAudioClip(urlAudio);
        ac.play();
        Thread.sleep(2000);
    }
}

  1. Image getImage(URl url)返回一个Image对象,可以在屏幕上进行绘制,参数url必须传递绝对URL,该方法始终立即返回,无论图像是否存在,当小程序尝试进行绘图时,会加载数据,绘制图像的图像元素会逐渐在屏幕上绘制。

  2. Applet getApplet(String name)找到并返回applet上下文表示的文档中的applet,文件具有给定的名称,可以设置name的属性,在HTML标签设置名称。

  3. Enumeration getApplets()查找该applet上下文表示的所有applet,结果是所有applet的枚举。

  4. void showDocument(URL url,String target)请求浏览器或小程序查看器由url指定的网页,此方法可能会被不是浏览器的小程序上下文忽略,target参数(一个string指示在哪里显示):

Target Argument Description “_self” Show in the window and frame that contain the applet. “_parent” Show in the applet’s parent frame. If the applet’s frame has no parent frame, acts the same as “_self”. “_top” Show in the top-level frame of the applet’s window. If the applet’s frame is the top-level frame, acts the same as “_self”. “_blank” Show in a new, unnamed top-level window. name Show in the frame or window named name. If a target named name does not already exist, a new top-level window with the specified name is created, and the document is shown there.

  1. void showStatus(String status)请求参数字符串显示在“状态窗口”中,应用程序可以向用户通知当前状态。
  2. void setStream(String key,InputStream stream)throws IOException将指定的流与applet上下文的指定关键字进行关联,如果小程序上下文之前包含该键的映射,则替换旧值,出于安全考虑,每个代码库都存在流和键映射,来自一个代码库的applet无法访问由一个applet从不同代码库创建的流。
  3. InputStream getStream(String key)返回指定键在applet上下文相关联的流,如果小程序上下文不包含此键,则返回null。
  4. Iterator getStreamKeys()在此applet上下文查找流的所有键。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卑微-程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值