0
public class Images extends Frame{
static Image img;
Images(){
Image img = Toolkit.getDefaultToolkit().getImage("C:\Users\HP-PC\Desktop\104APPLE\two.jpg");
MediaTracker track = new MediaTracker(this);
track.addImage(img, 0);
try{
track.waitForID(0);
}catch(InterruptedException ie){}
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void paint(Graphics g){
g.drawImage(img,200, 200, null);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Images i = new Images();
i.setSize(400,400);
i.setVisible(true);
i.setIconImage(img);
i.setTitle("Not Working...");
}
}
我已經提供了圖像的本地路徑,但它不起作用。 相反,它顯示錯誤Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\)
當我用\\\
替換\
錯誤消失,但圖像不加載。
請幫忙。無法在圖形類中使用drawImage方法繪製圖像