?? albumapplet.java
字號(hào):
import java.awt.*;
import java.applet.*;
import java.io.*;
public class AlbumApplet extends Applet{
Choice choicePhoto; //圖片選擇下拉框
int totalImages; //圖像總數(shù)量
Image images[],showImage; //圖像數(shù)組及當(dāng)前顯示圖像
Graphics graphics; //繪制圖像的Graphics對(duì)象
MediaTracker imagetracker; //媒體加載器
public void init(){
setBackground(Color.black); //設(shè)置Applet的背景顏色
setLayout(null); //設(shè)置布局管理器
choicePhoto = new Choice(); //實(shí)例化下拉框
choicePhoto.setBounds(5,10,200,20); //設(shè)置下拉框邊界與位置
String param;
param = getParameter("Amount"); //獲取圖像數(shù)量參數(shù)
totalImages=Integer.parseInt(param); //得到圖像數(shù)量
images = new Image[totalImages];
imagetracker = new MediaTracker(this); //實(shí)例化媒體加載器
for(int i=0; i<totalImages; i++){
param = getParameter("Name"+i); //獲取參數(shù)
choicePhoto.addItem(param); //增加下拉框選項(xiàng)
param = getParameter("Picture"+i); //獲取參數(shù)
images[i] = getImage(getDocumentBase(),param); //得到圖像
imagetracker.addImage(images[i],i); //增加待加載的圖像
}
try{
imagetracker.waitForID(0); //等待第一張圖片的加載完成
}
catch(InterruptedException e){}
add(choicePhoto); //增加組件到Applet
Dimension dim=getSize(); //得到Applet尺寸
showImage = createImage(dim.width,dim.height-40); //創(chuàng)建Image實(shí)例
graphics = showImage.getGraphics(); //得到Graphics實(shí)例
}
public void paint(Graphics g) {
g.drawImage(showImage,5,40,this); //繪制圖像
}
public boolean action(Event e , Object o){
if(e.target == choicePhoto) { //判斷事件源
int selected=choicePhoto.getSelectedIndex(); //得到選擇圖像編號(hào)
graphics.drawImage(images[selected],0,0,this); //繪制圖像
repaint(); //重繪屏幕
}
return true;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -