HTML文件:
<HTML>
<HEAD>
<TITLE>
图形按钮
</TITLE>
</HEAD>
<BODY>
图形按钮<BR>
<applet code="ImgButton" width=75 height=75>
<param name=soundA value="midiA.mid">
<param name=soundB value="midiB.mid">
<param name=Images1 value="button1.gif">
<param name=Images2 value="button2.gif">
<param name=Images3 value="button3.gif">
<param name=URL value=http://www.dzwww.com>
</applet>
</BODY>
</HTML>.java文件:
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);
}
}
<HTML>
<HEAD>
<TITLE>
图形按钮
</TITLE>
</HEAD>
<BODY>
图形按钮<BR>
<applet code="ImgButton" width=75 height=75>
<param name=soundA value="midiA.mid">
<param name=soundB value="midiB.mid">
<param name=Images1 value="button1.gif">
<param name=Images2 value="button2.gif">
<param name=Images3 value="button3.gif">
<param name=URL value=http://www.dzwww.com>
</applet>
</BODY>
</HTML>.java文件:
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);
}
}
Error loading class: ImgButton
java.lang.NoClassDefFoundError
java.lang.ClassNotFoundException: ImgButton
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/applet/AppletPanel.securedClassLoad
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run