0
,所以我知道我吸在編程,但如果ANY1可以給我一些代碼幫助,我將不勝感激,我不知道爲什麼我收到此錯誤的paintComponent心不是被調用,不能讓圖像變量工作
不能找到符號
g.drawImage(movPic2, 35, 515, 200, 200,this); ^
symbol: variable movPic2
location: class MovieDis
如果any1可以給我一個代碼片段的例子,我很難理解用文字。 厭倦了這個程序,只是想完成它。
import java.awt.*;
import javax.swing.*;
import javax.swing.JComponent.*;
public class Movie extends JApplet {
private String movName1;
private String director1;
private int yearMade1;
private Image movPic1;
private String movName2;
private String director2;
private int yearMade2;
private Image movPic2;
private String movName3;
private String director3;
private int yearMade3;
private Image movPic3;
private String movName4;
private String director4;
private int yearMade4;
private Image movPic4;
public void init() {
MovieDis goo = new MovieDis(movPic1, movPic2, movPic3, movPic4);
goo.setBounds(0, 0, 750, 500);
add(goo);
}
}
class MovieDis extends JComponent {
private String movName1;
private String director1;
private int yearMade1;
private Image movPic1;
private String movName2;
private String director2;
private int yearMade2;
private Image movPic2;
private String movName3;
private String director3;
private int yearMade3;
private Image movPic3;
private String movName4;
private String director4;
private int yearMade4;
private Image movPic4;
public MovieDis(Image movPic1, Image movPic2, Image movPic3, Image movPic4) {
setBackground(Color.black);
movPic1 = Toolkit.getDefaultToolkit().createImage("Shaw.jpg");
movPic2 = Toolkit.getDefaultToolkit().createImage("dances.jpg");
movPic3 = Toolkit.getDefaultToolkit().getImage("Inception.jpg");
movPic4 = Toolkit.getDefaultToolkit().getImage("Cuckoo.jpg");
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.black);
g.fillRect(0, 0, 750, 500);
g.drawImage(movPic1, 35, 35, 200, 200, this);
g.drawImage(movPic2, 35, 515, 200, 200, this);
g.drawImage(movPic3, 265, 35, 200, 200, this);
g.drawImage(movPic4, 35, 515, 200, 200, this);
}
}
嘿,這工作。謝謝,我仍然有一個問題,但創建圖像,它會得到g.fillRect(0,0,750,500);它並沒有畫出它看起來像的圖像,它是如何將它們存儲在MovieDis構造函數中的? – user1547182 2012-08-10 23:33:35
你能編輯你的問題並更新它來包含你的新代碼嗎?謝謝。 – 2012-08-10 23:37:08
@ user1547182:這似乎是一個新問題。考慮1+ orzechowskid的答案(就像我所做的那樣),接受它並提出一個新問題。 – 2012-08-10 23:48:02