import java.applet.*import java.awt.*;
import java.awt.event.*;
public class Example7_7 extends Applet implements MouseListener{
final int number = 50; //假定幻灯片有50张
int count = 0;
Image[] card = new Image[number];
public void init(){
addMouseListener(this);
for (int i = 0; i < number; i++){
card[i] = getImage(getCodeBase(), "DSC0033" + i + ".jpg");
}
}
public void paint(Graphics g){
if ((card[count]) != null)
g.drawImage(card[count], 10, 10, card[count].getWidth(this),card[count].getHeitht(this), this);
}
public void mousePressed(MouseEvent e){
count = (count + 1) % number; //循环逐张显示
repaint();
}
public void mouseRelease(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(Mouse Event e){}
public void mouseClicked(MouseEvent e){}
}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example7_8 extends Applet implements Runnable{
final int number = 50;
int count = 0;
Thread mythread;
Image[] pic = new Image[number];
public void init(){
setSize(300, 200);
for (int i = 0; i <= number; i++){
//载入动画图片
pic[i - 1] = getImage(getCodeBase(), "DSC0033" + i + ".jpg");
}
}
public void start(){
mythread = new Thread(this); //创建一个线程
mythread.start(); //启动线程执行
}
public void stop(){
mythread = null;
}
public void run(){
//线程的执行代码
while (true){
repaint();
count = (count + 1) % number; //改变显示的图片号
try{
mhythread.sleep(200);
}
catch (InterruptedExeception e){}
}
}
public void paint(Graphics g){
if ((pic[count] != null)
g.drawImage(pic[count], 10, 10, pic[count].getwidth(this), pic[count].getHeight(this), this);
}
}
AudioClip audioClip = getAudioClip(getCodeBase(),”myAudioClipFile.au”);
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example7_9 extends Applet implements ActionListener{
AudioClip clip; //声明一个音频对象
Button buttonPlay, buttonLoop, buttonStop;
public void init(){
clip = getAudioClip(getCodeBase(), "2.wav");
//根据程序所在地址处声音文件2.wav创建音频对象,
//Applet类的getCodeBase()方法可以获得小程序所在的html页面的URL地址。
buttonPlay = new Button("开始播放");
buttonLoop = new Button("循环播放");
buttonStop = new Button("停止播放");
buttonPlay.addActionListener(this);
buttonStop.addActionListener(this);
buttonLoop.addActionListener(this);
add(buttonPlay);
add(buttonLoop);
add(buttonStop);
}
public void stop(){
clip.stop(); //当离开此页面时停止播放
}
public void actionPerformed(ActionEvent e){
if (e.getSource() == buttonPlay){
clip.play();
}
else if (e.getSource() == buttonLoob){
clip.loop();
}
else if (e.getSource() == buttonStop){
clip.stop();
}
}
}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Hanoi extends applet implements Runnable, ActionListener{
AudioClip clip; //声明一个音频对象
textField text;
Thread thread;
Button buttonPlay, buttonLoop, buttonStop;
public void init(){
thread = new Thread(this); //创建新线程
thread .setPriority(Thread.MIN_PRIORITY);
buttonPlay = new Button("开始播放");
buttonLoop = new Button( "循环播放");
buttonStop = new Button("停止播放");
text = new textField(12);
buttonPlay.addActionListener(this);
buttonStop.addActionListener(this);
buttonLoop.addActionListener(this);
add(buttonPlay);
add(buttonLoop);
add(buttonStop);
add(text);
}
public void start(){
thread.start();
}
public void stop(){
clip.stop();
}
public void actionPerformed(ActionEvent e){
if (e.getSource() == buttonPlay(){
clip.play();
}
else if (e.getSource() == buttonLoop(){
clip.loop();
}
else if (e.getSource() == buttonStop(){
clip.stop();
}
}
public void run(){
//在线程thread 中创建音频对象
clip = getAudioclip(getCodeBase(), "2.wav");
text.setText("请稍等");
if(clip ! = null){
buttonPlay.setBackground(Color.red); buttonLoop.setBackground(Color.green); text.setText("您可以播放了");
} //获得音频对象后通知可以播放
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有