import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
//页面响应鼠标事件
public class ImgButton extends Applet implements MouseListener
{
  private int width,height;
  private Image offI,img1,img2,img3;
  private Graphics offG;
  private MediaTracker imageTracker;
  private boolean isMouseEnter = false, isPress = false;
  private Color ButtonColor=Color.yellow,lightC,darkC;
  private URL url;
  private AudioClip soundA, soundB;
  private String param;
  
  public void init(){
  
    param = new String();
    
    param = getParameter("soundA");
    if(param == null)
       param = "midiA.mid";
    soundA = getAudioClip(getDocumentBase(), param); 
    
    param = getParameter("soundB");
    if(param == null)
       param = "midiB.mid";
    soundB = 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);
    param = getParameter("Images1");
    img1 = getImage(getCodeBase(), param);
    imageTracker.addImage(img1, 0);    param = getParameter("Images2");
    img2 = getImage(getCodeBase(), param);
    imageTracker.addImage(img2, 0);    param = getParameter("Images3");
    img3 = getImage(getCodeBase(), param);
    imageTracker.addImage(img3, 0);
   
    try{
       imageTracker.waitForID(0);
    }catch(InterruptedException e){}
    addMouseListener(this);
  }
  
  public void start(){
   offG.drawImage(img1,0,0,width,height,this);
   repaint();
  }
  
 public void mouseClicked(MouseEvent e){
    
 } public void mousePressed(MouseEvent e){
    offG.drawImage(img3,0,0,width,height,this);
    repaint();
    soundA.play();
       System.out.println("soundB play");
 } public void mouseReleased(MouseEvent e){
    offG.drawImage(img2,0,0,width,height,this);
    repaint();
    soundB.play();
    getAppletContext().showDocument(url);
 } public void mouseEntered(MouseEvent e){
    offG.drawImage(img2,0,0,width,height,this);
    repaint();
 
 } public  void mouseExited(MouseEvent e){
    offG.drawImage(img1,0,0,width,height,this);
    repaint();
 }
  
  
  public void paint(Graphics g)
  {
    g.drawImage(offI,0,0,width,height,this);
  }
  
  
}

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【lulu820830】截止到2008-06-29 21:09:42的历史汇总数据(不包括此帖):
    发帖数:0                  发帖分:0                  
    结贴数:0                  结贴分:0                  
    未结数:0                  未结分:0                  
    结贴率:-------------------结分率:-------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    编译还照常编译,哪儿调用这个Applet调用就可以了啊。
      

  3.   

    编译还像普通程序一样编译,并写一个HTML代码,直接打开HTML文件就可以看到了<HTML>
    <HEAD><TITLE>ImgButton</TITLE></HEAD>
    <BODY>
    <APPLE NAME="ImgButton"   code="ImgButton.class"></APPLE>
    </BODY>
    </HTML>
      

  4.   

    1 编译就不说了
    2 可以放到html里面
    3 也可以放到appletViewer里面
      

  5.   

    自己手动添加main函数了,或像楼上所说的放到HTML里面也可以用AppletViewer来查看.
      

  6.   

    新建一个HTML文件在里面只写<applet   code="ImgButton.class"   width="300"   height="300">
    用ie打开或者appletviewer ImgButton.html   
      

  7.   

    是不能运行,根本就没创建Applet,怎么运行啊?
      

  8.   

    在ImgButton.java的文件同目录下建立一个ImgButton.html
    代码如下:
    <applet  code=ImgButton.class  width=300  height=300 >
    </applet>然后“运行”--“cmd”......Microsoft Windows XP [版本 5.1.2600]
    (C) 版权所有 1985-2001 Microsoft Corp.C:\Documents and Settings\Administrator>f:F:\>cd f:\tempF:\Temp>javac ImgButton.javaF:\Temp>appletviewer ImgButton.html呵呵,有点详细啦!