我是完整的Java noob,這個問題會非常簡單。我確實試圖找到整個互聯網上的答案,但沒有什麼特別是我需要的東西(如果你知道這個問題的任何教程頁面,請發佈鏈接,我將非常感激。)JPanel中的Java繪圖字符串
基本上我試圖畫我的字符串DrawPanel。我知道我需要在某處調用方法才能這樣做,但我不知道在哪裏。我的繪圖面板有方法:
public void drawGuessWord(Graphics g){
WordsList guessWord = new WordsList();
String word = guessWord.pickWord();
g.drawString(word, 20, 20);
}
而我想調用該方法,以便在DrawPanel中繪製字符串。
以防萬一,這是我的整個DrawPanel:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
public class DrawPanel extends JPanel {
DrawPanel(){
Border raisedbevel = BorderFactory.createRaisedBevelBorder();
Border loweredbevel = BorderFactory.createLoweredBevelBorder();
this.setBackground(Color.WHITE);
this.setBorder(BorderFactory.createLoweredBevelBorder());
this.setPreferredSize(new Dimension(200,200));
}
public void drawGuessWord(Graphics g){
WordsList guessWord = new WordsList();
String word = guessWord.pickWord();
g.drawString(word, 20, 20);
}
}
* facep阿爾姆*謝謝! – Shepard 2012-08-11 13:35:41
哈哈沒問題:) – MimiEAM 2012-08-11 13:36:53
請問我們,不要超過油漆(除非絕對要求);最好使用paintComponent。另外,我們應該叫super.paint(g); ...恕我直言 – MadProgrammer 2012-08-11 15:27:18