public class GraphicsBoard extends LayerUI {
String picPath = "pictures/";
String[] fileName = { "cards.png", "BlackJackBoard.png" };
ClassLoader cl = GraphicsBoard.class.getClassLoader();
URL imgURL[] = new URL[2];
Toolkit tk = Toolkit.getDefaultToolkit();
Image imgCards, imgBG;
public GraphicsBoard() throws Exception {
for (int x = 0; x < 2; x++)
imgURL[x] = cl.getResource(picPath + fileName[x]);
imgCards = tk.createImage(imgURL[0]);
imgBG = tk.createImage(imgURL[1]);
}
public void paintComponent(Graphics g) {
g.drawImage(imgBG, 0, 0, 550, 450, 0, 0, 551, 412, this);
}
}
這就是我的黑色遊戲即時通訊製作的underpart的代碼。然而,在eclipse中paintComponent的drawImage被加下劃線,我不確定如何修復它。當我在它懸停,它說LayerUI,g.drawImage帶下劃線
The method drawImage(Image, int, int, int, int, int, int, int, int, ImageObserver) in the type Graphics is not applicable for the arguments (Image, int, int, int, int, int, int, int, int, GraphicsBoard)
,並給我的選擇是
Cast argument 'this' to 'ImageObserver'
和
Let 'GraphicsBoard' implement 'ImageObserver'
如果我運行它,在上面層(這基本上是帶按鈕的JPanel)不透明。
這是我使用的JLayer添加到我的框架
OverBoard overLay = new OverBoard();
GraphicsBoard graphicsBG = new GraphicsBoard();
add(new JLayer(overLay, graphicsBG));
@trashgod在哪裏? – Exikle
@trashgod它不是一個導入的問題,它沒有編譯 – Exikle