我是完整的 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);
}
}