怎样才能显示出图片?目录怎么设置?
以下是我的程序的所有代码,我是在JBuilder 9下做的Applet
package aclock;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.Date;
import java.net.URL;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class ClockApplet extends Applet {
private boolean isStandalone = false;
MediaTracker mediaTracker=new MediaTracker(this);
Panel panel1 = new Panel();
BorderLayout borderLayout1 = new BorderLayout();
Label label1 = new Label();
Label label2 = new Label();
Label label3 = new Label();
TextField inHour = new TextField();
TextField inMin = new TextField();
TextField inSec = new TextField();
Button button1 = new Button();
Image img;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public ClockApplet() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.setLayout(borderLayout1);
label1.setText("时");
label2.setText("分 ");
label3.setText("秒");
button1.setLabel("确定");
button1.setLocale(java.util.Locale.getDefault());
inHour.setText("");
inHour.setColumns(2);
inMin.setText("");
inMin.setColumns(2);
inSec.setText("");
inSec.setColumns(2);
this.add(panel1, BorderLayout.SOUTH);
panel1.add(label1, null);
panel1.add(inHour, null);
panel1.add(label2, null);
panel1.add(inMin, null);
panel1.add(label3, null);
panel1.add(inSec, null);
panel1.add(button1, null);
}
/**
* 装载图片
*/
void imgInit(){
Image image = Toolkit.getDefaultToolkit().getImage("/img/clock.jpg");
//img=getImage(getDocumentBase(),"/img/clock.jpg");
System.out.println("显示图片");
//装载图片大小
mediaTracker.addImage(img,0);
try {
mediaTracker.waitForAll();
}
catch (InterruptedException ex) {
System.out.println("图片装载出错");
}
}
/**
* 重载paint()函数
* @return
*/
public void paint(Graphics g){
g.drawImage(img,0,0,this);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
}