Hello guys
Below code can't display text "Hello world", I guess it's because paintComponent method is not invoked, but why it is not invoked?
Thanks heaps
package xxx; import java.awt.*; import javax.swing.*; class TextPanel extends JPanel { // override the paintComponent method public void paintComponent(Graphics g) { super.paintComponent(g); Font f = new Font("SansSerif", Font.BOLD, 14); Font fi = new Font("SansSerif", Font.BOLD + Font.ITALIC, 14); FontMetrics fm = g.getFontMetrics(f); int x = 75; int y = 100; g.setFont(f); g.drawString("Hello, ", x, y); x += fm.stringWidth("Hello, "); g.setFont(fi); g.drawString("World!", x, y); } //paintComponent public static void main(String[] args) { JFrame f = new JFrame("Your Frame"); f.show(); } }