Canvas组件:画布,可以实现动画操作

Canvas组件:画布,可以实现动画操作。

TextArea:文本域。

在单行文本域中回车会激发ActionEvent。

用CheckBoxGroup实现单选框功能。

Java中,单选框和复选框都是使用CheckBox实现。

菜单:new MenuBar(),MenuBar表示菜单条。

菜单中的每一项为MenuItem,一般级联菜单不应该超过三级。

 

 1 package TomTexts;
 2 
 3 
 4 import java.awt.*;
 5 import java.awt.event.*;
 6 import java.applet.*;
 7 
 8 public class TomTexts_45 extends Applet implements Runnable{
 9   private int totalImages=3;//total number of images
10   private Image images[];//an array of images
11   private int width;
12   private int height;
13   private Graphics g;//绘图区域
14   private Thread runner;//动画线程
15   private AudioClip sound;//背景音乐
16   //applet 初始化
17   public void init(){
18     images=new Image[totalImages];
19     MediaTracker mt=new MediaTracker(this);
20     for(int i=0;i<totalImages;i++){
21       images[i]=getImage(getCodeBase(),"flower"+i+".jpg");
22       mt.addImage(images[i],i);
23     }
24     try{
25       mt.waitForAll();
26     }
27     catch(Exception e){
28       e.printStackTrace();
29     }
30     sound=getAudioClip(getCodeBase(),"backSound.au");
31   }
32   //启动applet
33   public void start(){
34     width = this.getSize().width;
35     height = this.getSize().height;
36     g = getGraphics();
37     if(runner==null){
38       //建立线程
39       runner=new Thread(this);
40       //启动线程
41       runner.start();
42     }
43   }
44   //启动线程
45   public void run(){
46     while(true){
47       sound.loop();
48       for(int i=0;i<totalImages;i++){
49         g.drawImage(images[i], 0, 0, width, height, this);
50         try {
51           Thread.currentThread().sleep(1000);
52         }
53         catch (InterruptedException e) {
54           e.printStackTrace();
55         }
56       }
57     }
58   }
59  //停止动画线程
60  public void stop(){
61    if(runner!=null){
62      runner.stop();
63      runner=null;
64    }
65    sound.stop();
66    System.out.println("stop");
67  }
68 }

猜你喜欢

转载自www.cnblogs.com/borter/p/9425309.html