?? picbutton.java
字號:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class PicButton extends Applet implements MouseListener
{
private int width,height;
private Image offI,img,img1,img2;
private Graphics offG;
private MediaTracker imageTracker;
private boolean isMouseEnter = false, isPress = false;
private Color ButtonColor=Color.yellow,lightC,darkC;
private URL url;
private AudioClip sound1, sound2;
private String param;
public void init(){
param = new String();
param = getParameter("sound1");
if(param == null)
param = "1.au";
sound1 = getAudioClip(getDocumentBase(), param);
param = getParameter("sound2");
if(param == null)
param = "2.au";
sound2 = getAudioClip(getDocumentBase(), param);
width = getSize().width;
height = getSize().height;
param = getParameter("URL");
try{
url = new URL(param);
}catch(MalformedURLException e){}
offI = createImage(width,height);
offG = offI.getGraphics();
imageTracker = new MediaTracker(this);
// img = new Image();
param = getParameter("Images");
img = getImage(getCodeBase(), param);
imageTracker.addImage(img, 0);
param = getParameter("Images1");
img1 = getImage(getCodeBase(), param);
imageTracker.addImage(img1, 0);
param = getParameter("Images2");
img2 = getImage(getCodeBase(), param);
imageTracker.addImage(img2, 0);
try{
imageTracker.waitForID(0);
}catch(InterruptedException e){}
addMouseListener(this);
}
public void start(){
offG.drawImage(img,0,0,width,height,this);
repaint();
}
public void mouseClicked(MouseEvent e){
}
public void mousePressed(MouseEvent e){
offG.drawImage(img2,0,0,width,height,this);
repaint();
sound1.play();
System.out.println("sound2 play");
}
public void mouseReleased(MouseEvent e){
offG.drawImage(img1,0,0,width,height,this);
repaint();
sound2.play();
getAppletContext().showDocument(url);
}
public void mouseEntered(MouseEvent e){
offG.drawImage(img1,0,0,width,height,this);
repaint();
}
public void mouseExited(MouseEvent e){
offG.drawImage(img,0,0,width,height,this);
repaint();
}
public void paint(Graphics g)
{
g.drawImage(offI,0,0,width,height,this);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -